mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
Make Chart::render return a string instead of writing to std::cout
This commit is contained in:
parent
365ae27e49
commit
c562f3fc81
3 changed files with 29 additions and 25 deletions
|
@ -36,7 +36,7 @@
|
|||
#include <timew.h>
|
||||
#include <Chart.h>
|
||||
|
||||
void Chart::render (
|
||||
std::string Chart::render (
|
||||
const Interval &filter,
|
||||
const std::vector<Interval> &tracked,
|
||||
const std::vector<Range> &exclusions,
|
||||
|
@ -78,12 +78,14 @@ void Chart::render (
|
|||
const auto indent = std::string (indent_size, ' ');
|
||||
const auto padding_size = indent_size + ((last_hour - first_hour + 1) * (cell_size)) + 1;
|
||||
|
||||
std::cout << '\n';
|
||||
std::stringstream out;
|
||||
|
||||
out << '\n';
|
||||
|
||||
// Render the axis.
|
||||
if (!with_internal_axis)
|
||||
{
|
||||
std::cout << indent
|
||||
out << indent
|
||||
<< Chart::renderAxis (
|
||||
first_hour,
|
||||
last_hour,
|
||||
|
@ -135,7 +137,7 @@ void Chart::render (
|
|||
auto labelWeekday = with_weekday ? Chart::renderWeekday (day, color_day) : "";
|
||||
auto labelDay = with_day ? Chart::renderDay (day, color_day) : "";
|
||||
|
||||
std::cout << labelMonth
|
||||
out << labelMonth
|
||||
<< labelWeek
|
||||
<< labelWeekday
|
||||
<< labelDay
|
||||
|
@ -145,22 +147,24 @@ void Chart::render (
|
|||
{
|
||||
for (unsigned int i = 1; i < lines.size (); ++i)
|
||||
{
|
||||
std::cout << "\n"
|
||||
out << "\n"
|
||||
<< indent
|
||||
<< lines[i].str ();
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << (with_totals ? Chart::renderTotal (work) : "")
|
||||
out << (with_totals ? Chart::renderTotal (work) : "")
|
||||
<< '\n';
|
||||
|
||||
previous = day;
|
||||
total_work += work;
|
||||
}
|
||||
|
||||
std::cout << (with_totals ? Chart::renderSubTotal (total_work, std::string (padding_size, ' ')) : "")
|
||||
out << (with_totals ? Chart::renderSubTotal (total_work, std::string (padding_size, ' ')) : "")
|
||||
<< (with_holidays ? Chart::renderHolidays (holidays) : "")
|
||||
<< (with_summary ? Chart::renderSummary (indent, filter, exclusions, tracked, show_intervals) : "");
|
||||
|
||||
return out.str ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -36,7 +36,7 @@ class Chart
|
|||
public:
|
||||
Chart() = default;
|
||||
|
||||
static void render (const Interval&, const std::vector <Interval>&, const std::vector <Range>&, const std::map <Datetime, std::string>&, const std::map <std::string, Color>&, const Color&, const Color&, const Color&, const Color&, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, int, int, int);
|
||||
static std::string render (const Interval&, const std::vector <Interval>&, const std::vector <Range>&, const std::map <Datetime, std::string>&, const std::map <std::string, Color>&, const Color&, const Color&, const Color&, const Color&, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, int, int, int);
|
||||
|
||||
static unsigned long getIndentSize (bool, bool, bool, bool);
|
||||
|
||||
|
|
|
@ -145,7 +145,7 @@ int renderChart (
|
|||
auto axis_type = rules.get ("reports." + type + ".axis");
|
||||
const auto with_internal_axis = axis_type == "internal";
|
||||
|
||||
Chart::render (filter, tracked, exclusions, holidays, tag_colors, color_today, color_holiday, color_label, color_exclusion, show_intervals, determine_hour_range, with_ids, with_summary, with_holidays, with_totals, with_month, with_week, with_day, with_weekday, with_internal_axis, minutes_per_char, spacing, num_lines);
|
||||
std::cout << Chart::render (filter, tracked, exclusions, holidays, tag_colors, color_today, color_holiday, color_label, color_exclusion, show_intervals, determine_hour_range, with_ids, with_summary, with_holidays, with_totals, with_month, with_week, with_day, with_weekday, with_internal_axis, minutes_per_char, spacing, num_lines);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue