Skip to content

Commit

Permalink
Merge branch 'main' into get-successors
Browse files Browse the repository at this point in the history
  • Loading branch information
Terry Howe authored Jul 19, 2024
2 parents 31a1862 + cdb60fc commit d36a282
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 10 deletions.
6 changes: 3 additions & 3 deletions cmd/oras/internal/display/status/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ const (
MinWidth = 80
// MinHeight is the minimal height of supported console.
MinHeight = 10
// cannot use aec.Save since DEC has better compatilibity than SCO
// Save cannot use aec.Save since DEC has better compatibility than SCO
Save = "\0337"
// cannot use aec.Restore since DEC has better compatilibity than SCO
// Restore cannot use aec.Restore since DEC has better compatibility than SCO
Restore = "\0338"
)

Expand Down Expand Up @@ -87,7 +87,7 @@ func (c *Console) OutputTo(upCnt uint, str string) {

// Restore restores the saved cursor position.
func (c *Console) Restore() {
// cannot use aec.Restore since DEC has better compatilibity than SCO
// cannot use aec.Restore since DEC has better compatibility than SCO
_, _ = c.Write([]byte(Restore))
_, _ = c.Write([]byte(aec.Column(0).
With(aec.EraseLine(aec.EraseModes.All)).
Expand Down
12 changes: 6 additions & 6 deletions cmd/oras/internal/display/status/progress/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,17 @@ func (m *manager) render() {
defer m.statusLock.RUnlock()
// todo: update size in another routine
width, height := m.console.Size()
len := len(m.status) * 2
lineCount := len(m.status) * 2
offset := 0
if len > height {
if lineCount > height {
// skip statuses that cannot be rendered
offset = len - height
offset = lineCount - height
}

for ; offset < len; offset += 2 {
for ; offset < lineCount; offset += 2 {
status, progress := m.status[offset/2].String(width)
m.console.OutputTo(uint(len-offset), status)
m.console.OutputTo(uint(len-offset-1), progress)
m.console.OutputTo(uint(lineCount-offset), status)
m.console.OutputTo(uint(lineCount-offset-1), progress)
}
}

Expand Down
52 changes: 52 additions & 0 deletions cmd/oras/internal/display/status/progress/manager_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//go:build freebsd || linux || netbsd || openbsd || solaris

/*
Copyright The ORAS Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package progress

import (
"fmt"
"testing"

"oras.land/oras/cmd/oras/internal/display/status/console"
"oras.land/oras/cmd/oras/internal/display/status/console/testutils"
)

func Test_manager_render(t *testing.T) {
pty, device, err := testutils.NewPty()
if err != nil {
t.Fatal(err)
}
defer device.Close()
m := &manager{
console: &console.Console{Console: pty},
}
_, height := m.console.Size()
for i := 0; i < height; i++ {
if _, err := m.Add(); err != nil {
t.Fatal(err)
}
}
m.render()
// validate
var want []string
for i := height; i > 0; i -= 2 {
want = append(want, fmt.Sprintf("%dF%s", i, zeroStatus))
}
if err = testutils.MatchPty(pty, device, want...); err != nil {
t.Fatal(err)
}
}
2 changes: 1 addition & 1 deletion cmd/oras/internal/display/status/progress/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func Test_status_String(t *testing.T) {
}
}

func Test_status_String_zeroWitdth(t *testing.T) {
func Test_status_String_zeroWidth(t *testing.T) {
// zero status and progress
s := newStatus()
if status, digest := s.String(console.MinWidth); status != zeroStatus || digest != zeroDigest {
Expand Down

0 comments on commit d36a282

Please sign in to comment.