diff --git a/option.go b/option.go index 7e83d6a..f3b9578 100644 --- a/option.go +++ b/option.go @@ -130,13 +130,21 @@ func OptionSelectedDescriptionBGColor(x Color) option { } } -func OptionMaxCompletions(x uint16) option { +func OptionMaxSuggestion(x uint16) option { return func(p *Prompt) error { p.completion.Max = x return nil } } +func OptionHistory(x []string) option { + return func(p *Prompt) error { + p.history.histories = x + p.history.Clear() + return nil + } +} + func New(executor Executor, completer Completer, opts ...option) *Prompt { pt := &Prompt{ in: &VT100Parser{fd: syscall.Stdin}, diff --git a/prompt.go b/prompt.go index 620b3e5..d6b2288 100644 --- a/prompt.go +++ b/prompt.go @@ -197,7 +197,7 @@ func (p *Prompt) tearDown() { func readBuffer(bufCh chan []byte, stopCh chan struct{}) { buf := make([]byte, 1024) - // Set NonBlocking mode because if syscall.Read block this goroutine, it cannot received value from stopCh. + // Set NonBlocking mode because if syscall.Read block this goroutine, it cannot receive data from stopCh. _, _, e := syscall.Syscall(syscall.SYS_FCNTL, uintptr(syscall.Stdin), uintptr(syscall.F_SETFL), uintptr(syscall.O_ASYNC|syscall.O_NONBLOCK)) if e != 0 { diff --git a/vt100_input.go b/vt100_input.go index 17c76e4..9bab566 100644 --- a/vt100_input.go +++ b/vt100_input.go @@ -82,8 +82,8 @@ var asciiSequences []*ASCIICode = []*ASCIICode{ {Key: ControlF, ASCIICode: []byte{0x6}}, {Key: ControlG, ASCIICode: []byte{0x7}}, {Key: ControlH, ASCIICode: []byte{0x8}}, - {Key: ControlI, ASCIICode: []byte{0x9}}, - {Key: ControlJ, ASCIICode: []byte{0xa}}, + //{Key: ControlI, ASCIICode: []byte{0x9}}, + //{Key: ControlJ, ASCIICode: []byte{0xa}}, {Key: ControlK, ASCIICode: []byte{0xb}}, {Key: ControlL, ASCIICode: []byte{0xc}}, {Key: ControlM, ASCIICode: []byte{0xd}}, @@ -116,6 +116,7 @@ var asciiSequences []*ASCIICode = []*ASCIICode{ {Key: End, ASCIICode: []byte{0x1b, 0x5b, 0x70}}, {Key: End, ASCIICode: []byte{0x1b, 0x4f, 0x70}}, + {Key: Enter, ASCIICode: []byte{0xa}}, {Key: Delete, ASCIICode: []byte{0x1b, 0x5b, 0x33, 0x7e}}, {Key: ShiftDelete, ASCIICode: []byte{0x1b, 0x5b, 0x33, 0x3b, 0x02, 0x7e}}, {Key: ControlDelete, ASCIICode: []byte{0x1b, 0x5b, 0x33, 0x3b, 0x05, 0x7e}}, @@ -125,6 +126,7 @@ var asciiSequences []*ASCIICode = []*ASCIICode{ {Key: PageDown, ASCIICode: []byte{0x1b, 0x5b, 0x06, 0x7e}}, {Key: Home, ASCIICode: []byte{0x1b, 0x5b, 0x07, 0x7e}}, {Key: End, ASCIICode: []byte{0x1b, 0x5b, 0x09, 0x7e}}, + {Key: Tab, ASCIICode: []byte{0x9}}, {Key: BackTab, ASCIICode: []byte{0x1b, 0x5b, 0x5a}}, {Key: Insert, ASCIICode: []byte{0x1b, 0x5b, 0x02, 0x7e}},