diff options
author | 2019-10-15 23:47:47 +0000 | |
---|---|---|
committer | 2019-10-16 11:11:24 +0900 | |
commit | fbccf255f9449c2f617d875ebf78b9f1730fae5d (patch) | |
tree | 3b6c5f94bd9adc0c6f995306ac87f03a20706963 /sequencer.h | |
parent | Ninth batch (diff) | |
download | tgif-fbccf255f9449c2f617d875ebf78b9f1730fae5d.tar.xz |
graph: automatically track display width of graph lines
All the output functions called by `graph_next_line()` currently keep
track of how many printable chars they've written to the buffer, before
calling `graph_pad_horizontally()` to pad the line with spaces. Some
functions do this by incrementing a counter whenever they write to the
buffer, and others do it by encoding an assumption about how many chars
are written, as in:
graph_pad_horizontally(graph, sb, graph->num_columns * 2);
This adds a fair amount of noise to the functions' logic and is easily
broken if one forgets to increment the right counter or update the
calculations used for padding.
To make this easier to use, I'm introducing a new struct called
`graph_line` that wraps a `strbuf` and keeps count of its display width
implicitly. `graph_next_line()` wraps this around the `struct strbuf *`
it's given and passes a `struct graph_line *` to the output functions,
which use its interface.
The `graph_line` interface wraps the `strbuf_addch()`,
`strbuf_addchars()` and `strbuf_addstr()` functions, and adds the
`graph_line_write_column()` function for adding a single character with
color formatting. The `graph_pad_horizontally()` function can then use
the `width` field from the struct rather than taking a character count
as a parameter.
Signed-off-by: James Coglan <jcoglan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sequencer.h')
0 files changed, 0 insertions, 0 deletions