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
61e65024
Unverified
Commit
61e65024
authored
Jan 08, 2024
by
Michael Yang
Committed by
GitHub
Jan 08, 2024
Browse files
Merge pull request #1818 from jmorganca/mxyng/fix-alt-prompt
fix(cmd): history in alt prompt
parents
08f1e189
2ef9352b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
26 deletions
+28
-26
readline/buffer.go
readline/buffer.go
+10
-20
readline/readline.go
readline/readline.go
+18
-6
No files found.
readline/buffer.go
View file @
61e65024
...
...
@@ -25,10 +25,7 @@ func NewBuffer(prompt *Prompt) (*Buffer, error) {
return
nil
,
err
}
lwidth
:=
width
-
len
(
prompt
.
Prompt
)
if
prompt
.
UseAlt
{
lwidth
=
width
-
len
(
prompt
.
AltPrompt
)
}
lwidth
:=
width
-
len
(
prompt
.
prompt
())
b
:=
&
Buffer
{
Pos
:
0
,
...
...
@@ -78,7 +75,7 @@ func (b *Buffer) MoveRight() {
if
b
.
Pos
<
b
.
Size
()
{
b
.
Pos
+=
1
if
b
.
Pos
%
b
.
LineWidth
==
0
{
fmt
.
Printf
(
CursorDown
+
CursorBOL
+
cursorRightN
(
b
.
Prompt
Size
(
)))
fmt
.
Printf
(
CursorDown
+
CursorBOL
+
cursorRightN
(
len
(
b
.
Prompt
.
prompt
()
)))
}
else
{
fmt
.
Print
(
CursorRight
)
}
...
...
@@ -109,7 +106,7 @@ func (b *Buffer) MoveToStart() {
fmt
.
Print
(
CursorUp
)
}
}
fmt
.
Printf
(
CursorBOL
+
cursorRightN
(
b
.
Prompt
Size
(
)))
fmt
.
Printf
(
CursorBOL
+
cursorRightN
(
len
(
b
.
Prompt
.
prompt
()
)))
b
.
Pos
=
0
}
}
...
...
@@ -123,7 +120,7 @@ func (b *Buffer) MoveToEnd() {
fmt
.
Print
(
CursorDown
)
}
remainder
:=
b
.
Size
()
%
b
.
LineWidth
fmt
.
Printf
(
CursorBOL
+
cursorRightN
(
b
.
Prompt
Size
(
)
+
remainder
))
fmt
.
Printf
(
CursorBOL
+
cursorRightN
(
len
(
b
.
Prompt
.
prompt
()
)
+
remainder
))
}
else
{
fmt
.
Print
(
cursorRightN
(
b
.
Size
()
-
b
.
Pos
))
}
...
...
@@ -143,13 +140,6 @@ func min(n, m int) int {
return
n
}
func
(
b
*
Buffer
)
PromptSize
()
int
{
if
b
.
Prompt
.
UseAlt
{
return
len
(
b
.
Prompt
.
AltPrompt
)
}
return
len
(
b
.
Prompt
.
Prompt
)
}
func
(
b
*
Buffer
)
Add
(
r
rune
)
{
if
b
.
Pos
==
b
.
Buf
.
Size
()
{
fmt
.
Printf
(
"%c"
,
r
)
...
...
@@ -232,7 +222,7 @@ func (b *Buffer) Remove() {
remainingLines
:=
(
b
.
Size
()
-
b
.
Pos
)
/
b
.
LineWidth
fmt
.
Printf
(
cursorDownN
(
remainingLines
+
1
)
+
CursorBOL
+
ClearToEOL
)
place
:=
b
.
Pos
%
b
.
LineWidth
fmt
.
Printf
(
cursorUpN
(
remainingLines
+
1
)
+
cursorRightN
(
place
+
len
(
b
.
Prompt
.
P
rompt
)))
fmt
.
Printf
(
cursorUpN
(
remainingLines
+
1
)
+
cursorRightN
(
place
+
len
(
b
.
Prompt
.
p
rompt
()
)))
}
}
}
...
...
@@ -247,7 +237,7 @@ func (b *Buffer) Delete() {
remainingLines
:=
(
b
.
Size
()
-
b
.
Pos
)
/
b
.
LineWidth
fmt
.
Printf
(
cursorDownN
(
remainingLines
)
+
CursorBOL
+
ClearToEOL
)
place
:=
b
.
Pos
%
b
.
LineWidth
fmt
.
Printf
(
cursorUpN
(
remainingLines
)
+
cursorRightN
(
place
+
len
(
b
.
Prompt
.
P
rompt
)))
fmt
.
Printf
(
cursorUpN
(
remainingLines
)
+
cursorRightN
(
place
+
len
(
b
.
Prompt
.
p
rompt
()
)))
}
}
}
...
...
@@ -294,15 +284,15 @@ func (b *Buffer) DeleteWord() {
}
func
(
b
*
Buffer
)
ClearScreen
()
{
fmt
.
Printf
(
ClearScreen
+
CursorReset
+
b
.
Prompt
.
P
rompt
)
fmt
.
Printf
(
ClearScreen
+
CursorReset
+
b
.
Prompt
.
p
rompt
()
)
if
b
.
IsEmpty
()
{
ph
:=
b
.
Prompt
.
P
laceholder
ph
:=
b
.
Prompt
.
p
laceholder
()
fmt
.
Printf
(
ColorGrey
+
ph
+
cursorLeftN
(
len
(
ph
))
+
ColorDefault
)
}
else
{
currPos
:=
b
.
Pos
b
.
Pos
=
0
b
.
drawRemaining
()
fmt
.
Printf
(
CursorReset
+
cursorRightN
(
len
(
b
.
Prompt
.
P
rompt
)))
fmt
.
Printf
(
CursorReset
+
cursorRightN
(
len
(
b
.
Prompt
.
p
rompt
()
)))
if
currPos
>
0
{
targetLine
:=
currPos
/
b
.
LineWidth
if
targetLine
>
0
{
...
...
@@ -329,7 +319,7 @@ func (b *Buffer) IsEmpty() bool {
func
(
b
*
Buffer
)
Replace
(
r
[]
rune
)
{
b
.
Pos
=
0
b
.
Buf
.
Clear
()
fmt
.
Printf
(
ClearLine
+
CursorBOL
+
b
.
Prompt
.
P
rompt
)
fmt
.
Printf
(
ClearLine
+
CursorBOL
+
b
.
Prompt
.
p
rompt
()
)
for
_
,
c
:=
range
r
{
b
.
Add
(
c
)
}
...
...
readline/readline.go
View file @
61e65024
...
...
@@ -16,6 +16,20 @@ type Prompt struct {
UseAlt
bool
}
func
(
p
*
Prompt
)
prompt
()
string
{
if
p
.
UseAlt
{
return
p
.
AltPrompt
}
return
p
.
Prompt
}
func
(
p
*
Prompt
)
placeholder
()
string
{
if
p
.
UseAlt
{
return
p
.
AltPlaceholder
}
return
p
.
Placeholder
}
type
Terminal
struct
{
outchan
chan
rune
}
...
...
@@ -46,8 +60,9 @@ func New(prompt Prompt) (*Instance, error) {
}
func
(
i
*
Instance
)
Readline
()
(
string
,
error
)
{
prompt
:=
i
.
Prompt
.
Prompt
if
i
.
Prompt
.
UseAlt
||
i
.
Pasting
{
prompt
:=
i
.
Prompt
.
prompt
()
if
i
.
Pasting
{
// force alt prompt when pasting
prompt
=
i
.
Prompt
.
AltPrompt
}
fmt
.
Print
(
prompt
)
...
...
@@ -71,10 +86,7 @@ func (i *Instance) Readline() (string, error) {
// don't show placeholder when pasting unless we're in multiline mode
showPlaceholder
:=
!
i
.
Pasting
||
i
.
Prompt
.
UseAlt
if
buf
.
IsEmpty
()
&&
showPlaceholder
{
ph
:=
i
.
Prompt
.
Placeholder
if
i
.
Prompt
.
UseAlt
{
ph
=
i
.
Prompt
.
AltPlaceholder
}
ph
:=
i
.
Prompt
.
placeholder
()
fmt
.
Printf
(
ColorGrey
+
ph
+
fmt
.
Sprintf
(
CursorLeftN
,
len
(
ph
))
+
ColorDefault
)
}
...
...
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