[WIP] Layout
This commit is contained in:
@ -23,15 +23,6 @@ func NewContextPickerPage(common *common.Common) *ContextPickerPage {
|
||||
contexts: common.TW.GetContexts(),
|
||||
}
|
||||
|
||||
// if allowAdd {
|
||||
// fields = append(fields, huh.NewInput().
|
||||
// Key("input").
|
||||
// Title("Input").
|
||||
// Prompt(fmt.Sprintf("Enter a new %s", header)).
|
||||
// Inline(false),
|
||||
// )
|
||||
// }
|
||||
|
||||
selected := common.TW.GetActiveContext().Name
|
||||
options := make([]string, 0)
|
||||
for _, c := range p.contexts {
|
||||
@ -59,6 +50,10 @@ func NewContextPickerPage(common *common.Common) *ContextPickerPage {
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *ContextPickerPage) SetSize(width, height int) {
|
||||
p.common.SetSize(width, height)
|
||||
}
|
||||
|
||||
func (p *ContextPickerPage) Init() tea.Cmd {
|
||||
return p.form.Init()
|
||||
}
|
||||
@ -67,10 +62,12 @@ func (p *ContextPickerPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
var cmds []tea.Cmd
|
||||
|
||||
switch msg := msg.(type) {
|
||||
case tea.WindowSizeMsg:
|
||||
p.SetSize(msg.Width, msg.Height)
|
||||
case tea.KeyMsg:
|
||||
switch {
|
||||
case key.Matches(msg, p.common.Keymap.Back):
|
||||
model, err := p.common.PageStack.Pop()
|
||||
model, err := p.common.PopPage()
|
||||
if err != nil {
|
||||
slog.Error("page stack empty")
|
||||
return nil, tea.Quit
|
||||
@ -87,7 +84,7 @@ func (p *ContextPickerPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
|
||||
if p.form.State == huh.StateCompleted {
|
||||
cmds = append(cmds, p.updateContextCmd)
|
||||
model, err := p.common.PageStack.Pop()
|
||||
model, err := p.common.PopPage()
|
||||
if err != nil {
|
||||
slog.Error("page stack empty")
|
||||
return nil, tea.Quit
|
||||
|
||||
Reference in New Issue
Block a user