main 6af0a61

summary_view.go RawHistoryFolder

1package views
2
3import (
4	"fmt"
5	"strings"
6	"time"
7
8	"github.com/bnema/archup/internal/interfaces/tui/models"
9	"github.com/charmbracelet/lipgloss"
10)
11
12// RenderSummary renders the installation summary (success case)
13func RenderSummary(im *models.InstallationModelImpl) string {
14	if err := im.GetError(); err != "" {
15		return RenderError(err)
16	}
17
18	_ = im.IsComplete() // keep for potential future use
19
20	var b strings.Builder
21
22	b.WriteString("\n")
23	b.WriteString(lipgloss.NewStyle().
24		Bold(true).
25		Foreground(lipgloss.Color("10")).
26		Render("Installation Complete!"))
27	b.WriteString("\n\n")
28
29	status := im.GetStatus()
30
31	// System information
32	if status.Hostname != "" {
33		b.WriteString("Hostname: ")
34		b.WriteString(lipgloss.NewStyle().
35			Foreground(lipgloss.Color("11")).
36			Render(status.Hostname))
37		b.WriteString("\n")
38	}
39
40	if status.Username != "" {
41		b.WriteString("User: ")
42		b.WriteString(lipgloss.NewStyle().
43			Foreground(lipgloss.Color("11")).
44			Render(status.Username))
45		b.WriteString("\n")
46	}
47
48	if status.TargetDisk != "" {
49		b.WriteString("Target Disk: ")
50		b.WriteString(lipgloss.NewStyle().
51			Foreground(lipgloss.Color("11")).
52			Render(status.TargetDisk))
53		b.WriteString("\n")
54	}
55
56	// Duration
57	if status.StartedAt != nil && status.CompletedAt != nil {
58		duration := status.CompletedAt.Sub(*status.StartedAt)
59		b.WriteString(fmt.Sprintf("Duration: %s\n", formatDuration(duration)))
60	}
61
62	b.WriteString("\n")
63	b.WriteString(lipgloss.NewStyle().
64		Bold(true).
65		Foreground(lipgloss.Color("14")).
66		Render("You can now reboot into your new system!"))
67	b.WriteString("\n\n")
68
69	if notice := im.GetNotice(); notice != "" {
70		b.WriteString(lipgloss.NewStyle().
71			Foreground(lipgloss.Color("3")).
72			Render(notice))
73		b.WriteString("\n\n")
74	}
75
76	b.WriteString(lipgloss.NewStyle().
77		Faint(true).
78		Render("Press 'r' to unmount and reboot, or 'q' to exit"))
79
80	return b.String()
81}
82
83// RenderError renders the error screen
84func RenderError(errorMsg string) string {
85	var b strings.Builder
86
87	b.WriteString("\n")
88	b.WriteString(lipgloss.NewStyle().
89		Bold(true).
90		Foreground(lipgloss.Color("1")).
91		Render("Installation Failed"))
92	b.WriteString("\n\n")
93
94	b.WriteString(lipgloss.NewStyle().
95		Foreground(lipgloss.Color("1")).
96		Render(errorMsg))
97	b.WriteString("\n\n")
98
99	b.WriteString(lipgloss.NewStyle().
100		Faint(true).
101		Render("Press 'q' or Ctrl+C to exit"))
102
103	return b.String()
104}
105
106// RenderStatus renders the installation in-progress status
107func RenderStatus(im *models.InstallationModelImpl) string {
108	var b strings.Builder
109
110	b.WriteString("\n")
111	b.WriteString(lipgloss.NewStyle().
112		Bold(true).
113		Foreground(lipgloss.Color("12")).
114		Render("Installation Status"))
115	b.WriteString("\n\n")
116
117	status := im.GetStatus()
118
119	// Current phase
120	if status.CurrentPhase != "" {
121		b.WriteString("Phase: ")
122		b.WriteString(lipgloss.NewStyle().
123			Foreground(lipgloss.Color("11")).
124			Render(status.CurrentPhase))
125		b.WriteString("\n")
126	}
127
128	// Progress
129	if status.Progress > 0 {
130		b.WriteString(fmt.Sprintf("Progress: %d%%\n", status.Progress))
131	}
132
133	// Status
134	if status.State != "" {
135		b.WriteString(fmt.Sprintf("State: %s\n", status.State))
136	}
137
138	b.WriteString("\n")
139	b.WriteString(lipgloss.NewStyle().
140		Faint(true).
141		Render("Installation in progress... Press Ctrl+C to cancel"))
142
143	return b.String()
144}
145
146// formatDuration formats a duration into a human-readable string
147func formatDuration(d time.Duration) string {
148	hours := int(d.Hours())
149	minutes := int(d.Minutes()) % 60
150	seconds := int(d.Seconds()) % 60
151
152	if hours > 0 {
153		return fmt.Sprintf("%dh %dm %ds", hours, minutes, seconds)
154	}
155	if minutes > 0 {
156		return fmt.Sprintf("%dm %ds", minutes, seconds)
157	}
158	return fmt.Sprintf("%ds", seconds)
159}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 0

    ↑↓ moveenter openesc close