refactor(odin): Fixed AI mistakes.

This commit is contained in:
2026-06-12 07:14:03 -04:00
parent 2de7e20f5c
commit f8add2ad22
8 changed files with 226 additions and 42 deletions

View File

@@ -1,11 +1,16 @@
package main
import "core:encoding/json"
import "core:fmt"
import "core:io"
import "core:os"
import "core:strings"
render_table :: proc(headers: []string, rows: [][]string) {
if !is_tty() {
render_json_rows(headers, rows)
w := io.to_writer(os.to_writer(os.stdout))
render_json_rows(w, headers, rows)
io.write_string(w, "\n")
return
}
@@ -71,20 +76,22 @@ render_table :: proc(headers: []string, rows: [][]string) {
hline(&b, "\u2514", "\u2534", "\u2518", col_widths)
}
render_json_rows :: proc(headers: []string, rows: [][]string) {
fmt.print("[")
for i in 0..<len(rows) {
if i > 0 {
fmt.print(",")
render_json_rows :: proc(w: io.Writer, headers: []string, rows: [][]string) {
entries := make([dynamic]map[string]string, 0, len(rows))
defer delete(entries)
for row in rows {
entry: map[string]string
for i in 0..<len(headers) {
entry[headers[i]] = row[i]
}
fmt.print("{")
for j in 0..<len(headers) {
if j > 0 {
fmt.print(",")
}
fmt.printf("\"%s\":\"%s\"", headers[j], rows[i][j])
}
fmt.print("}")
append(&entries, entry)
}
fmt.println("]")
data, err := json.marshal(entries[:])
if err != nil {
fmt.eprintf("Error marshaling JSON: %v\n", err)
return
}
io.write_string(w, string(data))
}