mirror of
https://github.com/sbrow/envr.git
synced 2026-06-27 10:38:33 -04:00
refactor: Fixed duplicate terminal checks.
This commit is contained in:
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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]))
|
||||
|
||||
Reference in New Issue
Block a user