Added --fancy option.

This commit is contained in:
shy 2021-04-12 17:06:43 +02:00
parent f3b48aa7a8
commit fd325a88ca
5 changed files with 20 additions and 26 deletions

View file

@ -15,7 +15,7 @@ pub struct Clock {
pub paused: bool, pub paused: bool,
paused_at: Option<time::Instant>, paused_at: Option<time::Instant>,
pub color_index: Option<usize>, pub color_index: Option<usize>,
pub font: font::Font, pub font: &'static font::Font,
} }
impl Clock { impl Clock {
@ -27,10 +27,7 @@ impl Clock {
paused: false, paused: false,
paused_at: None, paused_at: None,
color_index: None, color_index: None,
font: match config.plain { font: config.font,
false => font::NORMAL,
true => font::PLAIN,
},
} }
} }

View file

@ -162,8 +162,7 @@ pub const PLAIN: Font = Font {
]], ]],
}; };
/* pub const CHROME: Font = Font {
pub const FANCE: Font = Font {
height: DIGIT_HEIGHT, height: DIGIT_HEIGHT,
width: 5, width: 5,
dot: '', dot: '',
@ -239,4 +238,4 @@ pub const FANCE: Font = Font {
" 🮐" " 🮐"
]], ]],
}; };
*/

View file

@ -1,11 +1,11 @@
pub const COLOR: [&dyn termion::color::Color; 6] = [ pub const COLOR: [&dyn termion::color::Color; 6] = [
&termion::color::Cyan, &termion::color::LightGreen,
&termion::color::Magenta, &termion::color::LightYellow,
&termion::color::Green, &termion::color::LightMagenta,
&termion::color::Yellow, &termion::color::LightCyan,
&termion::color::Blue, &termion::color::LightRed,
&termion::color::Red, &termion::color::LightBlue,
]; ];
// Maximum length of labels. // Maximum length of labels.
@ -27,7 +27,8 @@ OPTIONS:
-e, --exec [COMMAND] Execute COMMAND on alarm. Occurrences of {t} will -e, --exec [COMMAND] Execute COMMAND on alarm. Occurrences of {t} will
be replaced by the alarm time in (HH:)MM:SS format. be replaced by the alarm time in (HH:)MM:SS format.
Occurrences of {l} by alarm label. 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. -q, --quit Quit program after last alarm.
SIGNALS: <SIGUSR1> Reset clock. SIGNALS: <SIGUSR1> Reset clock.

View file

@ -1,6 +1,5 @@
use std::sync::Arc; use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use crate::Config;
use crate::clock::Clock; use crate::clock::Clock;
pub struct Position { pub struct Position {
@ -11,7 +10,6 @@ pub struct Position {
pub struct Layout { pub struct Layout {
pub force_redraw: bool, // Redraw elements on screen. pub force_redraw: bool, // Redraw elements on screen.
pub force_recalc: Arc<AtomicBool>, // Recalculate position of elements. pub force_recalc: Arc<AtomicBool>, // Recalculate position of elements.
pub plain: bool, // Plain style clock.
pub width: u16, pub width: u16,
pub height: u16, pub height: u16,
clock_width: u16, clock_width: u16,
@ -30,12 +28,11 @@ pub struct Layout {
} }
impl Layout { impl Layout {
pub fn new(config: &Config) -> Layout { pub fn new(sigwinch: Arc<AtomicBool>) -> Layout {
Layout { Layout {
force_redraw: true, force_redraw: true,
// May be set by signal handler (SIGWINCH). // May be set by signal handler (SIGWINCH).
force_recalc: Arc::new(AtomicBool::new(true)), force_recalc: sigwinch,
plain: config.plain,
width: 0, width: 0,
height: 0, height: 0,
clock_width: 0, clock_width: 0,

View file

@ -18,7 +18,7 @@ use termion::raw::{IntoRawMode, RawTerminal};
use termion::event::Key; use termion::event::Key;
use termion::input::TermRead; use termion::input::TermRead;
use buffer::Buffer; use buffer::Buffer;
use clock::Clock; use clock::{Clock, font};
use layout::Layout; use layout::Layout;
use alarm::{Countdown, exec_command}; use alarm::{Countdown, exec_command};
pub use alarm::AlarmRoster; pub use alarm::AlarmRoster;
@ -41,8 +41,7 @@ pub fn run(
spawned: &mut Option<process::Child>, spawned: &mut Option<process::Child>,
) -> Result<(), std::io::Error> ) -> Result<(), std::io::Error>
{ {
let mut layout = Layout::new(&config); let mut layout = Layout::new(sigwinch);
layout.force_recalc = sigwinch;
// Initialise roster_width. // Initialise roster_width.
layout.set_roster_width(alarm_roster.width()); layout.set_roster_width(alarm_roster.width());
let mut clock = Clock::new(&config); let mut clock = Clock::new(&config);
@ -336,8 +335,8 @@ pub fn run(
} }
pub struct Config { pub struct Config {
plain: bool,
quit: bool, quit: bool,
font: &'static font::Font,
command: Option<Vec<String>>, command: Option<Vec<String>>,
} }
@ -347,8 +346,8 @@ impl Config {
-> Result<Config, String> -> Result<Config, String>
{ {
let mut config = Config { let mut config = Config {
plain: false,
quit: false, quit: false,
font: &font::NORMAL,
command: None, command: None,
}; };
let mut iter = args.skip(1); let mut iter = args.skip(1);
@ -365,7 +364,8 @@ impl Config {
println!("{} {}", NAME, VERSION); println!("{} {}", NAME, VERSION);
process::exit(0); 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, "-q" | "--quit" => config.quit = true,
"-e" | "--exec" => { "-e" | "--exec" => {
if let Some(e) = iter.next() { if let Some(e) = iter.next() {