From fd325a88ca20855962a8053de3f5a4aa58a75bbf Mon Sep 17 00:00:00 2001 From: shy Date: Mon, 12 Apr 2021 17:06:43 +0200 Subject: [PATCH] Added --fancy option. --- src/clock.rs | 7 ++----- src/clock/font.rs | 5 ++--- src/consts.rs | 15 ++++++++------- src/layout.rs | 7 ++----- src/lib.rs | 12 ++++++------ 5 files changed, 20 insertions(+), 26 deletions(-) diff --git a/src/clock.rs b/src/clock.rs index 4940dc3..db84e85 100644 --- a/src/clock.rs +++ b/src/clock.rs @@ -15,7 +15,7 @@ pub struct Clock { pub paused: bool, paused_at: Option, pub color_index: Option, - pub font: font::Font, + pub font: &'static font::Font, } impl Clock { @@ -27,10 +27,7 @@ impl Clock { paused: false, paused_at: None, color_index: None, - font: match config.plain { - false => font::NORMAL, - true => font::PLAIN, - }, + font: config.font, } } diff --git a/src/clock/font.rs b/src/clock/font.rs index 420874f..8ed8076 100644 --- a/src/clock/font.rs +++ b/src/clock/font.rs @@ -162,8 +162,7 @@ pub const PLAIN: Font = Font { ]], }; -/* -pub const FANCE: Font = Font { +pub const CHROME: Font = Font { height: DIGIT_HEIGHT, width: 5, dot: '■', @@ -239,4 +238,4 @@ pub const FANCE: Font = Font { " 🮐" ]], }; -*/ + diff --git a/src/consts.rs b/src/consts.rs index efdc28f..b1df914 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -1,11 +1,11 @@ pub const COLOR: [&dyn termion::color::Color; 6] = [ - &termion::color::Cyan, - &termion::color::Magenta, - &termion::color::Green, - &termion::color::Yellow, - &termion::color::Blue, - &termion::color::Red, + &termion::color::LightGreen, + &termion::color::LightYellow, + &termion::color::LightMagenta, + &termion::color::LightCyan, + &termion::color::LightRed, + &termion::color::LightBlue, ]; // Maximum length of labels. @@ -27,7 +27,8 @@ OPTIONS: -e, --exec [COMMAND] Execute COMMAND on alarm. Occurrences of {t} will be replaced by the alarm time in (HH:)MM:SS format. Occurrences of {l} by alarm label. - -p, --plain Use simpler block chars. + -p, --plain Use simpler block chars to draw the clock. + -f, --fancy Use fancy clock style. -q, --quit Quit program after last alarm. SIGNALS: Reset clock. diff --git a/src/layout.rs b/src/layout.rs index 1f0d9a7..9fb324c 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -1,6 +1,5 @@ use std::sync::Arc; use std::sync::atomic::{AtomicBool, Ordering}; -use crate::Config; use crate::clock::Clock; pub struct Position { @@ -11,7 +10,6 @@ pub struct Position { pub struct Layout { pub force_redraw: bool, // Redraw elements on screen. pub force_recalc: Arc, // Recalculate position of elements. - pub plain: bool, // Plain style clock. pub width: u16, pub height: u16, clock_width: u16, @@ -30,12 +28,11 @@ pub struct Layout { } impl Layout { - pub fn new(config: &Config) -> Layout { + pub fn new(sigwinch: Arc) -> Layout { Layout { force_redraw: true, // May be set by signal handler (SIGWINCH). - force_recalc: Arc::new(AtomicBool::new(true)), - plain: config.plain, + force_recalc: sigwinch, width: 0, height: 0, clock_width: 0, diff --git a/src/lib.rs b/src/lib.rs index cfb3b39..f49680f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,7 +18,7 @@ use termion::raw::{IntoRawMode, RawTerminal}; use termion::event::Key; use termion::input::TermRead; use buffer::Buffer; -use clock::Clock; +use clock::{Clock, font}; use layout::Layout; use alarm::{Countdown, exec_command}; pub use alarm::AlarmRoster; @@ -41,8 +41,7 @@ pub fn run( spawned: &mut Option, ) -> Result<(), std::io::Error> { - let mut layout = Layout::new(&config); - layout.force_recalc = sigwinch; + let mut layout = Layout::new(sigwinch); // Initialise roster_width. layout.set_roster_width(alarm_roster.width()); let mut clock = Clock::new(&config); @@ -336,8 +335,8 @@ pub fn run( } pub struct Config { - plain: bool, quit: bool, + font: &'static font::Font, command: Option>, } @@ -347,8 +346,8 @@ impl Config { -> Result { let mut config = Config { - plain: false, quit: false, + font: &font::NORMAL, command: None, }; let mut iter = args.skip(1); @@ -365,7 +364,8 @@ impl Config { println!("{} {}", NAME, VERSION); process::exit(0); }, - "-p" | "--plain" => config.plain = true, + "-p" | "--plain" => config.font = &font::PLAIN, + "-f" | "--fancy" => config.font = &font::CHROME, "-q" | "--quit" => config.quit = true, "-e" | "--exec" => { if let Some(e) = iter.next() {