Skip to content

Commit cdb60fc

Browse files
Terry Howeqweeah
andauthored
fix: variable name conflicts with built in function (oras-project#1448)
Signed-off-by: Terry Howe <[email protected]> Signed-off-by: Billy Zha <[email protected]> Co-authored-by: Billy Zha <[email protected]>
1 parent 9e5e766 commit cdb60fc

File tree

4 files changed

+62
-10
lines changed

4 files changed

+62
-10
lines changed

cmd/oras/internal/display/status/console/console.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ const (
2727
MinWidth = 80
2828
// MinHeight is the minimal height of supported console.
2929
MinHeight = 10
30-
// cannot use aec.Save since DEC has better compatilibity than SCO
30+
// Save cannot use aec.Save since DEC has better compatibility than SCO
3131
Save = "\0337"
32-
// cannot use aec.Restore since DEC has better compatilibity than SCO
32+
// Restore cannot use aec.Restore since DEC has better compatibility than SCO
3333
Restore = "\0338"
3434
)
3535

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

8888
// Restore restores the saved cursor position.
8989
func (c *Console) Restore() {
90-
// cannot use aec.Restore since DEC has better compatilibity than SCO
90+
// cannot use aec.Restore since DEC has better compatibility than SCO
9191
_, _ = c.Write([]byte(Restore))
9292
_, _ = c.Write([]byte(aec.Column(0).
9393
With(aec.EraseLine(aec.EraseModes.All)).

cmd/oras/internal/display/status/progress/manager.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,17 @@ func (m *manager) render() {
9292
defer m.statusLock.RUnlock()
9393
// todo: update size in another routine
9494
width, height := m.console.Size()
95-
len := len(m.status) * 2
95+
lineCount := len(m.status) * 2
9696
offset := 0
97-
if len > height {
97+
if lineCount > height {
9898
// skip statuses that cannot be rendered
99-
offset = len - height
99+
offset = lineCount - height
100100
}
101101

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//go:build freebsd || linux || netbsd || openbsd || solaris
2+
3+
/*
4+
Copyright The ORAS Authors.
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
package progress
19+
20+
import (
21+
"fmt"
22+
"testing"
23+
24+
"oras.land/oras/cmd/oras/internal/display/status/console"
25+
"oras.land/oras/cmd/oras/internal/display/status/console/testutils"
26+
)
27+
28+
func Test_manager_render(t *testing.T) {
29+
pty, device, err := testutils.NewPty()
30+
if err != nil {
31+
t.Fatal(err)
32+
}
33+
defer device.Close()
34+
m := &manager{
35+
console: &console.Console{Console: pty},
36+
}
37+
_, height := m.console.Size()
38+
for i := 0; i < height; i++ {
39+
if _, err := m.Add(); err != nil {
40+
t.Fatal(err)
41+
}
42+
}
43+
m.render()
44+
// validate
45+
var want []string
46+
for i := height; i > 0; i -= 2 {
47+
want = append(want, fmt.Sprintf("%dF%s", i, zeroStatus))
48+
}
49+
if err = testutils.MatchPty(pty, device, want...); err != nil {
50+
t.Fatal(err)
51+
}
52+
}

cmd/oras/internal/display/status/progress/status_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func Test_status_String(t *testing.T) {
6868
}
6969
}
7070

71-
func Test_status_String_zeroWitdth(t *testing.T) {
71+
func Test_status_String_zeroWidth(t *testing.T) {
7272
// zero status and progress
7373
s := newStatus()
7474
if status, digest := s.String(console.MinWidth); status != zeroStatus || digest != zeroDigest {

0 commit comments

Comments
 (0)