Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
6b45b1d6
Unverified
Commit
6b45b1d6
authored
Mar 12, 2025
by
Shane-XB-Qian
Committed by
GitHub
Mar 12, 2025
Browse files
cli: adding support ctrl-n/p like general cli (#9136)
Signed-off-by:
shane.xb.qian
<
shane.qian@foxmail.com
>
parent
b3af953a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
12 deletions
+24
-12
readline/readline.go
readline/readline.go
+24
-12
No files found.
readline/readline.go
View file @
6b45b1d6
...
@@ -116,19 +116,9 @@ func (i *Instance) Readline() (string, error) {
...
@@ -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
,
&
currentLineBuf
)
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
,
&
currentLineBuf
)
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) {
...
@@ -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
,
&
currentLineBuf
)
case
CharNext
:
i
.
historyNext
(
buf
,
&
currentLineBuf
)
case
CharLineStart
:
case
CharLineStart
:
buf
.
MoveToStart
()
buf
.
MoveToStart
()
case
CharLineEnd
:
case
CharLineEnd
:
...
@@ -246,6 +240,24 @@ func (i *Instance) HistoryDisable() {
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment