Skip to content

Commit

Permalink
chore: render border more clever
Browse files Browse the repository at this point in the history
  • Loading branch information
maraisr committed Aug 1, 2023
1 parent 47ca701 commit 42145ee
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/exporter.console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ export function exporter(max_cols = 120) {

if (!spans.length) return;

let out = '';

let tmp, i;

let out = '';
let max_time = 0;
let min_time = spans[0].start;

Expand Down Expand Up @@ -42,13 +43,12 @@ export function exporter(max_cols = 120) {
let mid_str = format(t_dur / 2);
let mid_str_anchor = Math.floor(mid_str.length / 2);

out += ' '.repeat(max_time_length + 1);
out += '╭';
// spans top border
out += '╭'.padStart(max_time_col);
out += '─'.repeat(max_trace_col);
out += '╮';

out += '\n';
out += '╮\n';

// render spans
for (i = 0; (tmp = scope.spans[i++]); ) {
let start_time = tmp.start - min_time;
let end_time = (tmp.end ?? max_time) - min_time;
Expand Down Expand Up @@ -80,16 +80,16 @@ export function exporter(max_cols = 120) {
out += '\n';
}

out += ' '.repeat(max_time_length + 1);
out += '╰';
// spans bottom border
out += '╰'.padStart(max_time_col);
out += '┼';
out += '┴'.repeat(mid - 2);
out += '┼';
out += '┴'.repeat(max_trace_col - mid - 1);
out += '┼';
out += '╯';
out += '\n';
out += '╯\n';

// legend
out += '0 ms'.padStart(max_time_length + 2 + 4); // .[0 ms
out += mid_str.padStart(mid + mid_str_anchor - 4); // 0 ms
out += t_dur_str.padStart(
Expand All @@ -100,10 +100,8 @@ export function exporter(max_cols = 120) {
t_dur_str.length,
);

out += '\n';

// trailer
out += '\n';
out += '\n\n';
let t_dur_str_seg = format(t_dur / trace_cols);
let t_max_len = Math.max(t_dur_str_seg.length, t_dur_str.length);
out += tmp = `one └┘ unit is less than: ${t_dur_str_seg}\n`;
Expand Down

0 comments on commit 42145ee

Please sign in to comment.