Skip to content

Commit fda1f8e

Browse files
authored
Merge pull request #103 from balajz/double-key-press-user-notify
Double key press user notify
2 parents c40b1ae + 16690c1 commit fda1f8e

3 files changed

Lines changed: 27 additions & 6 deletions

File tree

internal/app/ui/components/status.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,17 @@ import (
77
"charm.land/lipgloss/v2"
88
)
99

10-
// StatusModel manages the status bar and the executing spinner.
10+
// MessageUpdateMsg is used to update the message in the status bar
11+
type MessageUpdateMsg struct {
12+
Message string
13+
}
14+
15+
// MessageResetMsg is used to reset the message in the status bar
16+
type MessageResetMsg struct{}
17+
18+
// StatusModel manages the status bar and the executing spinner
1119
type StatusModel struct {
20+
Message string
1221
Version string
1322
Width int
1423
IssueLink string
@@ -32,6 +41,10 @@ func (m StatusModel) Update(msg tea.Msg) (StatusModel, tea.Cmd) {
3241
switch msg := msg.(type) {
3342
case tea.WindowSizeMsg:
3443
m.Width = msg.Width
44+
case MessageUpdateMsg:
45+
m.Message = msg.Message
46+
case MessageResetMsg:
47+
m.Message = ""
3548
}
3649
return m, cmd
3750
}
@@ -63,7 +76,14 @@ func (m StatusModel) View() string {
6376
}
6477
padding := strings.Repeat(" ", paddingWidth)
6578

66-
statusBar := m.StatusBarStyle.Width(m.Width).Render(name + padding + link)
79+
firstLine := m.StatusBarStyle.Faint(true).Render(m.Message)
80+
secondLine := m.StatusBarStyle.Render(lipgloss.Sprintf("%s%s%s", name, padding, link))
81+
82+
statusBar := lipgloss.JoinVertical(
83+
lipgloss.Top,
84+
firstLine,
85+
secondLine,
86+
)
6787

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

80-
// Top separator + Bottom separator + Status bar
81-
return lipgloss.Height(separator)*2 + lipgloss.Height(statusBar)
99+
// Top separator + Bottom separator + message line + version line
100+
return lipgloss.Height(separator)*2 + 2
82101
}

internal/app/ui/model.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
182182

183183
case seqTimeoutMsg:
184184
if msg.seq == m.pendingSeq {
185+
m.statusModel, _ = m.statusModel.Update(components.MessageResetMsg{}) // reset status message
185186
m.state = StateInput
186187
}
187188
return m, nil
@@ -218,6 +219,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
218219
m.state = StatePendingQuit
219220
m.pendingSeq++
220221
n := m.pendingSeq
222+
m.statusModel, _ = m.statusModel.Update(components.MessageUpdateMsg{Message: "Press Ctrl+C again to quit"})
221223
return m, tea.Tick(500*time.Millisecond, func(t time.Time) tea.Msg {
222224
return seqTimeoutMsg{seq: n}
223225
})
@@ -234,6 +236,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
234236
m.state = StatePendingClear
235237
m.pendingSeq++
236238
n := m.pendingSeq
239+
m.statusModel, _ = m.statusModel.Update(components.MessageUpdateMsg{Message: "Press ESC again to clear"})
237240
return m, tea.Tick(500*time.Millisecond, func(t time.Time) tea.Msg {
238241
return seqTimeoutMsg{seq: n}
239242
})

internal/app/ui/styles.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ func DefaultStyles() Styles {
4949
Faint(true),
5050
StatusBar: lipgloss.NewStyle().
5151
Foreground(lipgloss.Color("#C4B5FD")).
52-
Background(lipgloss.Color("#2A273F")).
5352
Padding(0, 1),
5453
ClampNotice: lipgloss.NewStyle().
5554
Foreground(lipgloss.Color("#A78BFA")).

0 commit comments

Comments
 (0)