1
0
mirror of https://github.com/mrusme/neonmodem.git synced 2024-11-03 04:27:16 -05:00

Fixed runaway spinner, adjusted shortcuts

This commit is contained in:
マリウス 2023-01-01 20:13:02 -05:00
parent fe97aad5b5
commit 3daf2abf01
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F
3 changed files with 37 additions and 25 deletions

View File

@ -11,9 +11,9 @@ import (
var ( var (
highlight = lipgloss.AdaptiveColor{Light: "#874BFD", Dark: "#7D56F4"} highlight = lipgloss.AdaptiveColor{Light: "#874BFD", Dark: "#7D56F4"}
banner = "▄▗▖▎▄▗▅▖▗▅▅▖▗▅▅▖▅▅▅▖▏▉▅▅┓▅▖▎▗▅▌\n" + banner = "▄▗▖▎▄▗▅▖▗▅▅▖▗▅▅▖▅▅▅▖▏▉▅▅┓▅▖▎▗▅▌\n" +
"▗▎▍▄▗▗▎▏▍▝▝▘▍▝▂▉┈▂▎▍▅▋▊▂╴▏▊▗╴▋▎\n" + "▗▎▍▄▗▗▎▏▍▝▝▘▍▝▂▉┈▂▎▍▅▋▊▂╴▏▊▗╴▋▎\n" +
"▊▉▌╴▘▁▏▏▅▆┈▏▉▇▆▌▗▖▍▎▃▎▎▅▋▋▎▗▎▍▘\n" + "▊▉▌╴▘▁▏▏▅▆┈▏▉▇▆▌▗▖▍▎▃▎▎▅▋▋▎▗▎▍▘\n" +
"▝▄▄▄▘▇▄▆▄▄▄▝▄▄▘▝▘▝▘▏╴▄▘▄▝▘▇╴▄▘▄" "▝▄▄▄▘▇▄▆▄▄▄▝▄▄▘▝▘▝▘▏╴▄▘▄▝▘▇╴▄▘▄"
) )
type Model struct { type Model struct {
@ -42,6 +42,8 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
if m.ctx.Loading == true { if m.ctx.Loading == true {
cmds = append(cmds, m.spinner.Tick) cmds = append(cmds, m.spinner.Tick)
} else {
return m, nil
} }
switch msg := msg.(type) { switch msg := msg.(type) {

View File

@ -31,8 +31,8 @@ var DefaultKeyMap = KeyMap{
key.WithHelp("↓/j", "move down"), key.WithHelp("↓/j", "move down"),
), ),
Quit: key.NewBinding( Quit: key.NewBinding(
key.WithKeys("q", "ctrl+q"), key.WithKeys("q", "ctrl+q", "escape"),
key.WithHelp("q/Q", "quit"), key.WithHelp("q/esc", "quit"),
), ),
} }

View File

@ -36,15 +36,15 @@ type KeyMap struct {
var DefaultKeyMap = KeyMap{ var DefaultKeyMap = KeyMap{
Refresh: key.NewBinding( Refresh: key.NewBinding(
key.WithKeys("r", "R"), key.WithKeys("ctrl+r"),
key.WithHelp("r/R", "refresh"), key.WithHelp("ctrl+r", "refresh"),
), ),
Select: key.NewBinding( Select: key.NewBinding(
key.WithKeys("enter"), key.WithKeys("r", "enter"),
key.WithHelp("enter", "select"), key.WithHelp("r/enter", "read"),
), ),
Close: key.NewBinding( Close: key.NewBinding(
key.WithKeys("esc"), key.WithKeys("esc", "q"),
key.WithHelp("esc", "close"), key.WithHelp("esc", "close"),
), ),
} }
@ -63,6 +63,7 @@ type Model struct {
focused string focused string
buffer string buffer string
replyIDs []string replyIDs []string
viewcache string
} }
func (m Model) Init() tea.Cmd { func (m Model) Init() tea.Cmd {
@ -110,22 +111,24 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if m.focused == "list" { if m.focused == "list" {
m.ctx.Loading = true m.ctx.Loading = true
cmds = append(cmds, m.refresh()) cmds = append(cmds, m.refresh())
}
case key.Matches(msg, m.keymap.Select):
if m.focused == "list" {
i, ok := m.list.SelectedItem().(post.Post)
if ok {
m.ctx.Loading = true
cmds = append(cmds, m.loadItem(&i))
}
} else if m.focused == "post" { } else if m.focused == "post" {
m.focused = "reply" m.focused = "reply"
return m, m.textarea.Focus() return m, m.textarea.Focus()
} }
case key.Matches(msg, m.keymap.Select):
if m.focused == "list" {
m.ctx.Loading = true
i, ok := m.list.SelectedItem().(post.Post)
if ok {
cmds = append(cmds, m.loadItem(&i))
}
}
case key.Matches(msg, m.keymap.Close): case key.Matches(msg, m.keymap.Close):
if m.focused == "post" { if m.focused == "list" {
return m, tea.Quit
} else if m.focused == "post" {
// Let's make sure we reset the texarea // Let's make sure we reset the texarea
m.textarea.Reset() m.textarea.Reset()
m.focused = "list" m.focused = "list"
@ -176,6 +179,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.items = msg m.items = msg
m.list.SetItems(m.items) m.list.SetItems(m.items)
m.ctx.Loading = false m.ctx.Loading = false
return m, nil
case *post.Post: case *post.Post:
m.viewport.SetContent(m.renderViewport(msg)) m.viewport.SetContent(m.renderViewport(msg))
@ -204,6 +208,11 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (m Model) View() string { func (m Model) View() string {
var view strings.Builder = strings.Builder{} var view strings.Builder = strings.Builder{}
if m.focused == "reply" && m.viewcache != "" {
return helpers.PlaceOverlay(3, 2, m.textarea.View(), m.viewcache, false)
}
m.ctx.Logger.Debugln("View()")
var l string = "" var l string = ""
if m.focused == "list" { if m.focused == "list" {
l = m.ctx.Theme.PostsList.List.Focused.Render(m.list.View()) l = m.ctx.Theme.PostsList.List.Focused.Render(m.list.View())
@ -284,7 +293,8 @@ func (m Model) View() string {
view.WriteString(tmp) view.WriteString(tmp)
} }
return view.String() m.viewcache = view.String()
return m.viewcache
} }
func (m *Model) refresh() tea.Cmd { func (m *Model) refresh() tea.Cmd {