From 83474e7ac2c68f4f66e63b1fc358f24d06f8a0cb Mon Sep 17 00:00:00 2001 From: Terry Howe Date: Sun, 29 Sep 2024 09:28:51 -0600 Subject: [PATCH] refactor: remove console Size method Signed-off-by: Terry Howe --- .../display/status/console/console.go | 28 +++++++------------ .../display/status/console/console_test.go | 11 -------- 2 files changed, 10 insertions(+), 29 deletions(-) diff --git a/cmd/oras/internal/display/status/console/console.go b/cmd/oras/internal/display/status/console/console.go index 366a46cf7..fd9c06ec3 100644 --- a/cmd/oras/internal/display/status/console/console.go +++ b/cmd/oras/internal/display/status/console/console.go @@ -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 + } + 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) } diff --git a/cmd/oras/internal/display/status/console/console_test.go b/cmd/oras/internal/display/status/console/console_test.go index d41f36bce..65549e9e2 100644 --- a/cmd/oras/internal/display/status/console/console_test.go +++ b/cmd/oras/internal/display/status/console/console_test.go @@ -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)