Skip to content

Commit aeb8c8e

Browse files
authored
Merge pull request #40 from hugoh/output-title
fix(tui): added command to output window
2 parents cf298f5 + d07e172 commit aeb8c8e

5 files changed

Lines changed: 62 additions & 2 deletions

File tree

internal/tui/commands.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"strings"
78

89
tea "charm.land/bubbletea/v2"
910
"github.com/google/shlex"
@@ -127,6 +128,7 @@ func execCmd(m *model, selected []string, prefix, cmdStr string) tea.Cmd {
127128
m.execTotal = len(selected)
128129
m.execResults = nil
129130
m.execOutputStr = ""
131+
m.execLabel = strings.TrimSpace(prefix + " " + cmdStr)
130132

131133
concurrency := m.cfg.Settings.Concurrency
132134

internal/tui/commands_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,30 @@ func TestExecCmd(t *testing.T) {
4040
require.NotNil(t, cmd)
4141
}
4242

43+
func TestExecCmdSetsLabel(t *testing.T) {
44+
tests := []struct {
45+
name string
46+
prefix string
47+
cmdStr string
48+
wantLabel string
49+
}{
50+
{"vcs shortcut", "", "status", "status"},
51+
{"git command", "git", "diff HEAD", "git diff HEAD"},
52+
{"shell command", "sh", "ls -la", "sh ls -la"},
53+
}
54+
55+
for _, tt := range tests {
56+
t.Run(tt.name, func(t *testing.T) {
57+
m := &model{
58+
cfg: config.Config{Settings: config.Settings{Concurrency: 1}},
59+
}
60+
61+
execCmd(m, nil, tt.prefix, tt.cmdStr)
62+
assert.Equal(t, tt.wantLabel, m.execLabel)
63+
})
64+
}
65+
}
66+
4367
func TestShortcutCmdPrefixIndependent(t *testing.T) {
4468
tests := []struct {
4569
name string

internal/tui/model.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ type model struct {
185185
execCancel context.CancelFunc
186186
execResults []execResult
187187
execOutputStr string
188+
execLabel string
188189
resultsCh <-chan runner.Result
189190

190191
statusCh <-chan runner.StatusResult

internal/tui/view.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,16 @@ func (*model) renderFooter() string {
205205
}
206206

207207
func (m *model) outputView() string {
208+
label := m.execLabel
209+
if label == "" {
210+
label = "Output"
211+
}
212+
208213
var header string
209214
if m.executing {
210-
header = styleHeader.Render(" Output " + m.spinner.View() + " ")
215+
header = styleHeader.Render(" " + label + " " + m.spinner.View() + " ")
211216
} else {
212-
header = styleHeader.Render(" Output ")
217+
header = styleHeader.Render(" " + label + " ")
213218
}
214219

215220
sep := styleSeparator.Render(strings.Repeat(separatorChar, m.width))

internal/tui/view_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,34 @@ func TestOutputView(t *testing.T) {
104104
assert.Contains(t, view, "Output")
105105
}
106106

107+
func TestOutputViewWithLabel(t *testing.T) {
108+
tests := []struct {
109+
name string
110+
execLabel string
111+
want string
112+
}{
113+
{"vcs shortcut", "status", "status"},
114+
{"git command", "git diff HEAD", "git diff HEAD"},
115+
{"shell command", "sh ls -la", "sh ls -la"},
116+
{"no label falls back", "", "Output"},
117+
}
118+
119+
for _, tt := range tests {
120+
t.Run(tt.name, func(t *testing.T) {
121+
m := &model{
122+
screen: screenOutput,
123+
width: 80,
124+
height: 30,
125+
execLabel: tt.execLabel,
126+
output: viewport.New(viewport.WithWidth(80), viewport.WithHeight(10)),
127+
}
128+
m.ready = true
129+
130+
assert.Contains(t, m.outputView(), tt.want)
131+
})
132+
}
133+
}
134+
107135
func TestOutputViewExecuting(t *testing.T) {
108136
m := &model{
109137
screen: screenOutput,

0 commit comments

Comments
 (0)