mirror of
https://github.com/mrusme/neonmodem.git
synced 2024-12-04 14:46:37 -05:00
Implemented UI caching trickery, fixed shortcuts
This commit is contained in:
parent
3daf2abf01
commit
8e9102e951
28
ui/ui.go
28
ui/ui.go
@ -22,18 +22,18 @@ type KeyMap struct {
|
||||
}
|
||||
|
||||
var DefaultKeyMap = KeyMap{
|
||||
Up: key.NewBinding(
|
||||
key.WithKeys("k", "up"),
|
||||
key.WithHelp("↑/k", "move up"),
|
||||
),
|
||||
Down: key.NewBinding(
|
||||
key.WithKeys("j", "down"),
|
||||
key.WithHelp("↓/j", "move down"),
|
||||
),
|
||||
Quit: key.NewBinding(
|
||||
key.WithKeys("q", "ctrl+q", "escape"),
|
||||
key.WithHelp("q/esc", "quit"),
|
||||
),
|
||||
// Up: key.NewBinding(
|
||||
// key.WithKeys("k", "up"),
|
||||
// key.WithHelp("↑/k", "move up"),
|
||||
// ),
|
||||
// Down: key.NewBinding(
|
||||
// key.WithKeys("j", "down"),
|
||||
// key.WithHelp("↓/j", "move down"),
|
||||
// ),
|
||||
// Quit: key.NewBinding(
|
||||
// key.WithKeys("q", "ctrl+q", "escape"),
|
||||
// key.WithHelp("q/esc", "quit"),
|
||||
// ),
|
||||
}
|
||||
|
||||
type Model struct {
|
||||
@ -67,8 +67,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
case tea.KeyMsg:
|
||||
switch {
|
||||
case key.Matches(msg, m.keymap.Quit):
|
||||
return m, tea.Quit
|
||||
// case key.Matches(msg, m.keymap.Quit):
|
||||
// return m, tea.Quit
|
||||
}
|
||||
|
||||
case tea.WindowSizeMsg:
|
||||
|
@ -31,7 +31,8 @@ var (
|
||||
type KeyMap struct {
|
||||
Refresh key.Binding
|
||||
Select key.Binding
|
||||
Close key.Binding
|
||||
Esc key.Binding
|
||||
Quit key.Binding
|
||||
}
|
||||
|
||||
var DefaultKeyMap = KeyMap{
|
||||
@ -43,10 +44,13 @@ var DefaultKeyMap = KeyMap{
|
||||
key.WithKeys("r", "enter"),
|
||||
key.WithHelp("r/enter", "read"),
|
||||
),
|
||||
Close: key.NewBinding(
|
||||
key.WithKeys("esc", "q"),
|
||||
Esc: key.NewBinding(
|
||||
key.WithKeys("esc"),
|
||||
key.WithHelp("esc", "close"),
|
||||
),
|
||||
Quit: key.NewBinding(
|
||||
key.WithKeys("q"),
|
||||
),
|
||||
}
|
||||
|
||||
type Model struct {
|
||||
@ -60,10 +64,11 @@ type Model struct {
|
||||
|
||||
glam *glamour.TermRenderer
|
||||
|
||||
focused string
|
||||
buffer string
|
||||
replyIDs []string
|
||||
viewcache string
|
||||
focused string
|
||||
buffer string
|
||||
replyIDs []string
|
||||
viewcache string
|
||||
viewcacheTextareaXY []int
|
||||
}
|
||||
|
||||
func (m Model) Init() tea.Cmd {
|
||||
@ -74,10 +79,12 @@ func (m Model) Init() tea.Cmd {
|
||||
|
||||
func NewModel(c *ctx.Ctx) Model {
|
||||
m := Model{
|
||||
ctx: c,
|
||||
keymap: DefaultKeyMap,
|
||||
focused: "list",
|
||||
buffer: "",
|
||||
ctx: c,
|
||||
keymap: DefaultKeyMap,
|
||||
focused: "list",
|
||||
buffer: "",
|
||||
viewcache: "",
|
||||
viewcacheTextareaXY: []int{0, 0, 0, 0},
|
||||
}
|
||||
|
||||
listDelegate := list.NewDefaultDelegate()
|
||||
@ -122,10 +129,13 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
} else if m.focused == "post" {
|
||||
m.focused = "reply"
|
||||
|
||||
m.viewcache = m.View()
|
||||
|
||||
return m, m.textarea.Focus()
|
||||
}
|
||||
|
||||
case key.Matches(msg, m.keymap.Close):
|
||||
case key.Matches(msg, m.keymap.Esc), key.Matches(msg, m.keymap.Quit):
|
||||
if m.focused == "list" {
|
||||
return m, tea.Quit
|
||||
} else if m.focused == "post" {
|
||||
@ -133,7 +143,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.textarea.Reset()
|
||||
m.focused = "list"
|
||||
return m, nil
|
||||
} else if m.focused == "reply" {
|
||||
} else if m.focused == "reply" && key.Matches(msg, m.keymap.Esc) {
|
||||
m.focused = "post"
|
||||
m.buffer = ""
|
||||
return m, nil
|
||||
@ -209,7 +219,12 @@ func (m Model) View() string {
|
||||
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("Cached View()")
|
||||
|
||||
m.textarea.SetWidth(m.viewcacheTextareaXY[2])
|
||||
m.textarea.SetHeight(m.viewcacheTextareaXY[3])
|
||||
|
||||
return helpers.PlaceOverlay(m.viewcacheTextareaXY[0], m.viewcacheTextareaXY[1], m.textarea.View(), m.viewcache, false)
|
||||
}
|
||||
|
||||
m.ctx.Logger.Debugln("View()")
|
||||
@ -289,6 +304,11 @@ func (m Model) View() string {
|
||||
m.ctx.Theme.DialogBox.Window.Focused.Render(replyWindow),
|
||||
view.String(), true)
|
||||
|
||||
m.viewcacheTextareaXY[0] = 6
|
||||
m.viewcacheTextareaXY[1] = m.ctx.Screen[1] - 19
|
||||
m.viewcacheTextareaXY[2] = m.viewport.Width - 2
|
||||
m.viewcacheTextareaXY[3] = 6
|
||||
|
||||
view = strings.Builder{}
|
||||
view.WriteString(tmp)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user