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
17b1e81c
Commit
17b1e81c
authored
May 15, 2024
by
Josh Yan
Browse files
fixed width and word count for double spacing
parent
f2cf97d6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
6 deletions
+13
-6
cmd/cmd.go
cmd/cmd.go
+13
-6
No files found.
cmd/cmd.go
View file @
17b1e81c
...
@@ -25,7 +25,7 @@ import (
...
@@ -25,7 +25,7 @@ import (
"time"
"time"
"github.com/containerd/console"
"github.com/containerd/console"
"github.com/mattn/go-runewidth"
"github.com/olekukonko/tablewriter"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
"github.com/spf13/cobra"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh"
...
@@ -739,12 +739,13 @@ type displayResponseState struct {
...
@@ -739,12 +739,13 @@ type displayResponseState struct {
wordBuffer
string
wordBuffer
string
}
}
// using runewidth instead of len (cus length is number of bytes, we wnat display length)
func
displayResponse
(
content
string
,
wordWrap
bool
,
state
*
displayResponseState
)
{
func
displayResponse
(
content
string
,
wordWrap
bool
,
state
*
displayResponseState
)
{
termWidth
,
_
,
_
:=
term
.
GetSize
(
int
(
os
.
Stdout
.
Fd
()))
termWidth
,
_
,
_
:=
term
.
GetSize
(
int
(
os
.
Stdout
.
Fd
()))
if
wordWrap
&&
termWidth
>=
10
{
if
wordWrap
&&
termWidth
>=
10
{
for
_
,
ch
:=
range
content
{
for
_
,
ch
:=
range
content
{
if
state
.
lineLength
+
1
>
termWidth
-
5
{
if
state
.
lineLength
+
1
>
termWidth
-
5
{
if
len
(
state
.
wordBuffer
)
>
termWidth
-
10
{
if
runewidth
.
StringWidth
(
state
.
wordBuffer
)
>
termWidth
-
10
{
fmt
.
Printf
(
"%s%c"
,
state
.
wordBuffer
,
ch
)
fmt
.
Printf
(
"%s%c"
,
state
.
wordBuffer
,
ch
)
state
.
wordBuffer
=
""
state
.
wordBuffer
=
""
state
.
lineLength
=
0
state
.
lineLength
=
0
...
@@ -752,12 +753,18 @@ func displayResponse(content string, wordWrap bool, state *displayResponseState)
...
@@ -752,12 +753,18 @@ func displayResponse(content string, wordWrap bool, state *displayResponseState)
}
}
// 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
(
state
.
wordBuffer
))
fmt
.
Printf
(
"
\x1b
[%dD
\x1b
[K
\n
"
,
runewidth
.
StringWidth
(
state
.
wordBuffer
))
fmt
.
Printf
(
"%s%c"
,
state
.
wordBuffer
,
ch
)
fmt
.
Printf
(
"%s%c"
,
state
.
wordBuffer
,
ch
)
state
.
lineLength
=
len
(
state
.
wordBuffer
)
+
1
chWidth
:=
runewidth
.
RuneWidth
(
ch
)
state
.
lineLength
=
runewidth
.
StringWidth
(
state
.
wordBuffer
)
+
chWidth
}
else
{
}
else
{
fmt
.
Print
(
string
(
ch
))
fmt
.
Print
(
string
(
ch
))
state
.
lineLength
+=
1
state
.
lineLength
+=
runewidth
.
RuneWidth
(
ch
)
if
runewidth
.
RuneWidth
(
ch
)
>=
2
{
state
.
wordBuffer
=
""
continue
}
switch
ch
{
switch
ch
{
case
' '
:
case
' '
:
...
...
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