Modify clock style when paused.
This commit is contained in:
parent
21222baa71
commit
85f7b7af03
3 changed files with 53 additions and 63 deletions
|
@ -94,12 +94,11 @@ impl Buffer {
|
||||||
// Write error message if present and return.
|
// Write error message if present and return.
|
||||||
if let Some(msg) = self.message {
|
if let Some(msg) = self.message {
|
||||||
write!(stdout,
|
write!(stdout,
|
||||||
"{}{}{}{}{}{}",
|
"{}{}{}{}{}{}{}",
|
||||||
cursor::Hide,
|
cursor::Hide,
|
||||||
cursor::Goto(
|
cursor::Goto( layout.buffer.col, layout.buffer.line),
|
||||||
layout.buffer.col + (PROMPT.len() as u16),
|
clear::CurrentLine,
|
||||||
layout.buffer.line),
|
PROMPT,
|
||||||
clear::UntilNewline,
|
|
||||||
color::Fg(color::LightRed),
|
color::Fg(color::LightRed),
|
||||||
&msg,
|
&msg,
|
||||||
color::Fg(color::Reset))?;
|
color::Fg(color::Reset))?;
|
||||||
|
@ -110,7 +109,7 @@ impl Buffer {
|
||||||
write!(stdout,
|
write!(stdout,
|
||||||
"{}{}{}{}{}",
|
"{}{}{}{}{}",
|
||||||
cursor::Goto(layout.buffer.col, layout.buffer.line),
|
cursor::Goto(layout.buffer.col, layout.buffer.line),
|
||||||
clear::UntilNewline,
|
clear::CurrentLine,
|
||||||
PROMPT,
|
PROMPT,
|
||||||
cursor::Show,
|
cursor::Show,
|
||||||
&self.content)?;
|
&self.content)?;
|
||||||
|
|
64
src/clock.rs
64
src/clock.rs
|
@ -1,12 +1,11 @@
|
||||||
use std::time;
|
use std::time;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use termion::{color, cursor};
|
use termion::{color, cursor, style};
|
||||||
use termion::raw::RawTerminal;
|
use termion::raw::RawTerminal;
|
||||||
use crate::consts::COLOR;
|
use crate::consts::COLOR;
|
||||||
use crate::consts::digits::*;
|
use crate::consts::digits::*;
|
||||||
use crate::layout::{Layout, Position};
|
use crate::layout::{Layout, Position};
|
||||||
|
|
||||||
|
|
||||||
pub struct Clock {
|
pub struct Clock {
|
||||||
pub start: time::Instant,
|
pub start: time::Instant,
|
||||||
pub elapsed: u32,
|
pub elapsed: u32,
|
||||||
|
@ -149,12 +148,12 @@ impl Clock {
|
||||||
pos: &Position,
|
pos: &Position,
|
||||||
plain: bool,
|
plain: bool,
|
||||||
) {
|
) {
|
||||||
|
if self.paused {
|
||||||
|
write!(stdout, "{}", style::Faint).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(c) = self.color_index {
|
if let Some(c) = self.color_index {
|
||||||
write!(stdout,
|
write!(stdout, "{}", color::Fg(COLOR[c])).unwrap();
|
||||||
"{}{}",
|
|
||||||
cursor::Goto(pos.col, pos.line),
|
|
||||||
color::Fg(COLOR[c]))
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for l in 0..DIGIT_HEIGHT {
|
for l in 0..DIGIT_HEIGHT {
|
||||||
|
@ -179,10 +178,10 @@ impl Clock {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.color_index != None {
|
if self.paused || self.color_index != None {
|
||||||
write!(stdout,
|
write!(stdout,
|
||||||
"{}{}",
|
"{}{}",
|
||||||
cursor::Goto(pos.col + DIGIT_WIDTH + 1, pos.line + DIGIT_HEIGHT),
|
style::NoFaint,
|
||||||
color::Fg(color::Reset))
|
color::Fg(color::Reset))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
@ -196,27 +195,32 @@ impl Clock {
|
||||||
) {
|
) {
|
||||||
let dot = if plain {'█'} else {'■'};
|
let dot = if plain {'█'} else {'■'};
|
||||||
|
|
||||||
match self.color_index {
|
if self.paused {
|
||||||
Some(c) => {
|
write!(stdout, "{}", style::Faint).unwrap();
|
||||||
write!(stdout,
|
}
|
||||||
"{}{}{}{}{}{}",
|
|
||||||
cursor::Goto(pos.col, pos.line + 1),
|
if let Some(c) = self.color_index {
|
||||||
color::Fg(COLOR[c]),
|
write!(stdout,
|
||||||
dot,
|
"{}{}{}{}{}{}",
|
||||||
cursor::Goto(pos.col, pos.line + 3),
|
cursor::Goto(pos.col, pos.line + 1),
|
||||||
dot,
|
color::Fg(COLOR[c]),
|
||||||
color::Fg(color::Reset))
|
dot,
|
||||||
.unwrap();
|
cursor::Goto(pos.col, pos.line + 3),
|
||||||
}
|
dot,
|
||||||
None => {
|
color::Fg(color::Reset))
|
||||||
write!(stdout,
|
.unwrap();
|
||||||
"{}{}{}{}",
|
} else {
|
||||||
cursor::Goto(pos.col, pos.line + 1),
|
write!(stdout,
|
||||||
dot,
|
"{}{}{}{}",
|
||||||
cursor::Goto(pos.col, pos.line + 3),
|
cursor::Goto(pos.col, pos.line + 1),
|
||||||
dot)
|
dot,
|
||||||
.unwrap();
|
cursor::Goto(pos.col, pos.line + 3),
|
||||||
}
|
dot)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.paused {
|
||||||
|
write!(stdout, "{}", style::NoFaint).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
41
src/lib.rs
41
src/lib.rs
|
@ -49,9 +49,6 @@ pub fn run(
|
||||||
let mut countdown = Countdown::new();
|
let mut countdown = Countdown::new();
|
||||||
let mut buffer = Buffer::new();
|
let mut buffer = Buffer::new();
|
||||||
|
|
||||||
// State variables.
|
|
||||||
// Request redraw of menu.
|
|
||||||
let mut update_menu = false;
|
|
||||||
// Are we in insert mode?
|
// Are we in insert mode?
|
||||||
let mut insert_mode = false;
|
let mut insert_mode = false;
|
||||||
|
|
||||||
|
@ -159,22 +156,9 @@ pub fn run(
|
||||||
// Clear the window and redraw menu bar, alarm roster and buffer if
|
// Clear the window and redraw menu bar, alarm roster and buffer if
|
||||||
// requested.
|
// requested.
|
||||||
if layout.force_redraw {
|
if layout.force_redraw {
|
||||||
write!(stdout, "{}", clear::All)?;
|
// Write menu at the top.
|
||||||
|
|
||||||
// Redraw list of alarms.
|
|
||||||
alarm_roster.draw(&mut stdout, &mut layout);
|
|
||||||
|
|
||||||
// Redraw buffer.
|
|
||||||
buffer.draw(&mut stdout, &mut layout)?;
|
|
||||||
|
|
||||||
// Schedule menu redraw.
|
|
||||||
update_menu = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if update_menu {
|
|
||||||
update_menu = false;
|
|
||||||
write!(stdout,
|
write!(stdout,
|
||||||
"{}{}{}{}",
|
"{}{}{}{}{}",
|
||||||
cursor::Goto(1, 1),
|
cursor::Goto(1, 1),
|
||||||
style::Faint,
|
style::Faint,
|
||||||
// Switch menu bars. Use a compressed version or none at
|
// Switch menu bars. Use a compressed version or none at
|
||||||
|
@ -185,7 +169,14 @@ pub fn run(
|
||||||
false if layout.can_hold(MENUBAR_SHORT) => MENUBAR_SHORT,
|
false if layout.can_hold(MENUBAR_SHORT) => MENUBAR_SHORT,
|
||||||
_ => "",
|
_ => "",
|
||||||
},
|
},
|
||||||
style::Reset)?;
|
clear::AfterCursor,
|
||||||
|
style::NoFaint)?;
|
||||||
|
|
||||||
|
// Redraw list of alarms.
|
||||||
|
alarm_roster.draw(&mut stdout, &mut layout);
|
||||||
|
|
||||||
|
// Redraw buffer.
|
||||||
|
buffer.draw(&mut stdout, &mut layout)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
clock.draw(&mut stdout, &layout);
|
clock.draw(&mut stdout, &layout);
|
||||||
|
@ -221,7 +212,7 @@ pub fn run(
|
||||||
stdout.flush()?;
|
stdout.flush()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update buffer whenever the cursor is visible.
|
// Update buffer whenever the cursor should be visible.
|
||||||
if insert_mode || buffer.altered {
|
if insert_mode || buffer.altered {
|
||||||
buffer.draw(&mut stdout, &mut layout)?;
|
buffer.draw(&mut stdout, &mut layout)?;
|
||||||
stdout.flush()?;
|
stdout.flush()?;
|
||||||
|
@ -239,25 +230,22 @@ pub fn run(
|
||||||
} else {
|
} else {
|
||||||
// Input buffer processed without error.
|
// Input buffer processed without error.
|
||||||
layout.set_roster_width(alarm_roster.width());
|
layout.set_roster_width(alarm_roster.width());
|
||||||
layout.force_redraw = true;
|
|
||||||
}
|
}
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
insert_mode = false;
|
insert_mode = false;
|
||||||
update_menu = true;
|
layout.force_redraw = true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// Escape ^W, and ^U clear input buffer.
|
// Escape ^W, and ^U clear input buffer.
|
||||||
Key::Esc | Key::Ctrl('u') => {
|
Key::Esc | Key::Ctrl('u') => {
|
||||||
buffer.reset();
|
buffer.reset();
|
||||||
insert_mode = false;
|
insert_mode = false;
|
||||||
update_menu = true;
|
|
||||||
layout.force_redraw = true;
|
layout.force_redraw = true;
|
||||||
},
|
},
|
||||||
// ^W removes last word.
|
// ^W removes last word.
|
||||||
Key::Ctrl('w') => {
|
Key::Ctrl('w') => {
|
||||||
if !buffer.strip_word() {
|
if !buffer.strip_word() {
|
||||||
insert_mode = false;
|
insert_mode = false;
|
||||||
update_menu = true;
|
|
||||||
layout.force_redraw = true;
|
layout.force_redraw = true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -266,7 +254,6 @@ pub fn run(
|
||||||
// Delete last char in buffer.
|
// Delete last char in buffer.
|
||||||
if buffer.strip_char() && buffer.is_empty() {
|
if buffer.strip_char() && buffer.is_empty() {
|
||||||
insert_mode = false;
|
insert_mode = false;
|
||||||
update_menu = true;
|
|
||||||
layout.force_redraw = true;
|
layout.force_redraw = true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -284,6 +271,7 @@ pub fn run(
|
||||||
// (Un-)Pause on space.
|
// (Un-)Pause on space.
|
||||||
Key::Char(' ') => {
|
Key::Char(' ') => {
|
||||||
clock.toggle();
|
clock.toggle();
|
||||||
|
layout.force_redraw = true;
|
||||||
},
|
},
|
||||||
// Clear clock color on 'c'.
|
// Clear clock color on 'c'.
|
||||||
Key::Char('c') => {
|
Key::Char('c') => {
|
||||||
|
@ -318,7 +306,6 @@ pub fn run(
|
||||||
if c.is_ascii_digit() {
|
if c.is_ascii_digit() {
|
||||||
buffer.push(c);
|
buffer.push(c);
|
||||||
insert_mode = true;
|
insert_mode = true;
|
||||||
update_menu = true;
|
|
||||||
layout.force_redraw = true;
|
layout.force_redraw = true;
|
||||||
} else if !buffer.is_empty() && c == ':' {
|
} else if !buffer.is_empty() && c == ':' {
|
||||||
buffer.push(':');
|
buffer.push(':');
|
||||||
|
@ -455,7 +442,7 @@ fn suspend<W: Write>(mut stdout: &mut RawTerminal<W>)
|
||||||
write!(stdout,
|
write!(stdout,
|
||||||
"{}{}{}",
|
"{}{}{}",
|
||||||
cursor::Goto(1,1),
|
cursor::Goto(1,1),
|
||||||
clear::All,
|
clear::AfterCursor,
|
||||||
cursor::Show)?;
|
cursor::Show)?;
|
||||||
stdout.flush()?;
|
stdout.flush()?;
|
||||||
stdout.suspend_raw_mode()
|
stdout.suspend_raw_mode()
|
||||||
|
|
Loading…
Reference in a new issue