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 {
return
}
str := ""
if x.selected {
w.Write([]byte(" [X] " + x.text))
str += " [X] "
} 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 {

View File

@@ -53,6 +53,10 @@ var settingsKey = key.NewBinding(
)
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 {
case authors:
var cmd tea.Cmd

View File

@@ -96,6 +96,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
default:
}
var b tea.BatchMsg
switch m.cursor {
// multiple cursors defined for extensibility, but only graph is used
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.Repos = m.SettingsModel.SelectedRepos
tmp, _ := m.GraphModel.Update(msg)
tmp, c := m.GraphModel.Update(msg)
b = append(b, c)
m.GraphModel, _ = tmp.(Graph)
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)
}
tmpC, cmd := m.CommitLogModel.Update(msg)
b = append(b, cmd)
m.CommitLogModel, _ = tmpC.(CommitLog)
return m, cmd
fallthrough
case settings:
tmp, cmd := m.SettingsModel.Update(msg)
b = append(b, cmd)
m.SettingsModel, _ = tmp.(Settings)
return m, cmd
return m, tea.Batch(b...)
}
return m, nil
}