mirror of
https://github.com/sbrow/envr.git
synced 2026-06-27 10:38:33 -04:00
refactor(odin): ported deps command, added utilities (features, tty, table).
This commit is contained in:
1
cli.odin
1
cli.odin
@@ -13,6 +13,7 @@ Command :: struct {
|
||||
|
||||
IMPLEMENTED_COMMANDS := []string{
|
||||
"version",
|
||||
"deps",
|
||||
}
|
||||
|
||||
parse_args :: proc() -> (cmd: Command, ok: bool) {
|
||||
|
||||
@@ -19,6 +19,8 @@ main :: proc() {
|
||||
switch cmd.name {
|
||||
case "version":
|
||||
cmd_version(&cmd)
|
||||
case "deps":
|
||||
cmd_deps(&cmd)
|
||||
case:
|
||||
fmt.printf("Unknown command: %s\n", cmd.name)
|
||||
print_usage()
|
||||
|
||||
18
table.odin
18
table.odin
@@ -9,14 +9,15 @@ render_table :: proc(headers: []string, rows: [][]string) {
|
||||
return
|
||||
}
|
||||
|
||||
col_widths := make([dynamic]int, len(headers))
|
||||
col_widths := make([dynamic]int, 0, len(headers))
|
||||
for i in 0..<len(headers) {
|
||||
append(&col_widths, len(headers[i]))
|
||||
append(&col_widths, strings.rune_count(headers[i]))
|
||||
}
|
||||
for r in rows {
|
||||
for i in 0..<len(r) {
|
||||
if i < len(col_widths) && len(r[i]) > col_widths[i] {
|
||||
col_widths[i] = len(r[i])
|
||||
w := strings.rune_count(r[i])
|
||||
if i < len(col_widths) && w > col_widths[i] {
|
||||
col_widths[i] = w
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,9 +45,14 @@ render_table :: proc(headers: []string, rows: [][]string) {
|
||||
|
||||
hline(&b, "\u250c", "\u252c", "\u2510", col_widths)
|
||||
|
||||
cell :: proc(b: ^strings.Builder, s: string, width: int) {
|
||||
extra := len(s) - strings.rune_count(s)
|
||||
fmt.sbprintf(b, " %-*s \u2502", width + extra, s)
|
||||
}
|
||||
|
||||
strings.write_string(&b, "\u2502")
|
||||
for i in 0..<len(headers) {
|
||||
fmt.sbprintf(&b, " %-*s \u2502", col_widths[i], headers[i])
|
||||
cell(&b, headers[i], col_widths[i])
|
||||
}
|
||||
fmt.println(strings.to_string(b))
|
||||
strings.builder_reset(&b)
|
||||
@@ -56,7 +62,7 @@ render_table :: proc(headers: []string, rows: [][]string) {
|
||||
for r in rows {
|
||||
strings.write_string(&b, "\u2502")
|
||||
for i in 0..<len(r) {
|
||||
fmt.sbprintf(&b, " %-*s \u2502", col_widths[i], r[i])
|
||||
cell(&b, r[i], col_widths[i])
|
||||
}
|
||||
fmt.println(strings.to_string(b))
|
||||
strings.builder_reset(&b)
|
||||
|
||||
Reference in New Issue
Block a user