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
2113c9d3
Unverified
Commit
2113c9d3
authored
Dec 04, 2023
by
Patrick Devine
Committed by
GitHub
Dec 04, 2023
Browse files
make linewrap still work when the terminal width has changed (#1350)
parent
1f126afb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
2 deletions
+13
-2
cmd/cmd.go
cmd/cmd.go
+13
-2
No files found.
cmd/cmd.go
View file @
2113c9d3
...
@@ -521,9 +521,17 @@ func generate(cmd *cobra.Command, opts generateOptions) error {
...
@@ -521,9 +521,17 @@ func generate(cmd *cobra.Command, opts generateOptions) error {
latest
=
response
latest
=
response
if
opts
.
WordWrap
{
termWidth
,
_
,
_
=
term
.
GetSize
(
int
(
os
.
Stdout
.
Fd
()))
if
opts
.
WordWrap
&&
termWidth
>=
10
{
for
_
,
ch
:=
range
response
.
Response
{
for
_
,
ch
:=
range
response
.
Response
{
if
currentLineLength
+
1
>
termWidth
-
5
{
if
currentLineLength
+
1
>
termWidth
-
5
{
if
len
(
wordBuffer
)
>
termWidth
-
10
{
fmt
.
Printf
(
"%s%c"
,
wordBuffer
,
ch
)
wordBuffer
=
""
currentLineLength
=
0
continue
}
// backtrack the length of the last word and clear to the end of the line
// backtrack the length of the last word and clear to the end of the line
fmt
.
Printf
(
"
\x1b
[%dD
\x1b
[K
\n
"
,
len
(
wordBuffer
))
fmt
.
Printf
(
"
\x1b
[%dD
\x1b
[K
\n
"
,
len
(
wordBuffer
))
fmt
.
Printf
(
"%s%c"
,
wordBuffer
,
ch
)
fmt
.
Printf
(
"%s%c"
,
wordBuffer
,
ch
)
...
@@ -543,7 +551,10 @@ func generate(cmd *cobra.Command, opts generateOptions) error {
...
@@ -543,7 +551,10 @@ func generate(cmd *cobra.Command, opts generateOptions) error {
}
}
}
}
}
else
{
}
else
{
fmt
.
Print
(
response
.
Response
)
fmt
.
Printf
(
"%s%s"
,
wordBuffer
,
response
.
Response
)
if
len
(
wordBuffer
)
>
0
{
wordBuffer
=
""
}
}
}
return
nil
return
nil
...
...
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