mirror of
https://github.com/nikolassv/bartib
synced 2024-11-10 14:14:12 +00:00
Merge branch 'master' of github.com:nikolassv/bartib
This commit is contained in:
commit
2d14fbabe1
9 changed files with 39 additions and 48 deletions
28
README.md
28
README.md
|
@ -96,24 +96,24 @@ An exciting day at work continues. As it is a Friday Alice decides to already le
|
|||
```console
|
||||
alice@work: ~ $ bartib report --today
|
||||
|
||||
Important Project................................. 2h 43m
|
||||
Another Task xyz.............................. 15m
|
||||
Important Call with the Client................ 35m
|
||||
Urgent Task X................................. 1h 53m
|
||||
Important Project................................. 2h 43m
|
||||
Another Task xyz.............................. 15m
|
||||
Important Call with the Client................ 35m
|
||||
Urgent Task X................................. 1h 53m
|
||||
|
||||
Internal Project C................................ 4h 30m
|
||||
Another Meeting............................... 45m
|
||||
Boring Task XY................................ 1h 15m
|
||||
Long Meeting with Everyone from the Department 2h 30m
|
||||
Internal Project C................................ 4h 30m
|
||||
Another Meeting............................... 45m
|
||||
Boring Task XY................................ 1h 15m
|
||||
Long Meeting with Everyone from the Department 2h 30m
|
||||
|
||||
Just Another Project B............................ 45m
|
||||
More Urgent Task Y............................ 45m
|
||||
Just Another Project B............................ 45m
|
||||
More Urgent Task Y............................ 45m
|
||||
|
||||
Less Important Project............................ 2h 27m
|
||||
Simple Task No. 5............................. 1h 35m
|
||||
Simple Task Z................................. 52m
|
||||
Less Important Project............................ 2h 27m
|
||||
Simple Task No. 5............................. 1h 35m
|
||||
Simple Task Z................................. 52m
|
||||
|
||||
Total............................................. 9h 25m
|
||||
Total............................................. 10h 25m
|
||||
```
|
||||
|
||||
Alice is happy. This was just another great day at the company and thanks to Bartib tracking her time was a breeze.
|
||||
|
|
|
@ -32,7 +32,7 @@ pub fn list(file_name: &str, filter: getter::ActivityFilter, do_group_activities
|
|||
&filtered_activities[first_element..],
|
||||
);
|
||||
} else {
|
||||
let with_start_dates = !filter.date.is_some();
|
||||
let with_start_dates = filter.date.is_none();
|
||||
list::list_activities(
|
||||
&filtered_activities[first_element..],
|
||||
with_start_dates,
|
||||
|
|
|
@ -48,7 +48,7 @@ fn save_new_activity(
|
|||
);
|
||||
|
||||
file_content.push(bartib_file::Line::for_activity(activity));
|
||||
bartib_file::write_to_file(file_name, &file_content)
|
||||
bartib_file::write_to_file(file_name, file_content)
|
||||
.context(format!("Could not write to file: {}", file_name))
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ impl Activity {
|
|||
|
||||
impl fmt::Display for Activity {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let escaped_project_name = escape_special_chars(&format!("{}", self.project));
|
||||
let escaped_project_name = escape_special_chars(self.project.as_str());
|
||||
let escaped_description = escape_special_chars(&self.description);
|
||||
|
||||
match self.end {
|
||||
|
|
|
@ -79,13 +79,13 @@ pub fn filter_activities<'a>(
|
|||
}
|
||||
|
||||
pub fn get_last_activity_by_end(file_content: &[bartib_file::Line]) -> Option<&activity::Activity> {
|
||||
get_activities(&file_content)
|
||||
get_activities(file_content)
|
||||
.filter(|activity| activity.is_stopped())
|
||||
.max_by_key(|activity| activity.end.unwrap_or(naive::MIN_DATE.and_hms(0, 0, 0)))
|
||||
.max_by_key(|activity| activity.end.unwrap_or_else(||naive::MIN_DATE.and_hms(0, 0, 0)))
|
||||
}
|
||||
|
||||
pub fn get_last_activity_by_start(file_content: &Vec<bartib_file::Line>) -> Option<&activity::Activity> {
|
||||
get_activities(&file_content).max_by_key(|activity| activity.start)
|
||||
pub fn get_last_activity_by_start(file_content: &[bartib_file::Line]) -> Option<&activity::Activity> {
|
||||
get_activities(file_content).max_by_key(|activity| activity.start)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -251,7 +251,7 @@ fn run_subcommand(matches: &ArgMatches, file_name: &str) -> Result<()> {
|
|||
filter.date = Some(Local::now().naive_local().date() - Duration::days(1));
|
||||
}
|
||||
|
||||
let do_group_activities = !sub_m.is_present("no_grouping") && !filter.date.is_some();
|
||||
let do_group_activities = !sub_m.is_present("no_grouping") && filter.date.is_none();
|
||||
bartib::controller::list::list(file_name, filter, do_group_activities)
|
||||
}
|
||||
("report", Some(sub_m)) => {
|
||||
|
|
|
@ -18,7 +18,7 @@ pub fn list_activities(activities: &[&activity::Activity], with_start_dates: boo
|
|||
|
||||
activities
|
||||
.iter()
|
||||
.map(|t| get_activity_table_row(&t, with_start_dates))
|
||||
.map(|t| get_activity_table_row(t, with_start_dates))
|
||||
.for_each(|row| activity_table.add_row(row));
|
||||
|
||||
println!("\n{}", activity_table);
|
||||
|
@ -56,7 +56,7 @@ fn create_activity_table() -> table::Table {
|
|||
fn create_activites_group(title: &str, activities: &[&activity::Activity]) -> table::Group {
|
||||
let rows = activities
|
||||
.iter()
|
||||
.map(|a| get_activity_table_row(&a, false))
|
||||
.map(|a| get_activity_table_row(a, false))
|
||||
.collect();
|
||||
table::Group::new(Some(title.to_string()), rows)
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ fn group_activities_by_date<'a>(
|
|||
for &activity in activities.iter() {
|
||||
activities_by_date
|
||||
.entry(activity.start.date())
|
||||
.or_insert(Vec::new())
|
||||
.or_insert_with(Vec::new)
|
||||
.push(activity);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,8 +21,8 @@ struct Report<'a> {
|
|||
impl<'a> Report<'a> {
|
||||
fn new(activities: &'a [&'a activity::Activity]) -> Report<'a> {
|
||||
Report {
|
||||
project_map: create_project_map(&activities),
|
||||
total_duration: sum_duration(&activities)
|
||||
project_map: create_project_map(activities),
|
||||
total_duration: sum_duration(activities)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ impl<'a> Report<'a> {
|
|||
impl<'a> fmt::Display for Report<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let mut longest_line = get_longest_line(&self.project_map).unwrap_or(0);
|
||||
let longest_duration_string = get_longest_duration_string(&self).unwrap_or(0);
|
||||
let longest_duration_string = get_longest_duration_string(self).unwrap_or(0);
|
||||
|
||||
let terminal_width = term_size::dimensions_stdout().map(|d| d.0)
|
||||
.unwrap_or(conf::DEFAULT_WIDTH);
|
||||
|
@ -43,7 +43,7 @@ impl<'a> fmt::Display for Report<'a> {
|
|||
print_project_heading(f, project, duration, longest_line, longest_duration_string)?;
|
||||
|
||||
print_descriptions_with_durations(f, activities, longest_line, longest_duration_string)?;
|
||||
writeln!(f, "")?;
|
||||
writeln!(f)?;
|
||||
}
|
||||
|
||||
print_total_duration(f, self.total_duration, longest_line)?;
|
||||
|
@ -131,7 +131,7 @@ fn print_descriptions_with_durations<'a>(f: &mut fmt::Formatter<'_>, activities:
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn print_total_duration<'a>(f: &mut fmt::Formatter<'_>, total_duration: Duration, line_width: usize) -> fmt::Result {
|
||||
fn print_total_duration(f: &mut fmt::Formatter<'_>, total_duration: Duration, line_width: usize) -> fmt::Result {
|
||||
writeln!(f, "{prefix}{total:.<width$} {duration}{suffix}",
|
||||
prefix = Style::new().bold().prefix(),
|
||||
total = "Total",
|
||||
|
@ -166,7 +166,7 @@ fn get_longest_line(project_map: &ProjectMap) -> Option<usize> {
|
|||
|
||||
fn get_longest_duration_string(report: &Report) -> Option<usize> {
|
||||
let longest_project_duration = report.project_map.values()
|
||||
.map(|(_a, d)| format_util::format_duration(&d))
|
||||
.map(|(_a, d)| format_util::format_duration(d))
|
||||
.map(|s| s.chars().count())
|
||||
.max();
|
||||
let longest_activity_duration = report.project_map.values()
|
||||
|
@ -225,10 +225,7 @@ mod tests {
|
|||
let a2 = activity::Activity::start("p1".to_string(), "d2".to_string(), None);
|
||||
let a3 = activity::Activity::start("p2".to_string(), "d1".to_string(), None);
|
||||
|
||||
let mut activities: Vec<&activity::Activity> = Vec::new();
|
||||
activities.push(&a1);
|
||||
activities.push(&a2);
|
||||
activities.push(&a3);
|
||||
let activities = vec![&a1, &a2, &a3];
|
||||
let m = create_project_map(&activities);
|
||||
|
||||
assert_eq!(m.len(), 2);
|
||||
|
@ -243,11 +240,7 @@ mod tests {
|
|||
let a3 = activity::Activity::start("p2".to_string(), "d1".to_string(), None);
|
||||
let a4 = activity::Activity::start("p2".to_string(), "d1".to_string(), None);
|
||||
|
||||
let mut activities: Vec<&activity::Activity> = Vec::new();
|
||||
activities.push(&a1);
|
||||
activities.push(&a2);
|
||||
activities.push(&a3);
|
||||
activities.push(&a4);
|
||||
let activities = vec![&a1, &a2, &a3, &a4];
|
||||
let m = group_activities_by_description(&activities);
|
||||
|
||||
assert_eq!(m.len(), 2);
|
||||
|
|
|
@ -108,7 +108,7 @@ impl Table {
|
|||
|
||||
// we start with a width of 0 for all the wrapable columns
|
||||
let mut column_width : Vec<usize> = max_column_width.iter().zip(columns_wrap.iter())
|
||||
.map(|(width, wrap)| if matches!(wrap, Wrap::NoWrap) { width.clone() } else { 0 })
|
||||
.map(|(width, wrap)| if matches!(wrap, Wrap::NoWrap) { *width } else { 0 })
|
||||
.collect();
|
||||
|
||||
// then we distribute the available width to the wrappable columns
|
||||
|
@ -198,7 +198,7 @@ impl fmt::Display for Table {
|
|||
fn write_group(
|
||||
f: &mut fmt::Formatter<'_>,
|
||||
group: &Group,
|
||||
column_width: &Vec<usize>,
|
||||
column_width: &[usize],
|
||||
) -> fmt::Result {
|
||||
let empty_string = "".to_string();
|
||||
let title = group.title.as_ref().unwrap_or(&empty_string);
|
||||
|
@ -207,14 +207,14 @@ fn write_group(
|
|||
writeln!(f, "{}", Style::new().bold().paint(title))?;
|
||||
|
||||
for row in &group.rows {
|
||||
write_row(f, row, &column_width)?;
|
||||
write_row(f, row, column_width)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn write_row(f: &mut fmt::Formatter<'_>, row: &Row, column_width: &Vec<usize>) -> fmt::Result {
|
||||
write_cells(f, &row.content, &column_width, row.style)?;
|
||||
fn write_row(f: &mut fmt::Formatter<'_>, row: &Row, column_width: &[usize]) -> fmt::Result {
|
||||
write_cells(f, &row.content, column_width, row.style)?;
|
||||
writeln!(f)?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -232,9 +232,7 @@ fn write_cells<T: AsRef<str> + std::fmt::Display>(
|
|||
.map(|(i, c)| match column_width.get(i) {
|
||||
Some(s) => textwrap::wrap(c.as_ref(), textwrap::Options::new(*s)),
|
||||
None => {
|
||||
let mut lines = Vec::new();
|
||||
lines.push(Cow::from(c.as_ref()));
|
||||
lines
|
||||
vec![Cow::from(c.as_ref())]
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
|
Loading…
Reference in a new issue