~adnano/astronaut

5b2ba7d7bffd153f57a7eac22f172a5d4d56c6a9 — Adnan Maolood 1 year, 8 months ago fe7ff9b
ui/view: Remove focus variable
2 files changed, 6 insertions(+), 12 deletions(-)

M browser.go
M ui/input.go
M browser.go => browser.go +3 -2
@@ 170,8 170,6 @@ func (b *Browser) Draw() {
		b.view.Invalidate()
	}

	b.input.Draw()

	switch b.mode {
	case ModeNormal:
		// Draw overlay message


@@ 184,6 182,9 @@ func (b *Browser) Draw() {
			b.statusView.DrawText(0, 0, b.message.text, style)
		}

	case ModeCommand, ModeInput:
		b.input.Draw()

	case ModeFollow:
		// Draw hint labels
		for _, hint := range b.hints {

M ui/input.go => ui/input.go +3 -10
@@ 34,7 34,6 @@ type Input struct {
	view      *View
	prompt    string
	input     []rune
	focus     bool
	sensitive bool
	confirm   bool
	index     int


@@ 48,10 47,6 @@ func (i *Input) SetView(view *View) {

// Draw draws the text input.
func (i *Input) Draw() {
	if !i.focus {
		i.view.HideCursor()
	}

	style := styles.Default
	x := i.view.DrawText(0, 0, i.prompt, style.Bold(true))



@@ 77,16 72,13 @@ func (i *Input) Draw() {

	sindex := i.index - i.scroll
	cells := runewidth.StringWidth(string(i.input[:sindex]))
	if i.focus {
		i.view.ShowCursor(x+cells, 0)
	}
	i.view.ShowCursor(x+cells, 0)
}

// Prompt sets the text input prompt.
func (i *Input) Prompt(prompt string) {
	i.view.Invalidate()
	i.Reset()
	i.focus = true
	i.prompt = prompt
}



@@ 103,7 95,6 @@ func (i *Input) SetInput(input string) {

// Reset resets the text input.
func (i *Input) Reset() {
	i.focus = false
	i.sensitive = false
	i.input = nil
	i.prompt = ""


@@ 140,6 131,7 @@ func (i *Input) Event(event tcell.Event) (string, bool) {
			i.view.Invalidate()
		case tcell.KeyESC:
			i.Reset()
			i.view.HideCursor()
			i.view.Invalidate()
			return "", true
		case tcell.KeyRune:


@@ 148,6 140,7 @@ func (i *Input) Event(event tcell.Event) (string, bool) {
		case tcell.KeyEnter:
			input := string(i.input)
			i.Reset()
			i.view.HideCursor()
			i.view.Invalidate()
			return input, true
		}