// OnKey is the event callback when a key has been pressed in the interactive terminal
OnKey is the event callback when a key has been pressed in the interactive terminal
// OnKey is the event callback when a key has been pressed in the interactive terminal
func (p *Prompt) OnKey(key termios.Key) {
	if key == termios.InvalidKey {
		p.redraw()
	} else if key.Type == termios.KeyLetter {
		if p.pos == nil {
			p.line.PushBack(key.Value)
			p.pos = p.line.Back()
		} else {
			p.line.InsertAfter(key.Value, p.pos)
			p.pos = p.pos.Next()
		}
	} else if key.Type == termios.KeySpecial {
		switch key.Value {
		case termios.SpecialBackspace:
			p.doBackspace()
		case termios.SpecialEnter:
			var line string = util.RuneListToString(p.line)
			p.pos = nil
			p.line = list.New()
			p.last = nil
			p.lastY = 0
			p.parent.WriteString("\r\n")
			p.parent.Eval(line)
		case termios.SpecialArrowLeft:
			if p.pos != p.line.Front() {
				p.pos = p.pos.Prev()
			}
		case termios.SpecialArrowRight:
			if p.pos != p.line.Back() {
				p.pos = p.pos.Next()
			}
		}
	}
	p.redraw()
}
func ( p * Prompt ) OnKey ( key termios . Key ) { if key == termios . InvalidKey { p . redraw ( ) } else if key . Type == termios . KeyLetter { if p . pos == nil { p . line . PushBack ( key . Value ) p . pos = p . line . Back ( ) } else { p . line . InsertAfter ( key . Value , p . pos ) p . pos = p . pos . Next ( ) } } else if key . Type == termios . KeySpecial { switch key . Value { case termios . SpecialBackspace : p . doBackspace ( ) case termios . SpecialEnter : var line string = util . RuneListToString ( p . line ) p . pos = nil p . line = list . New ( ) p . last = nil p . lastY = 0 p . parent . WriteString ( " \r \n " ) p . parent . Eval ( line ) case termios . SpecialArrowLeft : if p . pos != p . line . Front ( ) { p . pos = p . pos . Prev ( ) } case termios . SpecialArrowRight : if p . pos != p . line . Back ( ) { p . pos = p . pos . Next ( ) } } } p . redraw ( ) }
OnKey is the event callback when a key has been pressed in the interactive terminal
OnKey is the event callback when a key has been pressed in the interactive terminal