Add hint :annotations to display annotation column in summary (default: hidden)

This commit is contained in:
Thomas Lauf 2018-10-10 22:10:01 +02:00
parent a35b9d6660
commit 3678c2cdc3
2 changed files with 33 additions and 13 deletions

View file

@ -82,6 +82,7 @@ int CmdSummary (
Color colorID (rules.getBoolean ("color") ? rules.get ("theme.colors.ids") : "");
auto ids = findHint (cli, ":ids");
auto show_annotation = findHint (cli, ":annotations");
Table table;
table.width (1024);
@ -91,10 +92,20 @@ int CmdSummary (
table.add ("Day");
if (ids)
{
table.add ("ID");
}
table.add ("Tags");
auto offset = 0;
if (show_annotation)
{
table.add ("Annotation");
offset = 1;
}
table.add ("Start", false);
table.add ("End", false);
table.add ("Time", false);
@ -131,32 +142,40 @@ int CmdSummary (
today.end = Datetime ();
std::string tags = join(", ", track.tags());
if (ids)
{
table.set (row, 3, format ("@{1}", track.id), colorID);
}
table.set (row, (ids ? 4 : 3), tags);
if (show_annotation)
{
auto annotation = track.getAnnotation ();
if (annotation.length () > 15)
annotation = annotation.substr (0, 12) + "...";
if (ids)
table.set (row, 3, format ("@{1}", track.id), colorID);
table.set (row, (ids ? 4 : 3), tags);
table.set (row, (ids ? 5 : 4), annotation);
table.set (row, (ids ? 6 : 5), today.start.toString ("h:N:S"));
table.set (row, (ids ? 7 : 6), (track.is_open () ? "-" : today.end.toString ("h:N:S")));
table.set (row, (ids ? 8 : 7), Duration (today.total ()).formatHours ());
}
table.set (row, (ids ? 5 : 4) + offset, today.start.toString ("h:N:S"));
table.set (row, (ids ? 6 : 5) + offset, (track.is_open () ? "-" : today.end.toString ("h:N:S")));
table.set (row, (ids ? 7 : 6) + offset, Duration (today.total ()).formatHours ());
daily_total += today.total ();
}
if (row != -1)
table.set (row, (ids ? 9 : 8), Duration (daily_total).formatHours ());
table.set (row, (ids ? 8 : 7) + offset, Duration (daily_total).formatHours ());
grand_total += daily_total;
}
// Add the total.
table.set (table.addRow (), (ids ? 9 : 8), " ", Color ("underline"));
table.set (table.addRow (), (ids ? 9 : 8), Duration (grand_total).formatHours ());
table.set (table.addRow (), (ids ? 8 : 7) + offset, " ", Color ("underline"));
table.set (table.addRow (), (ids ? 8 : 7) + offset, Duration (grand_total).formatHours ());
std::cout << '\n'
<< table.render ()

View file

@ -1,6 +1,6 @@
////////////////////////////////////////////////////////////////////////////////
//
// Copyright 2015 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
// Copyright 2016 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@ -93,6 +93,7 @@ void initializeEntities (CLI& cli)
cli.entity ("hint", ":debug");
cli.entity ("hint", ":fill");
cli.entity ("hint", ":ids");
cli.entity ("hint", ":annotations");
cli.entity ("hint", ":lastmonth");
cli.entity ("hint", ":lastquarter");
cli.entity ("hint", ":lastweek");