Add some refactor changes

This commit is contained in:
c-bata 2017-08-09 12:50:07 +09:00
parent b53127c970
commit 01c461e472
3 changed files with 14 additions and 4 deletions

View File

@ -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},

View File

@ -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 {

View File

@ -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}},