diff --git a/internal/fs/ops.go b/internal/fs/ops.go index 4c07c80..c455c40 100644 --- a/internal/fs/ops.go +++ b/internal/fs/ops.go @@ -333,7 +333,12 @@ func MoveToTrash(path string) error { func MakeDir(parent string, name string) (string, error) { 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 target, nil diff --git a/internal/ui/hotfix_test.go b/internal/ui/hotfix_test.go new file mode 100644 index 0000000..a155e7c --- /dev/null +++ b/internal/ui/hotfix_test.go @@ -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) + } +} diff --git a/internal/ui/model.go b/internal/ui/model.go index 3977c51..1d09bf1 100644 --- a/internal/ui/model.go +++ b/internal/ui/model.go @@ -1264,8 +1264,14 @@ func (m Model) View() string { parts := make([]string, 0, 3) parts = append(parts, panels) - if m.filterMode { - parts = append(parts, renderFilterBar(m)) + if !m.viewMode { + // 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 { parts = append(parts, renderFooter(m)) @@ -3469,6 +3475,9 @@ func (m *Model) bodyHeight() int { if m.cfg.UI.ShowFooter && !m.viewMode { height-- } + if !m.viewMode { + height-- // status line / filter bar + } return max(height, 8) } @@ -3772,6 +3781,64 @@ func renderFooter(m Model) string { 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 { prompt := lipgloss.NewStyle(). Background(m.palette.Footer).