make settings list fit screen size, use batch message to ensure all callbacks used

This commit is contained in:
2023-03-01 18:20:56 -08:00
parent fdb5aeae32
commit 1b47179339
3 changed files with 22 additions and 6 deletions

View File

@@ -25,11 +25,18 @@ func (s selectableDelegate) Render(w io.Writer, m list.Model, index int, item li
if !ok { if !ok {
return return
} }
str := ""
if x.selected { if x.selected {
w.Write([]byte(" [X] " + x.text)) str += " [X] "
} else { } else {
w.Write([]byte(" [ ] " + x.text)) str += " [ ] "
} }
str += x.text
if m.Index() == index {
sty := list.NewDefaultItemStyles()
str = sty.SelectedTitle.Render(str)
}
w.Write([]byte(str))
} }
type delegateKeyMap struct { type delegateKeyMap struct {

View File

@@ -53,6 +53,10 @@ var settingsKey = key.NewBinding(
) )
func (m Settings) Update(msg tea.Msg) (tea.Model, tea.Cmd) { func (m Settings) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if msg, ok := msg.(tea.WindowSizeMsg); ok {
m.AuthorList.SetHeight(msg.Height - 8)
m.RepoList.SetHeight(msg.Height - 8)
}
switch m.cursor { switch m.cursor {
case authors: case authors:
var cmd tea.Cmd var cmd tea.Cmd

View File

@@ -96,6 +96,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
default: default:
} }
var b tea.BatchMsg
switch m.cursor { switch m.cursor {
// multiple cursors defined for extensibility, but only graph is used // multiple cursors defined for extensibility, but only graph is used
case graph, commitLog: case graph, commitLog:
@@ -104,8 +105,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.CommitLogModel.Authors = m.SettingsModel.SelectedAuthors m.CommitLogModel.Authors = m.SettingsModel.SelectedAuthors
m.CommitLogModel.Repos = m.SettingsModel.SelectedRepos m.CommitLogModel.Repos = m.SettingsModel.SelectedRepos
tmp, c := m.GraphModel.Update(msg)
tmp, _ := m.GraphModel.Update(msg) b = append(b, c)
m.GraphModel, _ = tmp.(Graph) m.GraphModel, _ = tmp.(Graph)
m.CommitLogModel.Year = m.GraphModel.Year m.CommitLogModel.Year = m.GraphModel.Year
@@ -114,12 +115,16 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.CommitLogModel.Table.SetCursor(0) m.CommitLogModel.Table.SetCursor(0)
} }
tmpC, cmd := m.CommitLogModel.Update(msg) tmpC, cmd := m.CommitLogModel.Update(msg)
b = append(b, cmd)
m.CommitLogModel, _ = tmpC.(CommitLog) m.CommitLogModel, _ = tmpC.(CommitLog)
return m, cmd fallthrough
case settings: case settings:
tmp, cmd := m.SettingsModel.Update(msg) tmp, cmd := m.SettingsModel.Update(msg)
b = append(b, cmd)
m.SettingsModel, _ = tmp.(Settings) m.SettingsModel, _ = tmp.(Settings)
return m, cmd return m, tea.Batch(b...)
} }
return m, nil return m, nil
} }