From fe3253f274c8557b98e8cbb681a13ee728f02b1e Mon Sep 17 00:00:00 2001 From: Spencer Brower Date: Sun, 14 Jun 2026 21:36:03 -0400 Subject: [PATCH] refactor: Fixed duplicate terminal checks. --- cmd_deps.odin | 13 ++++++++++++- table.odin | 9 --------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/cmd_deps.odin b/cmd_deps.odin index c3a7e68..6771f7c 100644 --- a/cmd_deps.odin +++ b/cmd_deps.odin @@ -1,5 +1,10 @@ package main +import "core:fmt" +import "core:io" +import "core:os" +import "core:terminal" + cmd_deps :: proc(cmd: ^Command) { feats := check_features() @@ -18,6 +23,12 @@ cmd_deps :: proc(cmd: ^Command) { append(&rows, []string{"fd", "\u2717 Missing"}) } - render_table(headers, rows[:]) + if terminal.is_terminal(os.stdout) { + render_table(headers, rows[:]) + } else { + w := io.to_writer(os.to_writer(os.stdout)) + render_json_rows(w, headers, rows[:]) + io.write_string(w, "\n") + } } diff --git a/table.odin b/table.odin index f6269a8..cf78cbf 100644 --- a/table.odin +++ b/table.odin @@ -3,18 +3,9 @@ package main import "core:encoding/json" import "core:fmt" import "core:io" -import "core:os" import "core:strings" -import "core:terminal" render_table :: proc(headers: []string, rows: [][]string) { - if !terminal.is_terminal(os.stdout) { - w := io.to_writer(os.to_writer(os.stdout)) - render_json_rows(w, headers, rows) - io.write_string(w, "\n") - return - } - col_widths := make([dynamic]int, 0, len(headers)) for i in 0 ..< len(headers) { append(&col_widths, strings.rune_count(headers[i]))