Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions pkg/leantui/banner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,21 @@ func TestCommitWelcomePadsBanner(t *testing.T) {
helpLine := ansi.Strip(lines[len(lines)-1])
assert.True(t, strings.HasPrefix(helpLine, leftPad))
}

func TestCommitWelcomeUsesConfiguredBanner(t *testing.T) {
t.Parallel()
custom := []string{"custom banner line one", "custom banner line two"}
m := &model{screen: ui.NewScreen("", "", ""), banner: custom}
m.commitWelcome()

require.Equal(t, 1, m.screen.Transcript.BlockCount())
lines := m.screen.Transcript.BlockLines(0, 80)
require.GreaterOrEqual(t, len(lines), bannerTopPadding+len(custom))

leftPad := strings.Repeat(" ", bannerLeftPadding)
for i, want := range custom {
assert.Equal(t, leftPad+want, ansi.Strip(lines[bannerTopPadding+i]))
}
// The configured banner replaces the built-in art, it does not append to it.
assert.NotEqual(t, leftPad+bannerLines[0], ansi.Strip(lines[bannerTopPadding]))
}
15 changes: 13 additions & 2 deletions pkg/leantui/leantui.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ type Config struct {

AppName string
DisabledCommands []string

// Banner overrides the ASCII-art welcome banner. When nil the built-in
// bannerLines ("docker agent") is used; embedders set it to brand the lean
// TUI with their own art (each line ideally within 56 columns).
Banner []string
}

// Run drives the lean TUI until the user exits. It owns the terminal (raw
Expand Down Expand Up @@ -159,6 +164,7 @@ type model struct {

quitting bool
appName string
banner []string
disabledCommands map[string]bool
}

Expand Down Expand Up @@ -189,6 +195,7 @@ func newModel(term *ui.Terminal, cfg Config) *model {
sessionState: sessionState,
usage: ui.NewUsageTracker(),
appName: appName,
banner: cfg.Banner,
disabledCommands: disabled,
}
}
Expand All @@ -208,14 +215,18 @@ func (m *model) renderFinal() {
}

func (m *model) commitWelcome() {
banner := m.banner
if len(banner) == 0 {
banner = bannerLines
}
m.screen.Transcript.AddBlock(func(int) []string {
lines := make([]string, 0, bannerTopPadding+len(bannerLines)+2)
lines := make([]string, 0, bannerTopPadding+len(banner)+2)
for range bannerTopPadding {
lines = append(lines, "")
}

leftPad := strings.Repeat(" ", bannerLeftPadding)
for _, l := range bannerLines {
for _, l := range banner {
lines = append(lines, ui.StAccent().Render(leftPad+l))
}
lines = append(lines,
Expand Down
Loading