Skip to content

Commit ef918b7

Browse files
committed
chore(tui): improve TUI layout and styling
1 parent 2cf292b commit ef918b7

2 files changed

Lines changed: 77 additions & 38 deletions

File tree

internal/tui/components/layout.go

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,59 @@ func (l *Layout) SetSize(width, height int) {
1919
l.height = height
2020
}
2121

22+
func (l Layout) Header(title string) string {
23+
return styles.HeaderStyle.
24+
Width(l.width).
25+
Render(title)
26+
}
27+
28+
func (l Layout) Footer(instructions string) string {
29+
return styles.FooterStyle.
30+
Width(l.width).
31+
Render(instructions)
32+
}
33+
34+
func (l Layout) Content(content string, headerHeight, footerHeight int) string {
35+
contentHeight := l.height - headerHeight - footerHeight
36+
if contentHeight < 0 {
37+
contentHeight = 0
38+
}
39+
40+
return styles.ContentStyle.
41+
Width(l.width).
42+
Height(contentHeight).
43+
Render(content)
44+
}
45+
2246
func (l Layout) FullView(title, content, instructions string) string {
2347
if l.width < 20 || l.height < 10 {
2448
return content
2549
}
2650

51+
// Calculate window dimensions (85% of terminal width, 80% height)
2752
windowWidth := int(float64(l.width) * 0.85)
2853
windowHeight := int(float64(l.height) * 0.8)
2954

55+
// Ensure minimum dimensions
3056
if windowWidth < 50 {
3157
windowWidth = 50
3258
}
3359
if windowHeight < 15 {
3460
windowHeight = 15
3561
}
3662

37-
innerWidth := windowWidth - 4
63+
// Calculate inner content dimensions (accounting for border)
64+
innerWidth := windowWidth - 4 // 2 chars for border + padding
3865
innerHeight := windowHeight - 4
39-
header := styles.WindowHeaderStyle.Copy().
66+
67+
// Create header and content with simplified, consistent styling
68+
header := lipgloss.NewStyle().
4069
Width(innerWidth).
70+
Padding(1, 2).
71+
Background(styles.Primary).
72+
Foreground(styles.TextPrimary).
73+
Bold(true).
74+
Align(lipgloss.Center).
4175
Render(title)
4276

4377
headerHeight := lipgloss.Height(header)
@@ -47,48 +81,66 @@ func (l Layout) FullView(title, content, instructions string) string {
4781
contentHeight = 1
4882
}
4983

50-
contentArea := styles.WindowContentStyle.Copy().
84+
contentArea := lipgloss.NewStyle().
5185
Width(innerWidth).
5286
Height(contentHeight).
87+
Padding(1, 2).
5388
Render(content)
5489

90+
// Join header and content vertically (no footer)
5591
windowContent := lipgloss.JoinVertical(
5692
lipgloss.Left,
5793
header,
5894
contentArea,
5995
)
6096

61-
borderedWindow := styles.WindowBorderStyle.Copy().
97+
// Create bordered window
98+
borderedWindow := lipgloss.NewStyle().
99+
Border(lipgloss.RoundedBorder()).
100+
BorderForeground(lipgloss.Color("15")). // White border
62101
Width(windowWidth).
63102
Height(windowHeight).
64103
Render(windowContent)
65104

105+
// Create elegant app branding banner at top
66106
brandingText := "Req - Test APIs with Terminal Velocity"
67-
appBranding := styles.AppBrandingStyle.Copy().
107+
appBranding := lipgloss.NewStyle().
68108
Width(l.width).
109+
Align(lipgloss.Center).
110+
Foreground(lipgloss.Color("230")). // Soft cream
111+
// Background(lipgloss.Color("237")). // Dark gray background
112+
Bold(true).
113+
Padding(1, 4).
114+
Margin(1, 0).
69115
Render(brandingText)
70116

71-
footer := styles.WindowFooterStyle.Copy().
117+
// Create footer outside the window
118+
footer := lipgloss.NewStyle().
72119
Width(l.width).
120+
Padding(0, 2).
121+
Foreground(styles.TextSecondary).
122+
Align(lipgloss.Center).
73123
Render(instructions)
74124

125+
// Calculate vertical position accounting for branding and footer
75126
brandingHeight := lipgloss.Height(appBranding)
76127
footerHeight := lipgloss.Height(footer)
77-
windowPlacementHeight := l.height - brandingHeight - footerHeight - 4
128+
windowPlacementHeight := l.height - brandingHeight - footerHeight - 4 // Extra padding
78129

79130
centeredWindow := lipgloss.Place(
80131
l.width, windowPlacementHeight,
81132
lipgloss.Center, lipgloss.Center,
82133
borderedWindow,
83134
)
84135

136+
// Combine branding, centered window, and footer with proper spacing
85137
return lipgloss.JoinVertical(
86138
lipgloss.Left,
87-
"",
139+
"", // Top padding
88140
appBranding,
89-
"",
141+
"", // Extra spacing line
90142
centeredWindow,
91-
"",
143+
"", // Reduced spacing before footer
92144
footer,
93145
)
94146
}

internal/tui/styles/layout.go

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,21 @@ package styles
33
import "github.com/charmbracelet/lipgloss"
44

55
var (
6-
// Window and layout styles
7-
WindowHeaderStyle = lipgloss.NewStyle().
8-
Padding(1, 2).
9-
Background(Primary).
10-
Foreground(TextPrimary).
11-
Bold(true).
12-
Align(lipgloss.Center)
13-
14-
WindowContentStyle = lipgloss.NewStyle().
15-
Padding(1, 2)
16-
17-
WindowBorderStyle = lipgloss.NewStyle().
18-
Border(lipgloss.RoundedBorder()).
19-
BorderForeground(lipgloss.Color("15")) // White border
20-
21-
AppBrandingStyle = lipgloss.NewStyle().
22-
Align(lipgloss.Center).
23-
Foreground(lipgloss.Color("230")). // Soft cream
24-
Bold(true).
25-
Padding(1, 4).
26-
Margin(1, 0)
27-
28-
WindowFooterStyle = lipgloss.NewStyle().
29-
Padding(0, 2).
30-
Foreground(TextSecondary).
31-
Align(lipgloss.Center)
32-
33-
// List and item styles
6+
HeaderStyle = lipgloss.NewStyle().
7+
Padding(1, 2).
8+
Background(Primary).
9+
Foreground(TextPrimary).
10+
Bold(true).
11+
Align(lipgloss.Center)
12+
13+
FooterStyle = lipgloss.NewStyle().
14+
Padding(0, 2).
15+
Foreground(TextSecondary).
16+
Align(lipgloss.Center)
17+
18+
ContentStyle = lipgloss.NewStyle().
19+
Padding(1, 2)
20+
3421
ListItemStyle = lipgloss.NewStyle().
3522
PaddingLeft(4)
3623

0 commit comments

Comments
 (0)