Skip to content

Commit 7a395ec

Browse files
Copilotwham
andauthored
Improved border styling and logging (#48)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: wham <448809+wham@users.noreply.github.com>
1 parent 0f7049f commit 7a395ec

File tree

2 files changed

+47
-59
lines changed

2 files changed

+47
-59
lines changed

main.go

Lines changed: 28 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4257,7 +4257,7 @@ func main() {
42574257
}
42584258

42594259
if err := RunLogin(homeDir); err != nil {
4260-
fmt.Fprintf(os.Stderr, "Login failed: %v\n", err)
4260+
slog.Error("Login failed", "error", err)
42614261
os.Exit(1)
42624262
}
42634263

@@ -4617,7 +4617,7 @@ func main() {
46174617
}
46184618

46194619
default:
4620-
fmt.Fprintf(os.Stderr, "Unknown command: %s\n", cmd)
4620+
slog.Error("Unknown command", "command", cmd)
46214621
fmt.Printf("Use %s -h for help\n", os.Args[0])
46224622
os.Exit(1)
46234623
}
@@ -4676,7 +4676,7 @@ func (p *UIProgress) InitItems(config *Config) {
46764676
// Start the program in a goroutine
46774677
go func() {
46784678
if _, err := p.program.Run(); err != nil {
4679-
fmt.Fprintf(os.Stderr, "Error running Bubble Tea program: %v\n", err)
4679+
slog.Error("Error running Bubble Tea program", "error", err)
46804680
}
46814681
}()
46824682

@@ -5090,42 +5090,27 @@ func (m model) View() string {
50905090
contentLines[i] = line + strings.Repeat(" ", padding)
50915091
}
50925092
}
5093+
5094+
// Add title as first line of content
5095+
titleStyle := lipgloss.NewStyle().Bold(true)
5096+
titleLine := titleStyle.Render("GitHub 🧠 pull")
5097+
// Pad title line to match content width
5098+
titlePadding := maxContentWidth - visibleLength(titleLine)
5099+
if titlePadding > 0 {
5100+
titleLine = titleLine + strings.Repeat(" ", titlePadding)
5101+
}
5102+
contentLines = append([]string{titleLine}, contentLines...)
50935103
content = strings.Join(contentLines, "\n")
50945104

5095-
// Create box without automatic width adjustment (we've done it ourselves)
5105+
// Create box with standard lipgloss borders
50965106
boxStyle := lipgloss.NewStyle().
50975107
Border(lipgloss.RoundedBorder()).
50985108
BorderForeground(borderColor).
5099-
Padding(0, 1). // 1 space padding on left and right
5109+
Padding(0, 1).
51005110
Align(lipgloss.Left)
51015111

51025112
box := boxStyle.Render(content)
51035113

5104-
// Add title to the top border while maintaining color
5105-
titleText := "GitHub 🧠 pull"
5106-
titleStyle := lipgloss.NewStyle().Bold(true).Foreground(borderColor)
5107-
borderStyle := lipgloss.NewStyle().Foreground(borderColor)
5108-
5109-
boxLines := strings.Split(box, "\n")
5110-
if len(boxLines) > 0 {
5111-
// Calculate the plain title width
5112-
titlePlainWidth := visibleLength(titleText)
5113-
// Get the full width of the first line
5114-
firstLineWidth := lipgloss.Width(boxLines[0])
5115-
// Calculate dashes needed: total width - "╭─ " (3) - title - " " (1) - "╮" (1)
5116-
dashesNeeded := firstLineWidth - 3 - titlePlainWidth - 1 - 1
5117-
if dashesNeeded < 0 {
5118-
dashesNeeded = 0
5119-
}
5120-
5121-
// Build the title line with proper coloring
5122-
boxLines[0] = borderStyle.Render("╭─ ") +
5123-
titleStyle.Render(titleText) +
5124-
borderStyle.Render(" " + strings.Repeat("─", dashesNeeded) + "╮")
5125-
5126-
box = strings.Join(boxLines, "\n")
5127-
}
5128-
51295114
return box + "\n"
51305115
}
51315116

@@ -5403,39 +5388,27 @@ func (m loginModel) View() string {
54035388
maxContentWidth = 64
54045389
}
54055390

5406-
// Create border style
5391+
// Create border style with title
54075392
borderStyle := lipgloss.NewStyle().
54085393
Border(lipgloss.RoundedBorder()).
54095394
BorderForeground(borderColor).
5395+
BorderTop(true).
5396+
BorderLeft(true).
5397+
BorderRight(true).
5398+
BorderBottom(true).
54105399
Padding(0, 1).
54115400
Width(maxContentWidth)
54125401

5413-
// Title
5414-
title := " GitHub 🧠 Login "
5415-
titleStyle := lipgloss.NewStyle().Bold(true)
5416-
54175402
box := borderStyle.Render(content)
5418-
5419-
// Replace top border with title
5420-
lines := strings.Split(box, "\n")
5421-
if len(lines) > 0 {
5422-
topBorder := lines[0]
5423-
titlePos := 2
5424-
if titlePos+len(title) < len(topBorder) {
5425-
runes := []rune(topBorder)
5426-
titleRunes := []rune(titleStyle.Render(title))
5427-
copy(runes[titlePos:], titleRunes)
5428-
lines[0] = string(runes)
5429-
}
5430-
box = strings.Join(lines, "\n")
5431-
}
54325403

54335404
return box
54345405
}
54355406

54365407
func (m loginModel) renderWaitingView() string {
54375408
var b strings.Builder
54385409

5410+
titleStyle := lipgloss.NewStyle().Bold(true)
5411+
b.WriteString(titleStyle.Render(" GitHub 🧠 Login") + "\n")
54395412
b.WriteString("\n")
54405413
b.WriteString(" 🔐 GitHub Authentication\n")
54415414
b.WriteString("\n")
@@ -5471,8 +5444,10 @@ func (m loginModel) renderWaitingView() string {
54715444
func (m loginModel) renderOrgInputView() string {
54725445
var b strings.Builder
54735446

5447+
titleStyle := lipgloss.NewStyle().Bold(true)
54745448
successStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("10"))
54755449

5450+
b.WriteString(titleStyle.Render(" GitHub 🧠 Login") + "\n")
54765451
b.WriteString("\n")
54775452
b.WriteString(" " + successStyle.Render(fmt.Sprintf("✅ Successfully authenticated as @%s", m.username)) + "\n")
54785453
b.WriteString("\n")
@@ -5488,8 +5463,10 @@ func (m loginModel) renderOrgInputView() string {
54885463
func (m loginModel) renderSuccessView() string {
54895464
var b strings.Builder
54905465

5466+
titleStyle := lipgloss.NewStyle().Bold(true)
54915467
successStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("10"))
54925468

5469+
b.WriteString(titleStyle.Render(" GitHub 🧠 Login") + "\n")
54935470
b.WriteString("\n")
54945471
b.WriteString(" " + successStyle.Render("✅ Setup complete!") + "\n")
54955472
b.WriteString("\n")
@@ -5509,8 +5486,10 @@ func (m loginModel) renderSuccessView() string {
55095486
func (m loginModel) renderErrorView() string {
55105487
var b strings.Builder
55115488

5489+
titleStyle := lipgloss.NewStyle().Bold(true)
55125490
errorStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("9"))
55135491

5492+
b.WriteString(titleStyle.Render(" GitHub 🧠 Login") + "\n")
55145493
b.WriteString("\n")
55155494
b.WriteString(" " + errorStyle.Render("❌ Authentication failed") + "\n")
55165495
b.WriteString("\n")

main.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ The app uses a registered OAuth App for authentication:
7979
3. Display the code and open browser:
8080

8181
```
82-
╭─ GitHub 🧠 Login ─────────────────────────────────────────────╮
82+
╭────────────────────────────────────────────────────────────────╮
83+
│ GitHub 🧠 Login │
8384
│ │
8485
│ 🔐 GitHub Authentication │
8586
│ │
@@ -116,7 +117,8 @@ The app uses a registered OAuth App for authentication:
116117
6. On success, prompt for organization:
117118

118119
```
119-
╭─ GitHub 🧠 Login ─────────────────────────────────────────────╮
120+
╭────────────────────────────────────────────────────────────────╮
121+
│ GitHub 🧠 Login │
120122
│ │
121123
│ ✅ Successfully authenticated as @wham │
122124
│ │
@@ -130,7 +132,8 @@ The app uses a registered OAuth App for authentication:
130132

131133
7. Save tokens (and organization if provided) to `.env` file:
132134
```
133-
╭─ GitHub 🧠 Login ─────────────────────────────────────────────╮
135+
╭────────────────────────────────────────────────────────────────╮
136+
│ GitHub 🧠 Login │
134137
│ │
135138
│ ✅ Setup complete! │
136139
│ │
@@ -202,7 +205,8 @@ Bubble Tea handles all rendering automatically:
202205
Console at the beginning of the `pull` command - all items selected:
203206

204207
```
205-
╭─ GitHub 🧠 pull ─────────────────────────────────────────────╮
208+
╭────────────────────────────────────────────────────────────────╮
209+
│ GitHub 🧠 pull │
206210
│ │
207211
│ 📋 Repositories │
208212
│ 📋 Discussions │
@@ -225,7 +229,8 @@ Console at the beginning of the `pull` command - all items selected:
225229
Console at the beginning of the `pull` command - `-i repositories`:
226230

227231
```
228-
╭─ GitHub 🧠 pull ─────────────────────────────────────────────╮
232+
╭────────────────────────────────────────────────────────────────╮
233+
│ GitHub 🧠 pull │
229234
│ │
230235
│ 📋 Repositories │
231236
│ 🔕 Discussions │
@@ -248,7 +253,8 @@ Console at the beginning of the `pull` command - `-i repositories`:
248253
Console during first item pull:
249254

250255
```
251-
╭─ GitHub 🧠 pull ─────────────────────────────────────────────╮
256+
╭────────────────────────────────────────────────────────────────╮
257+
│ GitHub 🧠 pull │
252258
│ │
253259
│ ⠋ Repositories: 1,247 │
254260
│ 📋 Discussions │
@@ -271,7 +277,8 @@ Console during first item pull:
271277
Console when first item completes:
272278

273279
```
274-
╭─ GitHub 🧠 pull ─────────────────────────────────────────────╮
280+
╭────────────────────────────────────────────────────────────────╮
281+
│ GitHub 🧠 pull │
275282
│ │
276283
│ ✅ Repositories: 2,847 │
277284
│ ⠙ Discussions: 156 │
@@ -294,7 +301,8 @@ Console when first item completes:
294301
Console when an error occurs:
295302

296303
```
297-
╭─ GitHub 🧠 pull ─────────────────────────────────────────────╮
304+
╭────────────────────────────────────────────────────────────────╮
305+
│ GitHub 🧠 pull │
298306
│ │
299307
│ ✅ Repositories: 2,847 │
300308
│ ❌ Discussions: 156 (errors) │
@@ -344,8 +352,9 @@ Console when an error occurs:
344352

345353
**Box Drawing:**
346354

347-
- Use lipgloss to build bordered layouts with `lipgloss.JoinVertical`
348-
- Rounded borders (╭╮╰╯) styled with adaptive colors
355+
- Use standard lipgloss borders - no custom border painting or string manipulation
356+
- Rounded borders (╭╮╰╯) styled with `lipgloss.RoundedBorder()`
357+
- Title rendered as bold text inside the box, not embedded in border
349358
- Border colors animated via `tickMsg` sent every second
350359
- Responsive width: `max(64, terminalWidth - 4)`
351360

0 commit comments

Comments
 (0)