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
3cb07d27
Commit
3cb07d27
authored
Nov 17, 2023
by
Michael Yang
Browse files
simplify StopAndClear
parent
97606836
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
14 deletions
+12
-14
progress/progress.go
progress/progress.go
+12
-14
No files found.
progress/progress.go
View file @
3cb07d27
...
@@ -3,12 +3,8 @@ package progress
...
@@ -3,12 +3,8 @@ package progress
import
(
import
(
"fmt"
"fmt"
"io"
"io"
"os"
"strings"
"sync"
"sync"
"time"
"time"
"golang.org/x/term"
)
)
type
State
interface
{
type
State
interface
{
...
@@ -48,19 +44,18 @@ func (p *Progress) Stop() bool {
...
@@ -48,19 +44,18 @@ func (p *Progress) Stop() bool {
}
}
func
(
p
*
Progress
)
StopAndClear
()
bool
{
func
(
p
*
Progress
)
StopAndClear
()
bool
{
fmt
.
Fprint
(
p
.
w
,
"
\0
33[?25l"
)
defer
fmt
.
Fprint
(
p
.
w
,
"
\0
33[?25h"
)
stopped
:=
p
.
Stop
()
stopped
:=
p
.
Stop
()
if
stopped
{
if
stopped
{
termWidth
,
_
,
err
:=
term
.
GetSize
(
int
(
os
.
Stderr
.
Fd
()))
if
err
!=
nil
{
panic
(
err
)
}
// clear the progress bar by:
// clear the progress bar by:
// 1. reset to beginning of line
// 1. for each line in the progress:
// 2. move up to the first line of the progress bar
// a. move the cursor up one line
// 3. fill the terminal width with spaces
// b. clear the line
// 4. reset to beginning of line
for
i
:=
0
;
i
<
p
.
pos
;
i
++
{
fmt
.
Fprintf
(
p
.
w
,
"
\r
\0
33[%dA%s
\r
"
,
p
.
pos
,
strings
.
Repeat
(
" "
,
termWidth
))
fmt
.
Fprint
(
p
.
w
,
"
\0
33[A
\0
33[2K"
)
}
}
}
return
stopped
return
stopped
...
@@ -77,6 +72,9 @@ func (p *Progress) render() error {
...
@@ -77,6 +72,9 @@ func (p *Progress) render() error {
p
.
mu
.
Lock
()
p
.
mu
.
Lock
()
defer
p
.
mu
.
Unlock
()
defer
p
.
mu
.
Unlock
()
fmt
.
Fprint
(
p
.
w
,
"
\0
33[?25l"
)
defer
fmt
.
Fprint
(
p
.
w
,
"
\0
33[?25h"
)
if
p
.
pos
>
0
{
if
p
.
pos
>
0
{
fmt
.
Fprintf
(
p
.
w
,
"
\0
33[%dA"
,
p
.
pos
)
fmt
.
Fprintf
(
p
.
w
,
"
\0
33[%dA"
,
p
.
pos
)
}
}
...
...
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