Skip to content

Commit

Permalink
feat: add custom colors (#18)
Browse files Browse the repository at this point in the history
Co-authored-by: uncenter <[email protected]>
  • Loading branch information
comfysage and uncenter authored Jun 6, 2024
1 parent c209add commit a46bc98
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 7 deletions.
20 changes: 20 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ edition = "2021"
clap = { version = "4.5.4", features = ["derive"] }
clap-stdin = "0.4.0"
color-eyre = "0.6.3"
console = "0.15.8"
crossterm = "0.27.0"
textwrap = "0.16.1"
unicode-width = "0.1.12"
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ kittysay <message>
echo <message> | kittysay
```

You can customize the output colors.

```sh
# -c <message color> <cat color>
kittysay -c 2 5 <message>
echo <message> | kittysay -c 2 5
```

### `--width`

You can use the `--width` flag to change the width of the speech bubble. Defaults to `45`, maxes out at a little less than the width of your terminal if you try to pass a very large number.
Expand Down
32 changes: 25 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ struct Cli {
/// Enable kittythink mode (thought bubble)
#[clap(long, short)]
think: bool,
/// Use custom colors. The first colors the message, the second colors the cat
#[arg(long, short, num_args(2))]
colors: Option<Vec<u8>>,
}

fn main() -> Result<()> {
Expand All @@ -75,18 +78,13 @@ fn main() -> Result<()> {
let mut lines = wrap(&args.message, width as usize);
let longest = lines.iter().map(|line| line.width()).max().unwrap();

println!(
let msg = format!(
"
{}
{}
{}
{}
{}
/l、
(゚、 。 7
l ~ヽ
じしf_,)ノ
",
{}",
chars.top.repeat(longest),
if lines.len() == 1 {
format!("{} {} {}", chars.single_left, lines[0], chars.single_right)
Expand Down Expand Up @@ -126,5 +124,25 @@ fn main() -> Result<()> {
chars.arrow,
);

let mut msg_color = console::Color::White;
let mut cat_color = console::Color::White;
if let Some(colors) = args.colors {
msg_color = console::Color::Color256(colors[0]);
cat_color = console::Color::Color256(colors[1]);
}

let cat = "
/l、
(゚、 。 7
l ~ヽ
じしf_,)ノ
";

println!(
"{}{}",
console::style(msg).fg(msg_color),
console::style(cat).fg(cat_color)
);

Ok(())
}

0 comments on commit a46bc98

Please sign in to comment.