Skip to content

Commit

Permalink
resolve comment
Browse files Browse the repository at this point in the history
Signed-off-by: Billy Zha <[email protected]>
  • Loading branch information
qweeah committed Sep 22, 2023
1 parent 00ca2fc commit c85e809
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
3 changes: 2 additions & 1 deletion cmd/oras/internal/display/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ func (c *Console) NewRow() {
func (c *Console) OutputTo(upCnt uint, str string) {
fmt.Fprint(c, "\0338")
fmt.Fprint(c, aec.PreviousLine(upCnt))
fmt.Fprint(c, str+" ")
fmt.Fprint(c, str)
fmt.Fprint(c, " ")
fmt.Fprint(c, aec.EraseLine(aec.EraseModes.Tail))
}

Expand Down
22 changes: 11 additions & 11 deletions cmd/oras/internal/display/progress/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"oras.land/oras/cmd/oras/internal/display/console"
)

const BUFFER_SIZE = 20
const BufferSize = 20

// Status is print message channel
type Status chan<- *status
Expand All @@ -42,7 +42,7 @@ type manager struct {
statuses []*status
rwLock sync.RWMutex
renderTick *time.Ticker
c *console.Console
console *console.Console
updating sync.WaitGroup
mu sync.Mutex
close sync.Once
Expand All @@ -57,7 +57,7 @@ func NewManager(f *os.File) (Manager, error) {
var m manager
var err error

m.c, err = console.New(f)
m.console, err = console.New(f)
if err != nil {
return nil, err
}
Expand All @@ -70,7 +70,7 @@ func NewManager(f *os.File) (Manager, error) {

func (m *manager) start() {
m.renderTick.Reset(bufFlushDuration)
m.c.Save()
m.console.Save()
go func() {
for {
m.render()
Expand All @@ -88,7 +88,7 @@ func (m *manager) render() {
m.mu.Lock()
defer m.mu.Unlock()
// todo: update size in another routine
width, height := m.c.Size()
width, height := m.console.Size()
len := len(m.statuses) * 2
offset := 0
if len > height {
Expand All @@ -100,8 +100,8 @@ func (m *manager) render() {
m.rwLock.RLock()
status, progress := m.statuses[offset/2].String(width)
m.rwLock.RUnlock()
m.c.OutputTo(uint(len-offset), status)
m.c.OutputTo(uint(len-offset-1), progress)
m.console.OutputTo(uint(len-offset), status)
m.console.OutputTo(uint(len-offset-1), progress)
}
}

Expand All @@ -111,13 +111,13 @@ func (m *manager) Add() Status {
defer m.mu.Unlock()
id := len(m.statuses)
m.statuses = append(m.statuses, nil)
defer m.c.NewRow()
defer m.c.NewRow()
defer m.console.NewRow()
defer m.console.NewRow()
return m.newStatus(id)
}

func (m *manager) newStatus(id int) Status {
ch := make(chan *status, BUFFER_SIZE)
ch := make(chan *status, BufferSize)
m.updating.Add(1)
go m.update(ch, id)
return ch
Expand All @@ -139,7 +139,7 @@ func (m *manager) StopAndWait() {
close(m.done)
defer m.close.Do(func() {
// 4. restore cursor, mark done
m.c.Restore()
m.console.Restore()
})
// 2. wait for all model update done
m.updating.Wait()
Expand Down
2 changes: 1 addition & 1 deletion cmd/oras/internal/display/track/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (r *reader) Read(p []byte) (int, error) {

if r.mu.TryLock() {
defer r.mu.Unlock()
if len(r.ch) < progress.BUFFER_SIZE {
if len(r.ch) < progress.BufferSize {
// intermediate progress might be ignored if buffer is full
r.ch <- progress.NewStatus(r.actionPrompt, r.descriptor, offset)
}
Expand Down

0 comments on commit c85e809

Please sign in to comment.