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
b5614f3e
Unverified
Commit
b5614f3e
authored
Sep 23, 2023
by
Patrick Devine
Committed by
GitHub
Sep 23, 2023
Browse files
fix end-of-line issue with the new prompt (#582)
parent
8b2ba9ca
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
5 deletions
+12
-5
cmd/cmd.go
cmd/cmd.go
+12
-5
No files found.
cmd/cmd.go
View file @
b5614f3e
...
@@ -33,15 +33,22 @@ import (
...
@@ -33,15 +33,22 @@ import (
)
)
type
Painter
struct
{
type
Painter
struct
{
HideH
in
t
bool
IsMultiL
in
e
bool
}
}
func
(
p
Painter
)
Paint
(
line
[]
rune
,
_
int
)
[]
rune
{
func
(
p
Painter
)
Paint
(
line
[]
rune
,
_
int
)
[]
rune
{
termType
:=
os
.
Getenv
(
"TERM"
)
termType
:=
os
.
Getenv
(
"TERM"
)
if
termType
==
"xterm-256color"
&&
len
(
line
)
==
0
&&
!
p
.
HideHint
{
if
termType
==
"xterm-256color"
&&
len
(
line
)
==
0
{
prompt
:=
"Send a message (/? for help)"
var
prompt
string
if
p
.
IsMultiLine
{
prompt
=
"Use
\"\"\"
to end multi-line input"
}
else
{
prompt
=
"Send a message (/? for help)"
}
return
[]
rune
(
fmt
.
Sprintf
(
"
\0
33[38;5;245m%s
\0
33[%dD
\0
33[0m"
,
prompt
,
len
(
prompt
)))
return
[]
rune
(
fmt
.
Sprintf
(
"
\0
33[38;5;245m%s
\0
33[%dD
\0
33[0m"
,
prompt
,
len
(
prompt
)))
}
}
// add a space and a backspace to prevent the cursor from walking up the screen
line
=
append
(
line
,
[]
rune
(
"
\b
"
)
...
)
return
line
return
line
}
}
...
@@ -579,7 +586,7 @@ func generateInteractive(cmd *cobra.Command, model string) error {
...
@@ -579,7 +586,7 @@ func generateInteractive(cmd *cobra.Command, model string) error {
case
isMultiLine
:
case
isMultiLine
:
if
strings
.
HasSuffix
(
line
,
`"""`
)
{
if
strings
.
HasSuffix
(
line
,
`"""`
)
{
isMultiLine
=
false
isMultiLine
=
false
painter
.
HideH
in
t
=
fals
e
painter
.
IsMultiL
in
e
=
isMultiLin
e
multiLineBuffer
+=
strings
.
TrimSuffix
(
line
,
`"""`
)
multiLineBuffer
+=
strings
.
TrimSuffix
(
line
,
`"""`
)
line
=
multiLineBuffer
line
=
multiLineBuffer
multiLineBuffer
=
""
multiLineBuffer
=
""
...
@@ -590,9 +597,9 @@ func generateInteractive(cmd *cobra.Command, model string) error {
...
@@ -590,9 +597,9 @@ func generateInteractive(cmd *cobra.Command, model string) error {
}
}
case
strings
.
HasPrefix
(
line
,
`"""`
)
:
case
strings
.
HasPrefix
(
line
,
`"""`
)
:
isMultiLine
=
true
isMultiLine
=
true
painter
.
IsMultiLine
=
isMultiLine
multiLineBuffer
=
strings
.
TrimPrefix
(
line
,
`"""`
)
+
" "
multiLineBuffer
=
strings
.
TrimPrefix
(
line
,
`"""`
)
+
" "
scanner
.
SetPrompt
(
"... "
)
scanner
.
SetPrompt
(
"... "
)
painter
.
HideHint
=
true
continue
continue
case
strings
.
HasPrefix
(
line
,
"/list"
)
:
case
strings
.
HasPrefix
(
line
,
"/list"
)
:
args
:=
strings
.
Fields
(
line
)
args
:=
strings
.
Fields
(
line
)
...
...
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