Skip to content

Commit

Permalink
Merge commit '26e6d06d252d468e2638d83e299efbcf25f88f19'
Browse files Browse the repository at this point in the history
  • Loading branch information
jgardona committed Jan 9, 2024
2 parents dd13805 + 26e6d06 commit 785b0c3
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 71 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ path = "examples/256color.rs"
name = "truecolor"
path = "examples/truecolor.rs"

[[example]]
name = "styles"
path = "examples/styles.rs"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ansi Stream
# AnsiStream

<p align="center">
<a href="https://crates.io/crates/ansistream">
Expand Down Expand Up @@ -90,7 +90,7 @@ flush(&mut *astream, &mut stdout)?;
```rust
let mut astream = AnsiEscapeStream::default();
astream.write_text_fc(FCGREEN, "123").unwrap();
// asserts that fcred was writed and also reseted with fcdefault
// asserts that fcfreen was writed and also reseted with fcdefault
assert_eq!(
&[0x1b, 0x5b, 0x33, 0x32, 0x6d, 0x31, 0x32, 0x33, 0x1b, 0x5b, 0x33, 0x39, 0x6d],
astream.get_ref().as_slice()
Expand Down
6 changes: 3 additions & 3 deletions examples/16color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ fn main() -> std::io::Result<()> {

astream.write_string("Printing 16 color to stdout\n\n")?;

astream.write_text_fc(FCBLACK, "")?;
astream.write_text_fc(FC_BLACK, "")?;
for i in 40..=47 {
astream.write_text_color(FCLIGHTGRAY, i, &format!(" {i}"))?;
astream.write_text_color(FC_LIGHT_GRAY, i, &format!(" {i}"))?;
}
writeln!(&mut *astream)?;
for i in 100..=107 {
astream.write_text_color(FCLIGHTGRAY, i, &format!(" {i}"))?;
astream.write_text_color(FC_LIGHT_GRAY, i, &format!(" {i}"))?;
}

let mut stdout = std::io::stdout().lock();
Expand Down
54 changes: 54 additions & 0 deletions examples/styles.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use std::io::{self, Read, Seek, Write};

use ansistream::{TS_BOLD, TS_ITALIC, TS_DIM, TS_INVERT, TS_OVERLINE, TS_UNDERLINE, TS_HIDDEN, TS_BLINK, TS_STRIKE};

fn flush<R: Read + Seek>(reader: &mut R) -> io::Result<()> {
reader.seek(io::SeekFrom::Start(0))?;
io::copy(reader, &mut io::stdout().lock())?;
Ok(())
}

fn main() -> io::Result<()> {
let mut astream = ansistream::AnsiEscapeStream::new(2000);
astream.write_string("This example will print text styles. Will depend on terminal emulator specs:\n\n")?;
astream.write_attribute(TS_BOLD)?;
astream.write_string("This is a bold styled text\n")?;
astream.reset_attribute(TS_BOLD)?;

astream.write_attribute(TS_ITALIC)?; // not working today?
astream.write_string("This is a italic styled text\n")?;
astream.reset_attribute(TS_ITALIC)?;

astream.write_attribute(TS_DIM)?;
astream.write_string("This is a dim styled text\n")?;
astream.reset_attribute(TS_DIM)?;

astream.write_attribute(TS_INVERT)?; // not working today?
astream.write_string("This is a invert styled text")?;
astream.reset_attribute(TS_INVERT)?;
writeln!(&mut *astream)?;
writeln!(&mut *astream)?;

astream.write_attribute(TS_OVERLINE)?; // not working today?
astream.write_string("This is a overline styled text\n")?;
astream.reset_attribute(TS_OVERLINE)?;

astream.write_attribute(TS_UNDERLINE)?; // not working today?
astream.write_string("This is a underline styled text\n")?;
astream.reset_attribute(TS_UNDERLINE)?;

astream.write_attribute(TS_HIDDEN)?; // not working today?
astream.write_string("This is a hidden styled text\n")?;
astream.reset_attribute(TS_HIDDEN)?;

astream.write_attribute(TS_BLINK)?; // not working today?
astream.write_string("This is a blink styled text\n")?;
astream.reset_attribute(TS_BLINK)?;

astream.write_attribute(TS_STRIKE)?; // not working today?
astream.write_string("This is a strike styled text\n")?;
astream.reset_attribute(TS_STRIKE)?;

flush(&mut *astream)?;
Ok(())
}
8 changes: 4 additions & 4 deletions examples/truecolor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::io::{self, Read, Seek, Write};

use ansistream::{BCBLACK, FCDARKGRAY};
use ansistream::{BC_BLACK, FC_DARK_GRAY};

fn flush_stdout<W: Read + Seek>(reader: &mut W) -> io::Result<()> {
let mut stdout = io::stdout().lock();
Expand Down Expand Up @@ -33,15 +33,15 @@ fn main() -> io::Result<()> {

for (idx, &c) in palettes.iter().enumerate() {
if idx % 5 == 0 {
astream.reset_attribute(BCBLACK)?;
astream.reset_attribute(BC_BLACK)?;
astream.write_string("\t")?;
}

if idx % 10 == 0 {
astream.reset_attribute(BCBLACK)?;
astream.reset_attribute(BC_BLACK)?;
writeln!(&mut *astream)?;
}
astream.write_text_fc(FCDARKGRAY, "")?;
astream.write_text_fc(FC_DARK_GRAY, "")?;
let (r, g, b) = hex2rgb(c);
astream.write_text_bcrgb(r, g, b, "")?;
write!(&mut *astream, " {c:#06x}")?;
Expand Down
Loading

0 comments on commit 785b0c3

Please sign in to comment.