mirror of
https://github.com/ollama/ollama.git
synced 2025-05-11 10:26:53 +02:00
cli: adding support ctrl-n/p like general cli (#9136)
Signed-off-by: shane.xb.qian <shane.qian@foxmail.com>
This commit is contained in:
parent
b3af953a55
commit
6b45b1d6b4
1 changed files with 24 additions and 12 deletions
|
@ -116,19 +116,9 @@ func (i *Instance) Readline() (string, error) {
|
||||||
|
|
||||||
switch r {
|
switch r {
|
||||||
case KeyUp:
|
case KeyUp:
|
||||||
if i.History.Pos > 0 {
|
i.historyPrev(buf, ¤tLineBuf)
|
||||||
if i.History.Pos == i.History.Size() {
|
|
||||||
currentLineBuf = []rune(buf.String())
|
|
||||||
}
|
|
||||||
buf.Replace([]rune(i.History.Prev()))
|
|
||||||
}
|
|
||||||
case KeyDown:
|
case KeyDown:
|
||||||
if i.History.Pos < i.History.Size() {
|
i.historyNext(buf, ¤tLineBuf)
|
||||||
buf.Replace([]rune(i.History.Next()))
|
|
||||||
if i.History.Pos == i.History.Size() {
|
|
||||||
buf.Replace(currentLineBuf)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case KeyLeft:
|
case KeyLeft:
|
||||||
buf.MoveLeft()
|
buf.MoveLeft()
|
||||||
case KeyRight:
|
case KeyRight:
|
||||||
|
@ -185,6 +175,10 @@ func (i *Instance) Readline() (string, error) {
|
||||||
esc = true
|
esc = true
|
||||||
case CharInterrupt:
|
case CharInterrupt:
|
||||||
return "", ErrInterrupt
|
return "", ErrInterrupt
|
||||||
|
case CharPrev:
|
||||||
|
i.historyPrev(buf, ¤tLineBuf)
|
||||||
|
case CharNext:
|
||||||
|
i.historyNext(buf, ¤tLineBuf)
|
||||||
case CharLineStart:
|
case CharLineStart:
|
||||||
buf.MoveToStart()
|
buf.MoveToStart()
|
||||||
case CharLineEnd:
|
case CharLineEnd:
|
||||||
|
@ -246,6 +240,24 @@ func (i *Instance) HistoryDisable() {
|
||||||
i.History.Enabled = false
|
i.History.Enabled = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *Instance) historyPrev(buf *Buffer, currentLineBuf *[]rune) {
|
||||||
|
if i.History.Pos > 0 {
|
||||||
|
if i.History.Pos == i.History.Size() {
|
||||||
|
*currentLineBuf = []rune(buf.String())
|
||||||
|
}
|
||||||
|
buf.Replace([]rune(i.History.Prev()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *Instance) historyNext(buf *Buffer, currentLineBuf *[]rune) {
|
||||||
|
if i.History.Pos < i.History.Size() {
|
||||||
|
buf.Replace([]rune(i.History.Next()))
|
||||||
|
if i.History.Pos == i.History.Size() {
|
||||||
|
buf.Replace(*currentLineBuf)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func NewTerminal() (*Terminal, error) {
|
func NewTerminal() (*Terminal, error) {
|
||||||
fd := os.Stdin.Fd()
|
fd := os.Stdin.Fd()
|
||||||
termios, err := SetRawMode(fd)
|
termios, err := SetRawMode(fd)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue