Skip to content

Commit

Permalink
refactor: remove console Size method
Browse files Browse the repository at this point in the history
Signed-off-by: Terry Howe <terrylhowe@gmail.com>
  • Loading branch information
TerryHowe committed Sep 29, 2024
1 parent 9ce8b55 commit 83474e7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 29 deletions.
28 changes: 10 additions & 18 deletions cmd/oras/internal/display/status/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,19 @@ func NewConsole(f *os.File) (Console, error) {
return &console{c}, nil
}

// Size returns the width and height of the console.
// GetHeightWidth returns the width and height of the console.
// If the console size cannot be determined, returns a default value of 80x10.
func (c *console) Size() (size containerd.WinSize, err error) {
size, err = c.Console.Size()
func (c *console) GetHeightWidth() (height, width int) {
windowSize, err := c.Console.Size()
if err != nil {
size.Height = MinHeight
size.Width = MinWidth
} else {
if size.Height < MinHeight {
size.Height = MinHeight
}
if size.Width < MinWidth {
size.Width = MinWidth
}
return MinHeight, MinWidth

Check warning on line 64 in cmd/oras/internal/display/status/console/console.go

View check run for this annotation

Codecov / codecov/patch

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

Added line #L64 was not covered by tests
}
if windowSize.Height < MinHeight {
windowSize.Height = MinHeight
}
if windowSize.Width < MinWidth {
windowSize.Width = MinWidth
}
return
}

// GetHeightWidth returns the width and height of the console.
func (c *console) GetHeightWidth() (height, width int) {
windowSize, _ := c.Size()
return int(windowSize.Height), int(windowSize.Width)
}

Expand Down
11 changes: 0 additions & 11 deletions cmd/oras/internal/display/status/console/console_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,6 @@ func TestNewConsole(t *testing.T) {
}
}

func TestConsole_Size(t *testing.T) {
c, _ := givenConsole(t)

size, err := c.Size()
if err != nil {
t.Fatalf("unexpected error getting size: %v", err)
}
validateSize(t, int(size.Width), int(size.Height), MinWidth, MinHeight)

}

func TestConsole_GetHeightWidth(t *testing.T) {
c, pty := givenConsole(t)

Expand Down

0 comments on commit 83474e7

Please sign in to comment.