feat: underlined header texts, and one-space right pad

This commit is contained in:
Lewis Wynne 2026-02-11 14:17:48 +00:00
parent 24853bfce8
commit 1f4732823d
3 changed files with 34 additions and 30 deletions

View file

@ -192,9 +192,9 @@ pda rm kitty -i
`pda ls` to see what you've got stored. `pda ls` to see what you've got stored.
```bash ```bash
pda ls pda ls
# KEY VALUE TTL # Key Value TTL
# name Alice no expiry # name Alice no expiry
# dogs four legged mammals no expiry # dogs four legged mammals no expiry
# Or as CSV. # Or as CSV.
pda ls --format csv pda ls --format csv
@ -210,12 +210,12 @@ pda ls --format csv
Long values are truncated to fit the terminal. Use `--full`/`-f` to show the complete value. Long values are truncated to fit the terminal. Use `--full`/`-f` to show the complete value.
```bash ```bash
pda ls pda ls
# KEY VALUE TTL # Key Value TTL
# note this is a very long (..30 more chars) no expiry # note this is a very long (..30 more chars) no expiry
pda ls --full pda ls --full
# KEY VALUE TTL # Key Value TTL
# note this is a very long value that keeps on going and going no expiry # note this is a very long value that keeps on going and going no expiry
``` ```
<p align="center"></p><!-- spacer --> <p align="center"></p><!-- spacer -->
@ -554,9 +554,9 @@ pda set session2 "xyz" --ttl 54m10s
`list` shows expiration in the TTL column by default. `list` shows expiration in the TTL column by default.
```bash ```bash
pda ls pda ls
# KEY VALUE TTL # Key Value TTL
# session 123 in 59m30s # session 123 in 59m30s
# session2 xyz in 51m40s # session2 xyz in 51m40s
``` ```
`export` and `import` persist the expiry date. Expirations will continue ticking down regardless of if they're actively in a store or not - the expiry is just a timestamp, not a timer. `export` and `import` persist the expiry date. Expirations will continue ticking down regardless of if they're actively in a store or not - the expiry is just a timestamp, not a timer.
@ -644,8 +644,8 @@ pda set api-key "oops"
If the identity file is missing, encrypted values are inaccessible but not lost. Keys are still visible, and the ciphertext is preserved through reads and writes. If the identity file is missing, encrypted values are inaccessible but not lost. Keys are still visible, and the ciphertext is preserved through reads and writes.
```bash ```bash
pda ls pda ls
# KEY VALUE TTL # Key Value TTL
# api-key locked (identity file missing) no expiry # api-key locked (identity file missing) no expiry
pda get api-key pda get api-key
# FAIL cannot get 'api-key': secret is locked (identity file missing) # FAIL cannot get 'api-key': secret is locked (identity file missing)

View file

@ -189,15 +189,13 @@ func list(cmd *cobra.Command, args []string) error {
tw.Style().Options.SeparateRows = false tw.Style().Options.SeparateRows = false
tw.Style().Options.SeparateColumns = false tw.Style().Options.SeparateColumns = false
tw.Style().Box.PaddingLeft = "" tw.Style().Box.PaddingLeft = ""
tw.Style().Box.PaddingRight = " " tw.Style().Box.PaddingRight = " "
tty := stdoutIsTerminal() && listFormat.String() == "table" tty := stdoutIsTerminal() && listFormat.String() == "table"
if !listNoHeader { if !listNoHeader {
tw.AppendHeader(headerRow(columns)) tw.AppendHeader(headerRow(columns, tty))
if tty { tw.Style().Format.Header = text.FormatDefault
tw.Style().Color.Header = text.Colors{text.Bold}
}
} }
lay := computeLayout(columns, output, filtered) lay := computeLayout(columns, output, filtered)
@ -313,16 +311,22 @@ func summariseValue(s string, maxWidth int, tty bool) string {
return text.Trim(first, maxWidth) return text.Trim(first, maxWidth)
} }
func headerRow(columns []columnKind) table.Row { func headerRow(columns []columnKind, tty bool) table.Row {
h := func(s string) interface{} {
if tty {
return text.Underline.Sprint(s)
}
return s
}
row := make(table.Row, 0, len(columns)) row := make(table.Row, 0, len(columns))
for _, col := range columns { for _, col := range columns {
switch col { switch col {
case columnKey: case columnKey:
row = append(row, "Key") row = append(row, h("Key"))
case columnValue: case columnValue:
row = append(row, "Value") row = append(row, h("Value"))
case columnTTL: case columnTTL:
row = append(row, "TTL") row = append(row, h("TTL"))
} }
} }
return row return row

View file

@ -1,15 +1,15 @@
$ pda set foo 1 $ pda set foo 1
$ pda set bar 2 $ pda set bar 2
$ pda ls $ pda ls
KEY VALUE TTL Key Value TTL
a echo hello (..1 more chars) no expiry a echo hello (..1 more chars) no expiry
a1 1 no expiry a1 1 no expiry
a2 2 no expiry a2 2 no expiry
b1 3 no expiry b1 3 no expiry
bar 2 no expiry bar 2 no expiry
copied-key hidden-value no expiry copied-key hidden-value no expiry
foo 1 no expiry foo 1 no expiry
moved-key hidden-value no expiry moved-key hidden-value no expiry
$ pda rm foo --glob "*" $ pda rm foo --glob "*"
$ pda get bar --> FAIL $ pda get bar --> FAIL
FAIL cannot get 'bar': no such key FAIL cannot get 'bar': no such key