pterm / pterm

✨ #PTerm is a modern Go module to easily beautify console output. Featuring charts, progressbars, tables, trees, text input, select menus and much more 🚀 It's completely configurable and 100% cross-platform compatible.

Home Page:https://pterm.sh

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Panic at interactive_textinput_printer

malyusha opened this issue · comments

Panic occurs when pterm.DefaultInteractiveTextInput.WithDefaultValue("default").Show() is called and a user presses Left or Right keys to change the default value in-place from a specific position. To understand what I mean, you can run test:

func TestInteractiveTextInputPrinter_Editable(t *testing.T) {
	go func() {
		// change `default` to `deffaultt` by simulating cursor moves `left`, `right` and inserting
		// keys on current cursor positions.
		keyboard.SimulateKeyPress(keys.Left)
		keyboard.SimulateKeyPress(keys.Left)
		keyboard.SimulateKeyPress(keys.Left)
		keyboard.SimulateKeyPress(keys.Left)
		keyboard.SimulateKeyPress(keys.Key{Code: keys.RuneKey, Runes: []rune{'f'}})
		keyboard.SimulateKeyPress(keys.Right)
		keyboard.SimulateKeyPress(keys.Right)
		keyboard.SimulateKeyPress(keys.Right)
		keyboard.SimulateKeyPress(keys.Key{Code: keys.RuneKey, Runes: []rune{'t'}})
		keyboard.SimulateKeyPress(keys.Enter)
	}()

	result, _ := pterm.DefaultInteractiveTextInput.WithDefaultValue("default").Show()
	testza.AssertEqual(t, "deffaultt", result)
}