Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,15 @@ OPTIONS:
r,g,b
";

const HELP_BG_COLORS: &str = "Set background color of Rain with color string name or tuple
OPTIONS:
white,
red,
blue,
green,
r,g,b
";

const HELP_CHARS: &str = "Set what kind of characters are printed as rain.
OPTIONS:
all - This shows most of the Character Groups all at once.
Expand Down Expand Up @@ -346,6 +355,8 @@ pub struct Cli {
pub group: Grouping,
#[arg(short = 'C', long, help = HELP_COLORS, default_value_t = String::from("green"))]
pub color: String,
#[arg(short = 'B', long, help = HELP_BG_COLORS)]
pub bg_color: Option<String>,
#[arg(short = 'H', long, help = HELP_HEAD, default_value_t = String::from("white"))]
pub head: String,
#[arg(short, long, help = HELP_DIRECTION, default_value = "south")]
Expand All @@ -365,6 +376,10 @@ impl Cli {
pub fn rain_color(&self) -> (u8, u8, u8) {
into_color(&self.color)
}

pub fn rain_bg_color(&self) -> Option<(u8, u8, u8)> {
self.bg_color.as_ref().map(|col| into_color(col.as_str()))
}
pub fn head_color(&self) -> (u8, u8, u8) {
into_color(&self.head)
}
Expand Down
17 changes: 13 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ mod test;
use clap::Parser;
use crossterm::{
cursor, event, execute, queue,
style::{Color, Print, SetForegroundColor},
terminal,
style::{Color, Print, SetBackgroundColor, SetForegroundColor},
terminal::{self, Clear, ClearType},
};
use ezemoji::CharGroup;
use rand::Rng;
Expand Down Expand Up @@ -477,7 +477,7 @@ impl App {
fn run(&mut self, settings: cli::Cli) -> std::io::Result<()> {
let (w, h) = terminal::size()?;
let mut rain = Rain::<1024>::new(w as usize, h as usize, &settings);
self.setup_terminal()?;
self.setup_terminal(&settings)?;

let mut is_running = true;
while is_running {
Expand Down Expand Up @@ -506,9 +506,18 @@ impl App {
}

#[inline(always)]
fn setup_terminal(&mut self) -> std::io::Result<()> {
fn setup_terminal(&mut self, settings: &cli::Cli) -> std::io::Result<()> {
terminal::enable_raw_mode()?;
execute!(self.stdout, terminal::EnterAlternateScreen, cursor::Hide)?;

if let Some(col) = settings.rain_bg_color() {
execute!(
self.stdout,
SetBackgroundColor(col.into()),
Clear(ClearType::All),
)?
}

Ok(())
}

Expand Down