From a96b1a54b29a88def905931e46b3bce32cf3129a Mon Sep 17 00:00:00 2001 From: Ilker Manap Date: Sat, 3 Oct 2026 23:47:26 +0200 Subject: [PATCH] Hugging Face in the console: models that chat when browsing, ages read at a glance, long menus scroll Co-Authored-By: Claude Opus 5.5 (1M context) --- internal/cli/tui_actions.go | 15 ++++++++++++++- internal/cli/tui_hf.go | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/internal/cli/tui_actions.go b/internal/cli/tui_actions.go index ae67aef..47cd17f 100644 --- a/internal/cli/tui_actions.go +++ b/internal/cli/tui_actions.go @@ -244,13 +244,26 @@ func (m consoleModel) actionDialog() (title, body string) { return m.confirmD.title, m.confirmD.text + "\n\n" + sDim.Render("Y yes · any other key no") case m.menuD != nil: var b strings.Builder - for i, it := range m.menuD.items { + // A long menu shows the part around the choice. + items, first := m.menuD.items, 0 + if room := max(5, m.height-12); len(items) > room { + first = min(max(0, m.menuD.sel-room/2), len(items)-room) + items = items[first : first+room] + if first > 0 { + b.WriteString(sDim.Render(" ↑ more") + "\n") + } + } + for j, it := range items { + i := first + j if i == m.menuD.sel { b.WriteString(fSelected.Render("› "+it.label) + "\n") } else { b.WriteString(" " + it.label + "\n") } } + if first+len(items) < len(m.menuD.items) { + b.WriteString(sDim.Render(" ↓ more") + "\n") + } b.WriteString("\n" + sDim.Render("↑↓ choose · Enter · Esc close")) return m.menuD.title, b.String() } diff --git a/internal/cli/tui_hf.go b/internal/cli/tui_hf.go index 14e87ca..4b106bb 100644 --- a/internal/cli/tui_hf.go +++ b/internal/cli/tui_hf.go @@ -60,7 +60,13 @@ func (m consoleModel) fetchHF() tea.Cmd { return func() tea.Msg { ctx, cancel := context.WithTimeout(context.Background(), 25*time.Second) defer cancel() - got, err := c.Explore(ctx, hf.Query{Search: q, Sort: hfSorts[sort].sort, GGUF: true, Limit: 50}) + hq := hf.Query{Search: q, Sort: hfSorts[sort].sort, GGUF: true, Limit: 50} + // Browsing: models that chat. A search finds the rest too, an + // embedding model included. + if q == "" { + hq.Task = "text-generation" + } + got, err := c.Explore(ctx, hq) return consoleHFMsg{query: q, sort: sort, models: got, err: err} } } @@ -164,6 +170,9 @@ func (m consoleModel) hfPanel(pw int) (string, string, string) { if m.hf.query != "" { what = "“" + m.hf.query + "”, " + what } + if m.hf.query == "" { + what = "text generation, " + what + } head := "\n GGUF models on Hugging Face: " + what + "\n\n" switch { case m.hf.err != nil: @@ -183,7 +192,7 @@ func (m consoleModel) hfPanel(pw int) (string, string, string) { gated = sWarn.Render("gated") } rows = append(rows, []string{x.ID, params, x.Architecture(), compactNum(x.Downloads), compactNum(x.Likes), - ago(x.LastModified, time.Now()), gated}) + ageShort(x.LastModified), gated}) } if len(rows) == 0 { return "Serve from Hugging Face", head + " " + sDim.Render("Nothing found. / searches again."), keys @@ -191,3 +200,22 @@ func (m consoleModel) hfPanel(pw int) (string, string, string) { return "Serve from Hugging Face", head + table([]string{"REPOSITORY", "SIZE", "ARCH", "DOWNLOADS", "LIKES", "UPDATED", ""}, rows, m.row, pw, m.inPanel), keys } + +// ageShort is how long ago, in the largest unit that says it: 5m, 3h, 12d, 7mo, 2y. +func ageShort(t time.Time) string { + if t.IsZero() { + return "" + } + d := time.Since(t) + switch { + case d < time.Hour: + return fmt.Sprintf("%dm ago", int(d.Minutes())) + case d < 48*time.Hour: + return fmt.Sprintf("%dh ago", int(d.Hours())) + case d < 60*24*time.Hour: + return fmt.Sprintf("%dd ago", int(d.Hours()/24)) + case d < 2*365*24*time.Hour: + return fmt.Sprintf("%dmo ago", int(d.Hours()/24/30)) + } + return fmt.Sprintf("%dy ago", int(d.Hours()/24/365)) +}