From d56f11250cb3a082aaa31a3b9e8c065c3d783979 Mon Sep 17 00:00:00 2001 From: Spencer Brower Date: Fri, 12 Jun 2026 15:54:27 -0400 Subject: [PATCH] refactor: removed `is_tty`. --- TODOS.md | 2 -- cmd_list.odin | 4 +++- cmd_scan.odin | 4 +++- cmd_sync.odin | 5 ++++- scan.odin | 5 +++-- table.odin | 3 ++- tty.odin | 8 -------- 7 files changed, 15 insertions(+), 16 deletions(-) delete mode 100644 tty.odin diff --git a/TODOS.md b/TODOS.md index 7948598..18b9fd4 100644 --- a/TODOS.md +++ b/TODOS.md @@ -52,8 +52,6 @@ Note: These todos can wait until all the subcommands have been ported. 21. Check for prealloc opportunities. i.e. `make([dynamic]string)` -> `make([dynamic]string, 5)`. -22. Replace is_tty with terminal.is_terminal - 23. Add a text filter to the multi_select. 24. Create backup / fallback fd. diff --git a/cmd_list.odin b/cmd_list.odin index 67d746c..a16ae8d 100644 --- a/cmd_list.odin +++ b/cmd_list.odin @@ -2,8 +2,10 @@ package main import "core:encoding/json" import "core:fmt" +import "core:os" import "core:path/filepath" import "core:strings" +import "core:terminal" ListEntry :: struct { Directory: string `json:"directory"`, @@ -23,7 +25,7 @@ cmd_list :: proc(cmd: ^Command) { } defer delete(rows) - if is_tty() { + if terminal.is_terminal(os.stdout) { headers := []string{"Directory", "Path"} table_rows := make([dynamic][]string, 0, len(rows), context.temp_allocator) diff --git a/cmd_scan.odin b/cmd_scan.odin index 987a96a..5d94fef 100644 --- a/cmd_scan.odin +++ b/cmd_scan.odin @@ -2,6 +2,8 @@ package main import "core:encoding/json" import "core:fmt" +import "core:os" +import "core:terminal" cmd_scan :: proc(cmd: ^Command) { feats := check_features() @@ -49,7 +51,7 @@ cmd_scan :: proc(cmd: ^Command) { return } - if !is_tty() { + if !terminal.is_terminal(os.stdout) { output, marshal_err := json.marshal(files[:]) if marshal_err != nil { fmt.printf("Error marshaling files to JSON: %v\n", marshal_err) diff --git a/cmd_sync.odin b/cmd_sync.odin index 639dfea..ad138f9 100644 --- a/cmd_sync.odin +++ b/cmd_sync.odin @@ -2,7 +2,9 @@ package main import "core:encoding/json" import "core:fmt" +import "core:os" import "core:strings" +import "core:terminal" SyncEntry :: struct { Path: string `json:"path"`, @@ -72,7 +74,7 @@ cmd_sync :: proc(cmd: ^Command) { append(&results, SyncEntry{Path = path_str, Status = status_str}) } - if is_tty() { + if terminal.is_terminal(os.stdout) { headers := []string{"File", "Status"} table_rows := make([dynamic][]string, 0, len(results)) @@ -93,3 +95,4 @@ cmd_sync :: proc(cmd: ^Command) { fmt.println(string(data)) } } + diff --git a/scan.odin b/scan.odin index 1dd49d2..b340550 100644 --- a/scan.odin +++ b/scan.odin @@ -4,13 +4,14 @@ import "core:fmt" import "core:os" import "core:strings" import "core:sync" +import "core:terminal" fd_counter: sync.Atomic_Mutex fd_seq: int // Caller is responsible for freeing paths scan_path :: proc(search_path: string, cfg: Config) -> (paths: [dynamic]string, ok: bool) { - if is_tty() { + if terminal.is_terminal(os.stdout) { fmt.printf("Searching for all files in \"%s\"...\n", search_path) } all_files, all_ok := run_fd(build_fd_args(search_path, cfg, true)) @@ -18,7 +19,7 @@ scan_path :: proc(search_path: string, cfg: Config) -> (paths: [dynamic]string, return } - if is_tty() { + if terminal.is_terminal(os.stdout) { fmt.printf("Search for unignored fies in \"%s\"...\n", search_path) } unignored_files, unignored_ok := run_fd(build_fd_args(search_path, cfg, false)) diff --git a/table.odin b/table.odin index 0f45388..f6269a8 100644 --- a/table.odin +++ b/table.odin @@ -5,9 +5,10 @@ import "core:fmt" import "core:io" import "core:os" import "core:strings" +import "core:terminal" render_table :: proc(headers: []string, rows: [][]string) { - if !is_tty() { + 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") diff --git a/tty.odin b/tty.odin deleted file mode 100644 index 8f7cb8e..0000000 --- a/tty.odin +++ /dev/null @@ -1,8 +0,0 @@ -package main - -import "core:sys/posix" - -is_tty :: proc() -> bool { - return bool(posix.isatty(1)) -} -