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
78f403ff
"src/git@developer.sourcefind.cn:renzhc/diffusers_dcu.git" did not exist on "1051ca81a60073702320b20eb633b178c3dd1c9b"
Unverified
Commit
78f403ff
authored
Feb 18, 2025
by
Jeremy Schlatter
Browse files
address code review comments
parent
f9c7ead1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
17 deletions
+17
-17
progress/progress.go
progress/progress.go
+17
-17
No files found.
progress/progress.go
View file @
78f403ff
package
progress
package
progress
import
(
import
(
"b
ytes
"
"b
ufio
"
"fmt"
"fmt"
"io"
"io"
"sync"
"sync"
...
@@ -13,9 +13,9 @@ type State interface {
...
@@ -13,9 +13,9 @@ type State interface {
}
}
type
Progress
struct
{
type
Progress
struct
{
mu
sync
.
Mutex
mu
sync
.
Mutex
w
io
.
Writer
// buffer output to minimize flickering on all terminals
buf
bytes
.
Buff
er
w
*
bufio
.
Writ
er
pos
int
pos
int
...
@@ -24,7 +24,7 @@ type Progress struct {
...
@@ -24,7 +24,7 @@ type Progress struct {
}
}
func
NewProgress
(
w
io
.
Writer
)
*
Progress
{
func
NewProgress
(
w
io
.
Writer
)
*
Progress
{
p
:=
&
Progress
{
w
:
w
}
p
:=
&
Progress
{
w
:
bufio
.
NewWriter
(
w
)
}
go
p
.
start
()
go
p
.
start
()
return
p
return
p
}
}
...
@@ -50,11 +50,14 @@ func (p *Progress) Stop() bool {
...
@@ -50,11 +50,14 @@ func (p *Progress) Stop() bool {
stopped
:=
p
.
stop
()
stopped
:=
p
.
stop
()
if
stopped
{
if
stopped
{
fmt
.
Fprint
(
p
.
w
,
"
\n
"
)
fmt
.
Fprint
(
p
.
w
,
"
\n
"
)
p
.
w
.
Flush
()
}
}
return
stopped
return
stopped
}
}
func
(
p
*
Progress
)
StopAndClear
()
bool
{
func
(
p
*
Progress
)
StopAndClear
()
bool
{
defer
p
.
w
.
Flush
()
fmt
.
Fprint
(
p
.
w
,
"
\0
33[?25l"
)
fmt
.
Fprint
(
p
.
w
,
"
\0
33[?25l"
)
defer
fmt
.
Fprint
(
p
.
w
,
"
\0
33[?25h"
)
defer
fmt
.
Fprint
(
p
.
w
,
"
\0
33[?25h"
)
...
@@ -83,29 +86,26 @@ func (p *Progress) render() {
...
@@ -83,29 +86,26 @@ func (p *Progress) render() {
p
.
mu
.
Lock
()
p
.
mu
.
Lock
()
defer
p
.
mu
.
Unlock
()
defer
p
.
mu
.
Unlock
()
// buffer output to minimize flickering on all terminals
defer
p
.
w
.
Flush
()
p
.
buf
.
Reset
()
defer
p
.
buf
.
WriteTo
(
p
.
w
)
// eliminate flickering on terminals that support synchronized output
// eliminate flickering on terminals that support synchronized output
fmt
.
Fprint
(
&
p
.
buf
,
"
\0
33[?2026h"
)
fmt
.
Fprint
(
p
.
w
,
"
\0
33[?2026h"
)
defer
fmt
.
Fprint
(
&
p
.
buf
,
"
\0
33[?2026l"
)
defer
fmt
.
Fprint
(
p
.
w
,
"
\0
33[?2026l"
)
fmt
.
Fprint
(
&
p
.
buf
,
"
\0
33[?25l"
)
fmt
.
Fprint
(
p
.
w
,
"
\0
33[?25l"
)
defer
fmt
.
Fprint
(
&
p
.
buf
,
"
\0
33[?25h"
)
defer
fmt
.
Fprint
(
p
.
w
,
"
\0
33[?25h"
)
// move the cursor back to the beginning
// move the cursor back to the beginning
for
range
p
.
pos
-
1
{
for
range
p
.
pos
-
1
{
fmt
.
Fprint
(
&
p
.
buf
,
"
\0
33[A"
)
fmt
.
Fprint
(
p
.
w
,
"
\0
33[A"
)
}
}
fmt
.
Fprint
(
&
p
.
buf
,
"
\0
33[1G"
)
fmt
.
Fprint
(
p
.
w
,
"
\0
33[1G"
)
// render progress lines
// render progress lines
for
i
,
state
:=
range
p
.
states
{
for
i
,
state
:=
range
p
.
states
{
fmt
.
Fprint
(
&
p
.
buf
,
state
.
String
())
fmt
.
Fprint
(
p
.
w
,
state
.
String
(),
"
\0
33[K"
)
fmt
.
Fprintf
(
&
p
.
buf
,
"
\0
33[K"
)
if
i
<
len
(
p
.
states
)
-
1
{
if
i
<
len
(
p
.
states
)
-
1
{
fmt
.
Fprint
(
&
p
.
buf
,
"
\n
"
)
fmt
.
Fprint
(
p
.
w
,
"
\n
"
)
}
}
}
}
...
...
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