fix(ui): show status and errors in a line above the footer (U-P1-1)

m.status was set in ~200 places but never rendered. A single status line
now sits between the panels and the footer, coloured by wording (error /
warning / info); the filter bar takes the same slot instead of growing
the view past the terminal height. Local mkdir now fails on an existing
name instead of silently reporting success.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
vrubelroman 2026-10-31 23:03:53 +03:00
parent 829b1237b2
commit 511375492a
3 changed files with 120 additions and 3 deletions

View file

@ -333,7 +333,12 @@ func MoveToTrash(path string) error {
func MakeDir(parent string, name string) (string, error) { func MakeDir(parent string, name string) (string, error) {
target := filepath.Join(parent, name) target := filepath.Join(parent, name)
if err := os.MkdirAll(target, 0o755); err != nil { // Parents may be created ("a/b"), but the final directory must be new:
// MkdirAll silently "succeeded" on an existing name.
if err := os.MkdirAll(filepath.Dir(target), 0o755); err != nil {
return "", err
}
if err := os.Mkdir(target, 0o755); err != nil {
return "", err return "", err
} }
return target, nil return target, nil

View file

@ -0,0 +1,45 @@
package ui
// Regression tests for the stage-1 hotfixes (plans/rework/03-tasks.md).
import (
"os"
"path/filepath"
"strings"
"testing"
)
// U-P1-1: status/error messages were assigned but never rendered.
func TestStatusVisible(t *testing.T) {
dir := t.TempDir()
if err := os.Mkdir(filepath.Join(dir, "taken"), 0o755); err != nil {
t.Fatal(err)
}
d := newDriver(t, dir, t.TempDir())
d.Press("f7")
d.Type("taken")
d.Press("enter")
d.Settle(settle)
status := cur(t, d).status
if classifyStatus(status) != statusError {
t.Fatalf("mkdir over existing dir should report an error, status=%q", status)
}
screen := d.Screen()
if !strings.Contains(screen, status) {
t.Fatalf("error %q not on screen:\n%s", status, screen)
}
lines := strings.Split(screen, "\n")
if len(lines) != 40 {
t.Fatalf("view must keep terminal height 40, got %d lines", len(lines))
}
}
func TestStatusLineKeepsHeightWhileFiltering(t *testing.T) {
dir := t.TempDir()
d := newDriver(t, dir, t.TempDir())
d.Press("/")
d.Type("x")
if n := len(strings.Split(d.Screen(), "\n")); n != 40 {
t.Fatalf("filter bar must replace the status line, view has %d lines", n)
}
}

View file

@ -1264,8 +1264,14 @@ func (m Model) View() string {
parts := make([]string, 0, 3) parts := make([]string, 0, 3)
parts = append(parts, panels) parts = append(parts, panels)
if m.filterMode { if !m.viewMode {
parts = append(parts, renderFilterBar(m)) // One line between panels and footer: the filter input while
// filtering, otherwise the last status/error message.
if m.filterMode {
parts = append(parts, renderFilterBar(m))
} else {
parts = append(parts, renderStatusLine(m))
}
} }
if m.cfg.UI.ShowFooter && !m.viewMode { if m.cfg.UI.ShowFooter && !m.viewMode {
parts = append(parts, renderFooter(m)) parts = append(parts, renderFooter(m))
@ -3469,6 +3475,9 @@ func (m *Model) bodyHeight() int {
if m.cfg.UI.ShowFooter && !m.viewMode { if m.cfg.UI.ShowFooter && !m.viewMode {
height-- height--
} }
if !m.viewMode {
height-- // status line / filter bar
}
return max(height, 8) return max(height, 8)
} }
@ -3772,6 +3781,64 @@ func renderFooter(m Model) string {
return line return line
} }
// statusLevel classifies a status message by its wording so errors stand
// out. Statuses are free-form strings set in ~200 places; this keeps the
// hotfix local instead of threading a level through all of them.
type statusLevel int
const (
statusInfo statusLevel = iota
statusWarn
statusError
)
var (
statusErrorWords = []string{
"fail", "error", "denied", "cannot", "can't", "no such", "not found",
"refus", "invalid", "must not", "unable", "not connected", "already exists",
"file exists", "not empty", "not permitted", "panic", "interrupted",
}
statusWarnWords = []string{
"read-only", "disabled", "nothing to", "cancel", "select ", "not supported",
"not available", "already running", "no directory history", "no forward history",
"no entry selected", "press y again", "blocked", "not allowed",
}
)
func classifyStatus(s string) statusLevel {
l := strings.ToLower(s)
for _, w := range statusErrorWords {
if strings.Contains(l, w) {
return statusError
}
}
for _, w := range statusWarnWords {
if strings.Contains(l, w) {
return statusWarn
}
}
return statusInfo
}
func renderStatusLine(m Model) string {
text := strings.Join(strings.Fields(m.status), " ") // single line
fg := m.palette.Muted
prefix := " "
switch classifyStatus(text) {
case statusError:
fg = m.palette.Danger
prefix = " ! "
case statusWarn:
fg = m.palette.Warning
}
style := lipgloss.NewStyle().Background(m.palette.StatusBar).Foreground(fg)
line := ansi.Truncate(prefix+text, m.width, "…")
if fill := m.width - ansi.StringWidth(line); fill > 0 {
line += strings.Repeat(" ", fill)
}
return style.Render(line)
}
func renderFilterBar(m Model) string { func renderFilterBar(m Model) string {
prompt := lipgloss.NewStyle(). prompt := lipgloss.NewStyle().
Background(m.palette.Footer). Background(m.palette.Footer).