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
orangecat
ollama
Commits
a79f030e
"vscode:/vscode.git/clone" did not exist on "c2216b0b2aa9bca185668d2bae419aaa0434379d"
Unverified
Commit
a79f030e
authored
Oct 26, 2023
by
Patrick Devine
Committed by
GitHub
Oct 26, 2023
Browse files
add bracketed paste mode (#922)
parent
9bc5864a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
18 deletions
+36
-18
cmd/cmd.go
cmd/cmd.go
+3
-0
readline/readline.go
readline/readline.go
+23
-16
readline/types.go
readline/types.go
+10
-2
No files found.
cmd/cmd.go
View file @
a79f030e
...
...
@@ -553,6 +553,9 @@ func generateInteractive(cmd *cobra.Command, model string) error {
wordWrap
=
false
}
fmt
.
Print
(
readline
.
StartBracketedPaste
)
defer
fmt
.
Printf
(
readline
.
EndBracketedPaste
)
var
multiLineBuffer
string
for
{
...
...
readline/readline.go
View file @
a79f030e
...
...
@@ -65,8 +65,7 @@ func (i *Instance) Readline() (string, error) {
var
esc
bool
var
escex
bool
var
metaDel
bool
var
bracketedPaste
bool
var
ignoreEnter
bool
var
pasteMode
PasteMode
var
currentLineBuf
[]
rune
...
...
@@ -111,7 +110,16 @@ func (i *Instance) Readline() (string, error) {
case
KeyRight
:
buf
.
MoveRight
()
case
CharBracketedPaste
:
bracketedPaste
=
true
var
code
string
for
cnt
:=
0
;
cnt
<
3
;
cnt
++
{
r
=
i
.
Terminal
.
ReadRune
()
code
+=
string
(
r
)
}
if
code
==
CharBracketedPasteStart
{
pasteMode
=
PasteModeStart
}
else
if
code
==
CharBracketedPasteEnd
{
pasteMode
=
PasteModeEnd
}
case
KeyDel
:
if
buf
.
Size
()
>
0
{
buf
.
Delete
()
...
...
@@ -141,10 +149,6 @@ func (i *Instance) Readline() (string, error) {
}
switch
r
{
case
CharBracketedPasteStart
:
if
bracketedPaste
{
ignoreEnter
=
true
}
case
CharEsc
:
esc
=
true
case
CharInterrupt
:
...
...
@@ -179,16 +183,19 @@ func (i *Instance) Readline() (string, error) {
case
CharCtrlW
:
buf
.
DeleteWord
()
case
CharEnter
:
if
!
ignoreEnter
{
output
:=
buf
.
String
()
if
output
!=
""
{
i
.
History
.
Add
([]
rune
(
output
))
}
buf
.
MoveToEnd
()
fmt
.
Println
()
return
output
,
nil
output
:=
buf
.
String
()
if
output
!=
""
{
i
.
History
.
Add
([]
rune
(
output
))
}
buf
.
MoveToEnd
()
fmt
.
Println
()
switch
pasteMode
{
case
PasteModeStart
:
output
=
`"""`
+
output
case
PasteModeEnd
:
output
=
output
+
`"""`
}
fallthrough
return
output
,
nil
default
:
if
metaDel
{
metaDel
=
false
...
...
readline/types.go
View file @
a79f030e
...
...
@@ -72,6 +72,14 @@ const (
const
(
CharBracketedPaste
=
50
CharBracketedPasteStart
=
0
CharBracketedPasteEnd
=
1
CharBracketedPasteStart
=
"00~"
CharBracketedPasteEnd
=
"01~"
)
type
PasteMode
int
const
(
PastModeOff
=
iota
PasteModeStart
PasteModeEnd
)
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