diff options
Diffstat (limited to 'client/ui.go')
| -rw-r--r-- | client/ui.go | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/client/ui.go b/client/ui.go index 023a1bf..740cc54 100644 --- a/client/ui.go +++ b/client/ui.go @@ -15,11 +15,33 @@ func (a *application) getWin() window.Window { return win } +func (a *application) pushPrompt(p window.Prompt) { + a.prompts = append(a.prompts, p) +} + +func (a *application) removePrompt(p window.Prompt) { + for i := len(a.prompts) - 1; i >= 0; i-- { + if i < len(a.prompts) - 1 { + a.prompts = append(a.prompts[:i], a.prompts[i + 1:]...) + } else { + a.prompts = a.prompts[:i] + } + } +} + +func (a *application) getPrompt() window.Prompt { + if len(a.prompts) > 0 { + return a.prompts[len(a.prompts) - 1] + } + return a.getWin() +} + func (a *application) onInput(ev tui.Event) { tui.Selected = "input" win := a.getWin() - win.Input().Update(ev) + prompt := a.getPrompt() + prompt.Input().Update(ev) buf := win.Buffer() buf.Scroll(-ev.Mouse.Scroll * 2) @@ -30,11 +52,11 @@ func (a *application) onInput(ev tui.Event) { case keys.PageDown: buf.Scroll(-scroll) case keys.Enter: - input := win.Input() + input := prompt.Input() if !input.IsEmpty() { is, text := isCommand(input.Text()) if !is { - win.Send(text) + prompt.Send(text) } else { a.processCommand(text) input.SetText("") @@ -68,15 +90,18 @@ func (a *application) show() { a.cmdWindow.showPreview() } + win := a.getWin() + prompt := a.getPrompt() + a.getWin().Buffer().Show("buffer") tui.Push("input border", tui.Box { Width: tui.Fill, Height: 1, Dir: tui.Left, Style: &tui.Style {Bg: tui.White, Fg: tui.Black}, }) - if a.getWin().Buffer().ScrollPos() > 0 { + if win.Buffer().ScrollPos() > 0 { tui.Push("", tui.Box {Width: tui.TextSize, Height: 1, NoWrap: true}) - if a.getWin().Buffer().AtTop() { + if win.Buffer().AtTop() { tui.Text("[TOP]", nil) } else { tui.Text("[MORE]", nil) @@ -87,7 +112,7 @@ func (a *application) show() { tui.Pop() tui.Push("status", tui.Box {Width: tui.TextSize, Height: 1, NoWrap: true}) - a.getWin().ShowStatusLine() + prompt.ShowStatusLine() tui.Pop() tui.Pop() @@ -96,7 +121,7 @@ func (a *application) show() { Width: tui.Fill, Height: tui.Children, Dir: tui.Right, }) a.showNickBox() - a.getWin().Input().Show("input") + prompt.Input().Show("input") tui.Pop() tui.Pop() |
