Skip to content

Commit

Permalink
feat: add --think option, improve help text (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
uncenter committed Feb 8, 2024
1 parent 7392d5c commit dec218f
Showing 1 changed file with 67 additions and 11 deletions.
78 changes: 67 additions & 11 deletions src/main.rs
Expand Up @@ -6,11 +6,58 @@ use clap_stdin::MaybeStdin;

use crossterm::terminal;

struct Chars {
arrow: &'static str,
top: &'static str,
bottom: &'static str,
left: &'static str,
right: &'static str,
single_left: &'static str,
single_right: &'static str,
angled_up_right: &'static str,
angled_up_left: &'static str,
angled_down_right: &'static str,
angled_down_left: &'static str,
}

static SAY_CHARS: Chars = Chars {
arrow: "\\",
top: "-",
bottom: "-",
left: "|",
right: "|",
single_left: "<",
single_right: ">",
angled_up_right: "/",
angled_up_left: "\\",
angled_down_right: "\\",
angled_down_left: "/",
};

static THINK_CHARS: Chars = Chars {
arrow: "○",
top: "⏜",
bottom: "⏝",
left: "(",
right: ")",
single_left: "(",
single_right: ")",
angled_up_right: "⎛",
angled_up_left: "⎞",
angled_down_right: "⎝",
angled_down_left: "⎠",
};

#[derive(Parser)]
#[command(version, about)]
struct Cli {
message: MaybeStdin<String>,
/// Set custom width of the message box
#[clap(long, short)]
width: Option<u16>,
/// Enable kittythink mode
#[clap(long, short)]
think: bool,
}

fn word_wrap(paragraph: &str, line_length: usize) -> Vec<String> {
Expand Down Expand Up @@ -42,6 +89,7 @@ fn main() -> Result<()> {
let (cols, _) = terminal::size()?;

let width = args.width.unwrap_or(45).min(cols.saturating_sub(5));
let chars = if args.think { &THINK_CHARS } else { &SAY_CHARS };

let mut lines = word_wrap(&args.message, width as usize);
let longest = lines.iter().map(String::len).max().unwrap();
Expand All @@ -51,42 +99,50 @@ fn main() -> Result<()> {
{}
{}
{}
\\
\\
{}
{}
/l、
(゚、 。 7
l ~ヽ
じしf_,)ノ
",
"-".repeat(longest),
chars.top.repeat(longest),
if lines.len() == 1 {
format!("< {} >", lines[0])
format!("{} {} {}", chars.single_left, lines[0], chars.single_right)
} else {
let mut result = format!(
"/ {}{}\\",
"{} {}{}{}",
chars.angled_up_right,
lines[0],
" ".repeat(longest - lines[0].len() + 1)
" ".repeat(longest - lines[0].len() + 1),
chars.angled_up_left
);
lines.remove(0);
let last = lines.pop().unwrap();

for line in lines {
result = format!(
"{}\n| {}{}|",
"{}\n{} {}{}{}",
result,
chars.left,
line,
" ".repeat(longest - line.len() + 1)
" ".repeat(longest - line.len() + 1),
chars.right,
);
}

format!(
"{}\n\\ {}{}/",
"{}\n{} {}{}{}",
result,
chars.angled_down_right,
last,
" ".repeat(longest - last.len() + 1)
" ".repeat(longest - last.len() + 1),
chars.angled_down_left,
)
},
"-".repeat(longest)
chars.bottom.repeat(longest),
chars.arrow,
chars.arrow,
);

Ok(())
Expand Down

0 comments on commit dec218f

Please sign in to comment.