make model.header() less gross

model.showHelp() too
This commit is contained in:
Lilian Jónsdóttir 2024-07-30 21:28:09 -07:00
parent cf82990925
commit e57afe835d

View file

@ -326,19 +326,14 @@ func (m model) showHelp() string {
if !m.readonly { if !m.readonly {
if m.mode != modes.Interactive { if m.mode != modes.Interactive {
keys = append([]string{ keys = append([]string{styleKey(m.keys.doit)}, keys...)
styleKey(m.keys.doit),
}, keys...)
} }
keys = append([]string{ keys = append([]string{styleKey(m.keys.mark)}, keys...)
styleKey(m.keys.mark),
}, keys...)
} }
return strings.Join(keys, darkesttext.Render(" • ")) return strings.Join(keys, darkesttext.Render(" • "))
} }
func (m model) header() string { func (m model) header() string {
// TODO: clean this ugly thing up
var ( var (
right, left string right, left string
spacerWidth int spacerWidth int
@ -355,35 +350,32 @@ func (m model) header() string {
styleKey(m.keys.clfl), styleKey(m.keys.clfl),
styleKey(m.keys.apfl), styleKey(m.keys.apfl),
} }
dot = darkesttext.Render("•") dot = darkesttext.Render("•")
wideDot = darkesttext.Render(" • ") wideDot = darkesttext.Render(" • ")
keysFmt = strings.Join(keys, wideDot)
selectFmt = strings.Join(selectKeys, wideDot)
filterFmt = strings.Join(filterKeys, wideDot)
) )
right = " " // to offset from the table border switch {
switch m.mode { case m.filtering:
case modes.Interactive: right = fmt.Sprintf(" Filtering %s %s", dot, filterFmt)
right += strings.Join(keys, wideDot) case m.mode == modes.Interactive:
default: right = fmt.Sprintf(" %s %s %s", keysFmt, dot, selectFmt)
right += m.mode.String() left = fmt.Sprintf("%d/%d %s %s", len(m.selected), len(m.fltrfiles), dot, humanize.Bytes(uint64(m.selectsize)))
if m.workdir != "" { case m.mode == modes.Listing:
right += fmt.Sprintf(" in %s", dirs.UnExpand(m.workdir, "")) var filtered string
}
}
right += fmt.Sprintf(" %s %s", dot, strings.Join(selectKeys, wideDot))
left = fmt.Sprintf("%d/%d %s %s", len(m.selected), len(m.fltrfiles), dot, humanize.Bytes(uint64(m.selectsize)))
if m.mode == modes.Listing {
title := "Showing"
if m.filter != "" || m.filtering { if m.filter != "" || m.filtering {
title += " (filtered)" filtered = " (filtered)"
} }
right = fmt.Sprintf(" %s %d files in trash", title, len(m.fltrfiles)) right = fmt.Sprintf(" Showing%s %d files in trash", filtered, len(m.fltrfiles))
left = "" default:
} var wd string
if m.workdir != "" {
if m.filtering { wd = " in " + dirs.UnExpand(m.workdir, "")
right = fmt.Sprintf(" Filtering %s %s", dot, strings.Join(filterKeys, wideDot)) }
right = fmt.Sprintf(" %s%s %s %s", m.mode.String(), wd, dot, selectFmt)
left = fmt.Sprintf("%d/%d %s %s", len(m.selected), len(m.fltrfiles), dot, humanize.Bytes(uint64(m.selectsize)))
} }
// offset of 2 again because of table border // offset of 2 again because of table border