<<
path:
root/public/track.git/html/src/display.jai
blob: 269841fc78e7b3fde48ec594f8e58f0e12fe8352
[raw]
[clear marker]
11 term := terminal_info_size();
13 // Hack. See TODO @TERMINAL_MIN_WIDTH
14 if term.col < TERMINAL_MIN_WIDTH then term.col = TERMINAL_MIN_WIDTH;
16 section_title(file_name, term);
18 tokens_print(todo, " TODO ", term);
19 tokens_print(note, " NOTE ", term);
20 tokens_print(idea, " IDEA ", term);
21 tokens_print(cont, " CONTINUE ", term);
22 tokens_print(other, " OTHER ", term);
32/** TODO(adam): This is a fugly hack. Below 88 columns I see on _my_ terminal
33 bazillions of hyphens. This is worth investigating.
35TERMINAL_MIN_WIDTH :: 88;
37COLUMN_LABEL_COLOR_LINE: Color_Foreground: .MAGENTA;
38COLUMN_LABEL_COLOR_PRIORITY: Color_Foreground: .GREEN;
39COLUMN_LABEL_COLOR_AUTHOR: Color_Foreground: .BLUE;
40COLUMN_LABEL_COLOR_KEYWORD: Color_Foreground: .RED;
42COLUMN_LABEL_LINE :: " Line ";
43COLUMN_LABEL_PRIORITY :: " Priority ";
44COLUMN_LABEL_AUTHOR :: " Author ";
46COLUMN_PADDING_LINE :: 3;
47COLUMN_PADDING_PRIORITY :: 1;
48COLUMN_PADDING_AUTHOR :: 5;
50COLUMN_WIDTH_LINE :: #run COLUMN_LABEL_LINE.count + COLUMN_PADDING_LINE;
51COLUMN_WIDTH_PRIORITY :: #run COLUMN_LABEL_PRIORITY.count + COLUMN_PADDING_PRIORITY;
52COLUMN_WIDTH_AUTHOR :: #run COLUMN_LABEL_AUTHOR.count + COLUMN_PADDING_AUTHOR;
54SEPARATOR_FIRST :: "|";
55SEPARATOR_CORNER :: "+-";
61#no_reset table_header_visual_count: int;
63TABLE_HEADER :: #run -> string {
65 create_column_title :: (
68 fgc: Color_Foreground,
71 -> vcount: int #expand
73 append(*`buf, SEPARATOR_CORNER);
81 for 0..padding append(*`buf, HLINE);
87 init_string_builder(*buf);
89 vcount_line := create_column_title(
91 COLUMN_PADDING_LINE - 1,
92 COLUMN_LABEL_COLOR_LINE,
96 vcount_prio := create_column_title(
97 COLUMN_LABEL_PRIORITY,
98 COLUMN_PADDING_PRIORITY,
99 COLUMN_LABEL_COLOR_PRIORITY,
103 vcount_author := create_column_title(
105 COLUMN_PADDING_AUTHOR,
106 COLUMN_LABEL_COLOR_AUTHOR,
110 append(*buf, SEPARATOR_CORNER);
112 table_header_visual_count += vcount_line
116 return builder_to_string(*buf);
121 row: u16 = 0; // not in use
122 col: u16 = TERMINAL_MIN_WIDTH;
123 xpixel: u16 = 0; // not in use
124 ypixel: u16 = 0; // not in use
128section_title :: (label: string, term: Winsize) {
129 title, vcount_title := paint(
130 tprint(" File: % ", label),
136 pref, vcount_pref := paint("o-", fg = .CYAN);
138 header := string_pad_right(
139 tprint("%%", pref, title),
140 term.col + vcount_title + vcount_pref - (PADDING - 1),
141 paint(HLINE, fg = .CYAN, no_termination = true)
146 print(paint_reset());
150tokens_print :: (tokens: [..]Token, label: string, term: Winsize) {
152 header_print(label, term);
154 for tokens print("%\n", lines_assemble(it, term));
158header_print :: (label: string, term: Winsize) {
159 title, title_vcount := paint(
161 fg = COLUMN_LABEL_COLOR_KEYWORD,
165 width_adapted := table_header_visual_count + title_vcount;
167 header := string_pad_right(
169 term.col - PADDING - TABLE_HEADER.count + width_adapted + 1,
173 print("%%\n", TABLE_HEADER, header);
176word_wrap_and_append :: (
177 buf: *String_Builder,
182 tab_to_keyword_column :: () #expand {
184 for 0..`columns_count-1 append(`buf, " ");
185 `current_line_width = `columns_count;
188 find_whitespace :: (s: string, pos: int) -> int {
190 for i: pos..s.count-1 {
192 if is_space(s[i]) then return c;
199 legal_term_width := current_width - PADDING;
200 idx_column: int = columns_count;
203 while idx_field < comment.count {
204 ws_pos := find_whitespace(comment, idx_field);
205 word_length := (idx_field + ws_pos) - idx_field;
207 if idx_column + word_length >= legal_term_width {
209 for 0..columns_count-1 append(buf, " ");
210 idx_column = columns_count;
213 if idx_column + word_length >= legal_term_width {
214 for idx_column..legal_term_width {
215 append(buf, comment[idx_field]);
221 append(buf, comment[idx_field]);
227lines_assemble :: (token: Token, terminal: Winsize) -> string {
232 fgc: Color_Foreground,
234 pad_proc: (string, int, string) -> string
238 str, vcount := paint(tprint("%", elem), fg = fgc);
239 out := pad_proc(str, width + vcount, filler);
245 init_string_builder(*buf);
247 line, vcount_line := make_string(
250 COLUMN_LABEL_COLOR_LINE,
255 priority, vcount_prio := make_string(
258 COLUMN_LABEL_COLOR_PRIORITY,
259 COLUMN_WIDTH_PRIORITY,
263 author, vcount_author := make_string(
266 COLUMN_LABEL_COLOR_AUTHOR,
271 current_width := terminal.col - PADDING;
273 columns_author_count := SEPARATOR_FIRST.count
274 + (SEPARATOR.count * 2)
275 + abs(line.count - vcount_line)
276 + abs(priority.count - vcount_prio);
278 columns_comment_count := columns_author_count
280 + abs(author.count - vcount_author);
282 append(*buf, SEPARATOR_FIRST);
284 append(*buf, SEPARATOR);
285 append(*buf, priority);
286 append(*buf, SEPARATOR);
287 append(*buf, author);
288 append(*buf, SEPARATOR);
290 word_wrap_and_append(
293 columns_comment_count,
297 return builder_to_string(*buf);
300terminal_info_size :: () -> term: Winsize {
302 error_code := ioctl(STDOUT_FILENO, TIOCGWINSZ, *w);
306 "[Warning]: Could not get terminal information. Falling back to defaults."