Skip to content

Move between two columns with lists #314

Answered by CalebJohnHunt
KacperKlys asked this question in Q&A
Discussion options

You must be logged in to vote

Definitely! All you need is for your model to have two different lists as well as a bool to tell you which one it is currently selecting. Then in the Update method, only send certain messages (e.g. keystrokes) to the list which is selected.

Omitting some boiler plate, it would look something like the following:

import (
    "github.com/charmbracelet/bubbles/list"
    tea "github.com/charmbracelet/bubbletea"
)

type model struct {
    leftList list.Model
    rightList list.Model
    is_selecting_left_list bool
}

func (m *model) selectedList() *list.Model {
	if m.is_selecting_left_list{
		return &m.leftList
	}
	return &m.rightList
}

func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@KacperKlys
Comment options

Answer selected by maaslalani
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
documentation Improvements or additions to documentation
2 participants