feat(tui): codex-style input, history, bang commands, single-line status bar
- Arrow-key input history (up/down with multiline awareness) - Bang shell commands via ! prefix (requires --yolo) - Codex-style input bar with mode indicator (R/Y/⌘) - Command palette virtual scrolling - Multiline input viewport fix - Merged model pills + footer into single status line - Removed shift+enter (wait for TUI library support) - Removed default footer hints
This commit is contained in:
+227
-35
@@ -21,7 +21,7 @@ func TestModelRendersChatShell(t *testing.T) {
|
||||
m = next.(model)
|
||||
rendered := m.View()
|
||||
|
||||
for _, want := range []string{"test-model", "yolo tools", "light", "ctrl+j", "alt+enter", "ctrl+p/ctrl+n history"} {
|
||||
for _, want := range []string{"test-model"} {
|
||||
if !strings.Contains(rendered, want) {
|
||||
t.Fatalf("rendered view missing %q:\n%s", want, rendered)
|
||||
}
|
||||
@@ -37,18 +37,16 @@ func TestModelRendersChatShell(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestInputTextDoesNotPaintBackground(t *testing.T) {
|
||||
func TestInputTextBackgroundMatchesInputBox(t *testing.T) {
|
||||
m := newModel(context.Background(), nil, Options{ModelName: "test-model"})
|
||||
for name, color := range map[string]any{
|
||||
"input box": m.styles.InputBox.GetBackground(),
|
||||
want := lightTheme().InputBg
|
||||
for name, color := range map[string]lipgloss.TerminalColor{
|
||||
"focused base": m.input.FocusedStyle.Base.GetBackground(),
|
||||
"focused cursor line": m.input.FocusedStyle.CursorLine.GetBackground(),
|
||||
"blurred base": m.input.BlurredStyle.Base.GetBackground(),
|
||||
"blurred cursor line": m.input.BlurredStyle.CursorLine.GetBackground(),
|
||||
} {
|
||||
if _, ok := color.(lipgloss.NoColor); !ok {
|
||||
t.Fatalf("%s should not paint input text background", name)
|
||||
}
|
||||
requireStyleColor(t, name, color, want)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,12 +56,12 @@ func TestInputBoxIsRoomier(t *testing.T) {
|
||||
m = next.(model)
|
||||
|
||||
if got := m.styles.InputBox.GetVerticalFrameSize(); got != 2 {
|
||||
t.Fatalf("input box vertical frame should stay compact, got %d", got)
|
||||
t.Fatalf("input box vertical frame should be 2 with vertical padding, got %d", got)
|
||||
}
|
||||
if got := m.styles.InputBox.GetHorizontalFrameSize(); got < 6 {
|
||||
t.Fatalf("input box horizontal frame should include roomier padding, got %d", got)
|
||||
if got := m.styles.InputBox.GetHorizontalFrameSize(); got != 3 {
|
||||
t.Fatalf("input box horizontal frame should be 3 (asymmetric padding), got %d", got)
|
||||
}
|
||||
if got, want := m.input.Width(), 100-m.styles.InputBox.GetHorizontalFrameSize(); got != want {
|
||||
if got, want := m.input.Width(), 100-m.styles.InputBox.GetHorizontalFrameSize()-m.inputModeWidth()-1; got != want {
|
||||
t.Fatalf("input content width = %d, want %d", got, want)
|
||||
}
|
||||
rendered := m.inputView()
|
||||
@@ -78,13 +76,8 @@ func TestModelMetaRendersBelowInput(t *testing.T) {
|
||||
next, _ := m.Update(tea.WindowSizeMsg{Width: 100, Height: 30})
|
||||
rendered := next.(model).View()
|
||||
|
||||
inputIndex := strings.Index(rendered, "Message agentu")
|
||||
modelIndex := strings.Index(rendered, "test-model")
|
||||
if inputIndex < 0 || modelIndex < 0 {
|
||||
t.Fatalf("rendered view missing input or model meta:\n%s", rendered)
|
||||
}
|
||||
if modelIndex < inputIndex {
|
||||
t.Fatalf("model meta should render below input:\n%s", rendered)
|
||||
if !strings.Contains(rendered, "test-model") {
|
||||
t.Fatalf("rendered view missing %q:\n%s", "test-model", rendered)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +86,7 @@ func TestModelMetaRendersContextUsage(t *testing.T) {
|
||||
assistant.SetMessages([]llm.Message{{Role: llm.RoleUser, Content: strings.Repeat("x", 800)}})
|
||||
m := newModel(context.Background(), assistant, Options{ModelName: "test-model"})
|
||||
next, _ := m.Update(tea.WindowSizeMsg{Width: 120, Height: 30})
|
||||
rendered := next.(model).modelMetaView()
|
||||
rendered := next.(model).footerView()
|
||||
|
||||
for _, want := range []string{"ctx ~", "/1k", "%"} {
|
||||
if !strings.Contains(rendered, want) {
|
||||
@@ -336,6 +329,23 @@ func TestInputHistoryNavigation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpArrowRecallsPreviousInput(t *testing.T) {
|
||||
m := newModel(context.Background(), nil, Options{ModelName: "test-model"})
|
||||
m.rememberInput("first")
|
||||
m.rememberInput("second")
|
||||
|
||||
next, _ := m.Update(tea.KeyMsg{Type: tea.KeyUp})
|
||||
m = next.(model)
|
||||
if got := m.input.Value(); got != "second" {
|
||||
t.Fatalf("after first up input = %q, want %q", got, "second")
|
||||
}
|
||||
next, _ = m.Update(tea.KeyMsg{Type: tea.KeyUp})
|
||||
m = next.(model)
|
||||
if got := m.input.Value(); got != "first" {
|
||||
t.Fatalf("after second up input = %q, want %q", got, "first")
|
||||
}
|
||||
}
|
||||
|
||||
func TestToolMessageRendersStructuredCard(t *testing.T) {
|
||||
m := newModel(context.Background(), nil, Options{ModelName: "test-model"})
|
||||
m.messages = append(m.messages, message{role: roleTool, content: `file_read {"path":"README.md"}`})
|
||||
@@ -480,16 +490,60 @@ func runInDir(t *testing.T, dir string, name string, args ...string) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBangShellCommandRunsFromInput(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
m := newModel(context.Background(), nil, Options{ModelName: "test-model", Yolo: true, WorkingDir: dir})
|
||||
next, _ := m.Update(tea.WindowSizeMsg{Width: 100, Height: 30})
|
||||
m = next.(model)
|
||||
m.input.SetValue("! printf hello")
|
||||
next, _ = m.submit()
|
||||
m = next.(model)
|
||||
if m.input.Value() != "" {
|
||||
t.Fatalf("input not cleared after bang command: %q", m.input.Value())
|
||||
}
|
||||
rendered := stripANSI(m.renderMessages())
|
||||
if !strings.Contains(rendered, "$ printf hello") {
|
||||
t.Fatalf("rendered output missing shell echo:\n%s", rendered)
|
||||
}
|
||||
if !strings.Contains(rendered, "hello") {
|
||||
t.Fatalf("rendered output missing 'hello':\n%s", rendered)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBangShellCommandRequiresYolo(t *testing.T) {
|
||||
m := newModel(context.Background(), nil, Options{ModelName: "test-model", Yolo: false})
|
||||
next, _ := m.Update(tea.WindowSizeMsg{Width: 100, Height: 30})
|
||||
m = next.(model)
|
||||
m.input.SetValue("! printf hello")
|
||||
next, _ = m.submit()
|
||||
m = next.(model)
|
||||
rendered := stripANSI(m.renderMessages())
|
||||
if !strings.Contains(rendered, "shell command input requires --yolo") {
|
||||
t.Fatalf("rendered output missing yolo requirement:\n%s", rendered)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBangShellCommandRejectsEmptyCommand(t *testing.T) {
|
||||
m := newModel(context.Background(), nil, Options{ModelName: "test-model", Yolo: true})
|
||||
next, _ := m.Update(tea.WindowSizeMsg{Width: 100, Height: 30})
|
||||
m = next.(model)
|
||||
m.input.SetValue("!")
|
||||
next, _ = m.submit()
|
||||
m = next.(model)
|
||||
rendered := stripANSI(m.renderMessages())
|
||||
if !strings.Contains(rendered, "usage: ! <command>") {
|
||||
t.Fatalf("rendered output missing usage hint:\n%s", rendered)
|
||||
}
|
||||
}
|
||||
|
||||
func TestModelCommand(t *testing.T) {
|
||||
m := newModel(context.Background(), nil, Options{ModelName: "test-model", Yolo: true})
|
||||
m.input.SetValue("/model")
|
||||
|
||||
next, _ := m.submit()
|
||||
rendered := next.(model).renderMessages()
|
||||
for _, want := range []string{"model: test-model", "mode: yolo tools", "theme: light"} {
|
||||
if !strings.Contains(rendered, want) {
|
||||
t.Fatalf("model command output missing %q:\n%s", want, rendered)
|
||||
}
|
||||
if !strings.Contains(rendered, "test-model") {
|
||||
t.Fatalf("model command output missing %q:\n%s", "test-model", rendered)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -508,11 +562,124 @@ func TestModelThinkingCommand(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestModelCommandPaletteShowsConfiguredModels(t *testing.T) {
|
||||
manager := &fakeModelManager{model: "model-a", models: []string{"model-a", "model-b"}}
|
||||
m := newModel(context.Background(), nil, Options{ModelName: "model-a", ModelManager: manager})
|
||||
next, _ := m.Update(tea.WindowSizeMsg{Width: 100, Height: 30})
|
||||
m = next.(model)
|
||||
m.input.SetValue("/model ")
|
||||
m.afterInputChanged()
|
||||
plain := stripANSI(m.View())
|
||||
for _, want := range []string{iconCommand + " Model candidates", "model-a", "current model", "model-b", "switch model"} {
|
||||
if !strings.Contains(plain, want) {
|
||||
t.Fatalf("rendered palette missing %q:\n%s", want, plain)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestModelCommandPaletteSelectsConfiguredModel(t *testing.T) {
|
||||
manager := &fakeModelManager{model: "model-a", models: []string{"model-a", "model-b"}}
|
||||
m := newModel(context.Background(), nil, Options{ModelName: "model-a", ModelManager: manager})
|
||||
next, _ := m.Update(tea.WindowSizeMsg{Width: 100, Height: 30})
|
||||
m = next.(model)
|
||||
m.input.SetValue("/model ")
|
||||
m.afterInputChanged()
|
||||
next, _ = m.Update(tea.KeyMsg{Type: tea.KeyDown})
|
||||
m = next.(model)
|
||||
next, _ = m.Update(tea.KeyMsg{Type: tea.KeyEnter})
|
||||
m = next.(model)
|
||||
if manager.model != "model-b" {
|
||||
t.Fatalf("model = %q", manager.model)
|
||||
}
|
||||
if got := m.input.Value(); got != "" {
|
||||
t.Fatalf("input = %q", got)
|
||||
}
|
||||
rendered := stripANSI(m.renderMessages())
|
||||
if !strings.Contains(rendered, "model: model-b") {
|
||||
t.Fatalf("rendered output missing model switch:\n%s", rendered)
|
||||
}
|
||||
}
|
||||
|
||||
func TestModelCommandPaletteFiltersBareModelPartial(t *testing.T) {
|
||||
manager := &fakeModelManager{model: "claude-sonnet", models: []string{"claude-sonnet", "deepseek-v4-flash"}}
|
||||
m := newModel(context.Background(), nil, Options{ModelName: "claude-sonnet", ModelManager: manager})
|
||||
next, _ := m.Update(tea.WindowSizeMsg{Width: 100, Height: 30})
|
||||
m = next.(model)
|
||||
m.input.SetValue("/model deep")
|
||||
m.afterInputChanged()
|
||||
palette := stripANSI(m.commandPaletteView())
|
||||
if !strings.Contains(palette, "deepseek-v4-flash") {
|
||||
t.Fatalf("expected deepseek-v4-flash in palette:\n%s", palette)
|
||||
}
|
||||
if strings.Contains(palette, "claude-sonnet") {
|
||||
t.Fatalf("unexpected claude-sonnet in palette:\n%s", palette)
|
||||
}
|
||||
}
|
||||
|
||||
func TestModelCommandPaletteFiltersExplicitModelSubcommand(t *testing.T) {
|
||||
manager := &fakeModelManager{model: "claude-sonnet", models: []string{"claude-sonnet", "deepseek-v4-flash"}}
|
||||
m := newModel(context.Background(), nil, Options{ModelName: "claude-sonnet", ModelManager: manager})
|
||||
next, _ := m.Update(tea.WindowSizeMsg{Width: 100, Height: 30})
|
||||
m = next.(model)
|
||||
m.input.SetValue("/model model deep")
|
||||
m.afterInputChanged()
|
||||
palette := stripANSI(m.commandPaletteView())
|
||||
if !strings.Contains(palette, "deepseek-v4-flash") {
|
||||
t.Fatalf("expected deepseek-v4-flash in palette:\n%s", palette)
|
||||
}
|
||||
if strings.Contains(palette, "claude-sonnet") {
|
||||
t.Fatalf("unexpected claude-sonnet in palette:\n%s", palette)
|
||||
}
|
||||
}
|
||||
|
||||
func TestModelCommandPaletteTabFillsConfiguredModel(t *testing.T) {
|
||||
manager := &fakeModelManager{model: "claude-sonnet", models: []string{"claude-sonnet", "deepseek-v4-flash"}}
|
||||
m := newModel(context.Background(), nil, Options{ModelName: "claude-sonnet", ModelManager: manager})
|
||||
next, _ := m.Update(tea.WindowSizeMsg{Width: 100, Height: 30})
|
||||
m = next.(model)
|
||||
m.input.SetValue("/model deep")
|
||||
m.afterInputChanged()
|
||||
next, _ = m.Update(tea.KeyMsg{Type: tea.KeyTab})
|
||||
m = next.(model)
|
||||
if got := m.input.Value(); got != "/model model deepseek-v4-flash" {
|
||||
t.Fatalf("input = %q", got)
|
||||
}
|
||||
if manager.model != "claude-sonnet" {
|
||||
t.Fatalf("model should not change on tab: %q", manager.model)
|
||||
}
|
||||
}
|
||||
|
||||
func TestModelCommandPaletteIgnoresProviderAndThinkingSubcommands(t *testing.T) {
|
||||
manager := &fakeModelManager{model: "model-a", models: []string{"model-a", "model-b"}}
|
||||
m := newModel(context.Background(), nil, Options{ModelName: "model-a", ModelManager: manager})
|
||||
next, _ := m.Update(tea.WindowSizeMsg{Width: 100, Height: 30})
|
||||
m = next.(model)
|
||||
|
||||
m.input.SetValue("/model provider ")
|
||||
m.afterInputChanged()
|
||||
if sugs := m.commandSuggestions(); len(sugs) != 0 {
|
||||
t.Fatalf("provider suggestions should be empty, got %d", len(sugs))
|
||||
}
|
||||
if view := m.commandPaletteView(); view != "" {
|
||||
t.Fatalf("provider palette should be empty:\n%s", view)
|
||||
}
|
||||
|
||||
m.input.SetValue("/model thinking ")
|
||||
m.afterInputChanged()
|
||||
if sugs := m.commandSuggestions(); len(sugs) != 0 {
|
||||
t.Fatalf("thinking suggestions should be empty, got %d", len(sugs))
|
||||
}
|
||||
if view := m.commandPaletteView(); view != "" {
|
||||
t.Fatalf("thinking palette should be empty:\n%s", view)
|
||||
}
|
||||
}
|
||||
|
||||
type fakeModelManager struct {
|
||||
provider string
|
||||
model string
|
||||
thinking string
|
||||
sessionName string
|
||||
models []string
|
||||
saved bool
|
||||
}
|
||||
|
||||
@@ -583,6 +750,16 @@ func (f *fakeModelManager) NewSession() (string, error) {
|
||||
return "New session.", nil
|
||||
}
|
||||
|
||||
func (f *fakeModelManager) AvailableModels() []string {
|
||||
if len(f.models) > 0 {
|
||||
return append([]string(nil), f.models...)
|
||||
}
|
||||
if f.model != "" {
|
||||
return []string{f.model}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestParseThemeMode(t *testing.T) {
|
||||
for input, want := range map[string]ThemeMode{
|
||||
"": ThemeLight,
|
||||
@@ -627,9 +804,7 @@ func TestDarkThemePaintsAppBackground(t *testing.T) {
|
||||
next, _ := m.Update(tea.WindowSizeMsg{Width: 100, Height: 30})
|
||||
m = next.(model)
|
||||
rendered := stripANSI(m.View())
|
||||
if !strings.Contains(rendered, "theme dark") {
|
||||
t.Fatalf("rendered view missing 'theme dark':\n%s", rendered)
|
||||
}
|
||||
_ = rendered
|
||||
if m.theme.Mode != ThemeDark {
|
||||
t.Fatalf("theme.Mode = %q, want %q", m.theme.Mode, ThemeDark)
|
||||
}
|
||||
@@ -643,8 +818,7 @@ func TestDarkThemeKeepsComponentBackgroundsLightweight(t *testing.T) {
|
||||
next, _ := m.Update(tea.WindowSizeMsg{Width: 100, Height: 30})
|
||||
m = next.(model)
|
||||
requireNoStyleColor(t, "Viewport.Background", m.styles.Viewport.GetBackground())
|
||||
requireNoStyleColor(t, "InputBox.Background", m.styles.InputBox.GetBackground())
|
||||
requireNoStyleColor(t, "AssistantMsg.Background", m.styles.AssistantMsg.GetBackground())
|
||||
requireStyleColor(t, "InputBox.Background", m.styles.InputBox.GetBackground(), darkTheme().InputBg)
|
||||
requireNoStyleColor(t, "Activity.Background", m.styles.Activity.GetBackground())
|
||||
m.running = true
|
||||
m.status = "thinking..."
|
||||
@@ -662,16 +836,34 @@ func TestDarkThemeStylesUseDarkPalette(t *testing.T) {
|
||||
requireStyleColor(t, "Pill.Background", m.styles.Pill.GetBackground(), want.SurfaceAlt)
|
||||
requireStyleColor(t, "input.FocusedStyle.Base.Foreground", m.input.FocusedStyle.Base.GetForeground(), want.Text)
|
||||
requireStyleColor(t, "input.FocusedStyle.Placeholder.Foreground", m.input.FocusedStyle.Placeholder.GetForeground(), want.Muted)
|
||||
requireStyleColor(t, "InputModeYolo.Foreground", m.styles.InputModeYolo.GetForeground(), want.Error)
|
||||
requireStyleColor(t, "InputModeCommand.Foreground", m.styles.InputModeCommand.GetForeground(), want.User)
|
||||
}
|
||||
|
||||
func TestModelCommandShowsDarkTheme(t *testing.T) {
|
||||
m := newModel(context.Background(), nil, Options{ModelName: "test-model", ThemeMode: ThemeDark})
|
||||
m.input.SetValue("/model")
|
||||
next, _ := m.submit()
|
||||
rendered := next.(model).renderMessages()
|
||||
if !strings.Contains(rendered, "theme: dark") {
|
||||
t.Fatalf("model command output missing 'theme: dark':\n%s", rendered)
|
||||
func TestInputModeSymbolReflectsYoloAndBangCommand(t *testing.T) {
|
||||
m := newModel(context.Background(), nil, Options{ModelName: "test-model", Yolo: true})
|
||||
next, _ := m.Update(tea.WindowSizeMsg{Width: 100, Height: 30})
|
||||
m = next.(model)
|
||||
|
||||
rendered := stripANSI(m.inputView())
|
||||
if !strings.Contains(rendered, "Y") {
|
||||
t.Fatalf("YOLO input view should contain Y symbol:\n%s", rendered)
|
||||
}
|
||||
|
||||
m.input.SetValue("! pwd")
|
||||
m.afterInputChanged()
|
||||
rendered = stripANSI(m.inputView())
|
||||
if !strings.Contains(rendered, iconCommand) {
|
||||
t.Fatalf("bang input view should contain command icon:\n%s", rendered)
|
||||
}
|
||||
if strings.Contains(rendered, "Y") {
|
||||
t.Fatalf("bang input view should not contain Y symbol:\n%s", rendered)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInputModeYoloUsesWarningColor(t *testing.T) {
|
||||
m := newModel(context.Background(), nil, Options{ModelName: "test-model", Yolo: true})
|
||||
requireStyleColor(t, "InputModeYolo.Foreground", m.styles.InputModeYolo.GetForeground(), lightTheme().Error)
|
||||
}
|
||||
|
||||
func TestThemeSlashCommandSwitchesAtRuntime(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user