Skip to content
Merged
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
29 changes: 24 additions & 5 deletions internal/app/ui/components/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@ import (
"charm.land/lipgloss/v2"
)

// StatusModel manages the status bar and the executing spinner.
// MessageUpdateMsg is used to update the message in the status bar
type MessageUpdateMsg struct {
Message string
}

// MessageResetMsg is used to reset the message in the status bar
type MessageResetMsg struct{}

// StatusModel manages the status bar and the executing spinner
type StatusModel struct {
Message string
Version string
Width int
IssueLink string
Expand All @@ -32,6 +41,10 @@ func (m StatusModel) Update(msg tea.Msg) (StatusModel, tea.Cmd) {
switch msg := msg.(type) {
case tea.WindowSizeMsg:
m.Width = msg.Width
case MessageUpdateMsg:
m.Message = msg.Message
case MessageResetMsg:
m.Message = ""
}
return m, cmd
}
Expand Down Expand Up @@ -63,7 +76,14 @@ func (m StatusModel) View() string {
}
padding := strings.Repeat(" ", paddingWidth)

statusBar := m.StatusBarStyle.Width(m.Width).Render(name + padding + link)
firstLine := m.StatusBarStyle.Faint(true).Render(m.Message)
secondLine := m.StatusBarStyle.Render(lipgloss.Sprintf("%s%s%s", name, padding, link))

statusBar := lipgloss.JoinVertical(
lipgloss.Top,
firstLine,
secondLine,
)

return lipgloss.JoinVertical(
lipgloss.Top,
Expand All @@ -75,8 +95,7 @@ func (m StatusModel) View() string {
// StaticHeight returns the height of the footer.
func (m StatusModel) StaticHeight() int {
separator := m.SeparatorStyle.Render(strings.Repeat("─", m.Width))
statusBar := m.StatusBarStyle.Width(m.Width).Render("pgxcli " + m.Version)

// Top separator + Bottom separator + Status bar
return lipgloss.Height(separator)*2 + lipgloss.Height(statusBar)
// Top separator + Bottom separator + message line + version line
return lipgloss.Height(separator)*2 + 2
}
3 changes: 3 additions & 0 deletions internal/app/ui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

case seqTimeoutMsg:
if msg.seq == m.pendingSeq {
m.statusModel, _ = m.statusModel.Update(components.MessageResetMsg{}) // reset status message
m.state = StateInput
}
return m, nil
Expand Down Expand Up @@ -218,6 +219,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.state = StatePendingQuit
m.pendingSeq++
n := m.pendingSeq
m.statusModel, _ = m.statusModel.Update(components.MessageUpdateMsg{Message: "Press Ctrl+C again to quit"})
return m, tea.Tick(500*time.Millisecond, func(t time.Time) tea.Msg {
return seqTimeoutMsg{seq: n}
})
Expand All @@ -234,6 +236,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.state = StatePendingClear
m.pendingSeq++
n := m.pendingSeq
m.statusModel, _ = m.statusModel.Update(components.MessageUpdateMsg{Message: "Press ESC again to clear"})
return m, tea.Tick(500*time.Millisecond, func(t time.Time) tea.Msg {
return seqTimeoutMsg{seq: n}
})
Expand Down
1 change: 0 additions & 1 deletion internal/app/ui/styles.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func DefaultStyles() Styles {
Faint(true),
StatusBar: lipgloss.NewStyle().
Foreground(lipgloss.Color("#C4B5FD")).
Background(lipgloss.Color("#2A273F")).
Padding(0, 1),
ClampNotice: lipgloss.NewStyle().
Foreground(lipgloss.Color("#A78BFA")).
Expand Down
Loading