display a nicer message when no entries are running with t now
This commit is contained in:
parent
57ec60226d
commit
9b07bedf55
|
@ -40,42 +40,46 @@ impl<'a> Command<'a> for NowCommand {
|
|||
|
||||
let (entries, needs_warning) = entries_or_warning(entries, &streams.db)?;
|
||||
|
||||
let current = streams.db.current_sheet()?;
|
||||
let last = streams.db.last_sheet()?;
|
||||
if entries.is_empty() {
|
||||
streams.out.write_all(b"No running entries\n")?;
|
||||
} else {
|
||||
let current = streams.db.current_sheet()?;
|
||||
let last = streams.db.last_sheet()?;
|
||||
|
||||
let mut tabs = Tabulate::with_columns(vec![
|
||||
// indicator of current or prev sheet
|
||||
Col::new().min_width(1).and_alignment(Right),
|
||||
let mut tabs = Tabulate::with_columns(vec![
|
||||
// indicator of current or prev sheet
|
||||
Col::new().min_width(1).and_alignment(Right),
|
||||
|
||||
// sheet name
|
||||
Col::new().min_width(9).and_alignment(Left),
|
||||
// sheet name
|
||||
Col::new().min_width(9).and_alignment(Left),
|
||||
|
||||
// running time
|
||||
Col::new().min_width(9).and_alignment(Right),
|
||||
// running time
|
||||
Col::new().min_width(9).and_alignment(Right),
|
||||
|
||||
// activity
|
||||
Col::new().min_width(0).and_alignment(Left),
|
||||
]);
|
||||
|
||||
tabs.feed(vec!["", "Timesheet", "Running", "Activity"]);
|
||||
tabs.separator(' ');
|
||||
|
||||
for entry in entries {
|
||||
tabs.feed(vec![
|
||||
if current == entry.sheet {
|
||||
"*"
|
||||
} else if last.as_ref() == Some(&entry.sheet) {
|
||||
"-"
|
||||
} else {
|
||||
""
|
||||
}.to_string(),
|
||||
entry.sheet,
|
||||
format_duration(facts.now - entry.start),
|
||||
entry.note.unwrap_or_default(),
|
||||
// activity
|
||||
Col::new().min_width(0).and_alignment(Left),
|
||||
]);
|
||||
}
|
||||
|
||||
streams.out.write_all(tabs.print(facts.env.stdout_is_tty).as_bytes())?;
|
||||
tabs.feed(vec!["", "Timesheet", "Running", "Activity"]);
|
||||
tabs.separator(' ');
|
||||
|
||||
for entry in entries {
|
||||
tabs.feed(vec![
|
||||
if current == entry.sheet {
|
||||
"*"
|
||||
} else if last.as_ref() == Some(&entry.sheet) {
|
||||
"-"
|
||||
} else {
|
||||
""
|
||||
}.to_string(),
|
||||
entry.sheet,
|
||||
format_duration(facts.now - entry.start),
|
||||
entry.note.unwrap_or_default(),
|
||||
]);
|
||||
}
|
||||
|
||||
streams.out.write_all(tabs.print(facts.env.stdout_is_tty).as_bytes())?;
|
||||
}
|
||||
|
||||
warn_if_needed(&mut streams.err, needs_warning, &facts.env)?;
|
||||
|
||||
|
@ -86,7 +90,7 @@ impl<'a> Command<'a> for NowCommand {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use chrono::{Utc, TimeZone, Local};
|
||||
use pretty_assertions::assert_eq;
|
||||
use pretty_assertions::assert_str_eq;
|
||||
|
||||
use crate::database::{SqliteDatabase, Database};
|
||||
|
||||
|
@ -111,7 +115,7 @@ mod tests {
|
|||
|
||||
NowCommand::handle(Default::default(), &mut streams, &facts).unwrap();
|
||||
|
||||
assert_eq!(&String::from_utf8_lossy(&streams.out), " Timesheet Running Activity
|
||||
assert_str_eq!(&String::from_utf8_lossy(&streams.out), " Timesheet Running Activity
|
||||
|
||||
- sheet4 1:52:45 some
|
||||
");
|
||||
|
@ -128,14 +132,28 @@ mod tests {
|
|||
|
||||
NowCommand::handle(Default::default(), &mut streams, &facts).unwrap();
|
||||
|
||||
assert_eq!(&String::from_utf8_lossy(&streams.out), " Timesheet Running Activity
|
||||
assert_str_eq!(&String::from_utf8_lossy(&streams.out), " Timesheet Running Activity
|
||||
|
||||
* default 0:10:24 que
|
||||
");
|
||||
|
||||
assert_eq!(
|
||||
assert_str_eq!(
|
||||
String::from_utf8_lossy(&streams.err),
|
||||
"[WARNING] You are using the old timetrap format, it is advised that you update your database using t migrate. To supress this warning set TIEMPO_SUPRESS_TIMETRAP_WARNING=1\n"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn with_no_running_entries_display_nicer_message() {
|
||||
std::env::set_var("TZ", "CST+6");
|
||||
|
||||
let mut streams = Streams::fake(b"");
|
||||
let now = Utc.ymd(2021, 1, 1).and_hms(13, 52, 45);
|
||||
let facts = Facts::new().with_now(now);
|
||||
|
||||
NowCommand::handle(Default::default(), &mut streams, &facts).unwrap();
|
||||
|
||||
assert_str_eq!(&String::from_utf8_lossy(&streams.out), "No running entries
|
||||
");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue