add mode show and fix some things #20

Merged
cscherrNT merged 21 commits from devel into master 2024-07-26 10:43:20 +02:00
3 changed files with 19 additions and 19 deletions
Showing only changes of commit 2526771026 - Show all commits

View File

@ -20,7 +20,7 @@ use std::time::Instant;
pub mod timebar;
pub mod ui;
use timebar::TimeBarLength;
use ui::UiData;
use ui::Data;
/// Make your terminal into a big clock
#[derive(Parser, Debug, Clone)]
@ -190,7 +190,7 @@ impl Clock {
) -> anyhow::Result<()> {
let tick_rate = std::time::Duration::from_millis(100);
let mut last_tick = Instant::now();
let mut uidata: UiData = UiData::default();
let mut uidata: Data = Data::default();
self.setup()?;
loop {
let raw_time = chrono::Local::now().round_subsecs(0);
@ -251,7 +251,7 @@ impl Clock {
fn ui(
&mut self,
terminal: &mut Terminal<CrosstermBackend<Stdout>>,
data: &UiData,
data: &Data,
) -> anyhow::Result<()> {
terminal.draw(|frame| {
debug!("rendering the ui");

View File

@ -9,16 +9,16 @@ use crate::clock::timebar::TimeBarLength;
use super::Clock;
#[derive(Debug, Clone, PartialEq, Default)]
pub struct UiData {
pub struct Data {
now: [DateTime<Local>; 2],
fdate: [String; 2],
ftime: [String; 2],
timebar_ratio: [Option<f64>; 2],
data_idx: usize,
idx: usize,
}
impl UiData {
impl Data {
pub fn update(
&mut self,
now: DateTime<Local>,
@ -26,11 +26,11 @@ impl UiData {
ftime: String,
timebar_ratio: Option<f64>,
) {
self.data_idx ^= 1;
self.now[self.data_idx] = now;
self.fdate[self.data_idx] = fdate;
self.ftime[self.data_idx] = ftime;
self.timebar_ratio[self.data_idx] = timebar_ratio;
self.idx ^= 1;
self.now[self.idx] = now;
self.fdate[self.idx] = fdate;
self.ftime[self.idx] = ftime;
self.timebar_ratio[self.idx] = timebar_ratio;
#[cfg(debug_assertions)]
if self.changed() {
trace!("update with change: {:#?}", self);
@ -49,32 +49,32 @@ impl UiData {
#[must_use]
#[inline]
pub fn fdate(&self) -> &str {
&self.fdate[self.data_idx]
&self.fdate[self.idx]
}
#[must_use]
#[inline]
pub fn ftime(&self) -> &str {
&self.ftime[self.data_idx]
&self.ftime[self.idx]
}
#[must_use]
#[inline]
pub fn now(&self) -> &DateTime<Local> {
&self.now[self.data_idx]
&self.now[self.idx]
}
#[must_use]
#[inline]
#[allow(clippy::missing_const_for_fn)] // no it's not const
pub fn timebar_ratio(&self) -> Option<f64> {
self.timebar_ratio[self.data_idx]
self.timebar_ratio[self.idx]
}
}
pub fn timebarw<'a>(
clock: &mut Clock,
data: &UiData,
data: &Data,
timebarw_padding: &[u16],
inner_rect: Rect,
) -> Option<LineGauge<'a>> {
@ -122,7 +122,7 @@ pub fn timebarw<'a>(
pub fn timebarw_label<'a>(
clock: &Clock,
data: &UiData,
data: &Data,
timebarw_padding: &[u16],
inner_rect: Rect,
) -> Option<Paragraph<'a>> {

View File

@ -63,7 +63,7 @@ fn mock_tests() {
use chrono::{Local, Timelike};
use libpt::log::info;
use crate::clock::ui::UiData;
use crate::clock::ui::Data;
info!("doing the mock tests");
{
let mut c = Clock::parse_from(["some exec", "-mvvv"]);
@ -81,7 +81,7 @@ fn mock_tests() {
info!("0s=0.0");
}
{
let mut data = UiData::default();
let mut data = Data::default();
let now = Local::now();
data.update(now, "date".to_owned(), "time".to_owned(), Some(0.1));
assert_eq!(data.timebar_ratio(), Some(0.1));