refactor: removed is_tty.

This commit is contained in:
2026-06-12 15:54:27 -04:00
parent 23b8c2dc67
commit d56f11250c
7 changed files with 15 additions and 16 deletions

View File

@@ -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.

View File

@@ -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)

View File

@@ -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)

View File

@@ -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))
}
}

View File

@@ -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))

View File

@@ -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")

View File

@@ -1,8 +0,0 @@
package main
import "core:sys/posix"
is_tty :: proc() -> bool {
return bool(posix.isatty(1))
}