-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Terry Howe <terrylhowe@gmail.com>
- Loading branch information
Showing
7 changed files
with
214 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
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 console | ||
|
||
import ( | ||
"os" | ||
|
||
containerd "github.com/containerd/console" | ||
) | ||
|
||
type discardConsole struct { | ||
*os.File | ||
} | ||
|
||
func NewDiscardConsole(f *os.File) Console { | ||
dc := discardConsole{ | ||
File: f, | ||
} | ||
return &dc | ||
} | ||
|
||
// Fd returns its file descriptor | ||
func (mc *discardConsole) Fd() uintptr { | ||
return os.Stderr.Fd() | ||
} | ||
|
||
// Name returns its file name | ||
func (mc *discardConsole) Name() string { | ||
return mc.File.Name() | ||
} | ||
|
||
func (mc *discardConsole) Resize(_ containerd.WinSize) error { | ||
return nil | ||
} | ||
|
||
func (mc *discardConsole) ResizeFrom(containerd.Console) error { | ||
return nil | ||
} | ||
func (mc *discardConsole) SetRaw() error { | ||
return nil | ||
} | ||
func (mc *discardConsole) DisableEcho() error { | ||
return nil | ||
} | ||
func (mc *discardConsole) Reset() error { | ||
return nil | ||
} | ||
func (mc *discardConsole) Size() (containerd.WinSize, error) { | ||
ws := containerd.WinSize{ | ||
Width: 80, | ||
Height: 24, | ||
} | ||
return ws, nil | ||
} | ||
|
||
// GetHeightWidth returns the width and height of the console. | ||
func (mc *discardConsole) GetHeightWidth() (height, width int) { | ||
windowSize, _ := mc.Size() | ||
return int(windowSize.Height), int(windowSize.Width) | ||
} | ||
|
||
func (mc *discardConsole) Save() { | ||
} | ||
|
||
func (mc *discardConsole) NewRow() { | ||
} | ||
|
||
func (mc *discardConsole) OutputTo(_ uint, _ string) { | ||
} | ||
|
||
func (mc *discardConsole) Restore() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
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 console | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
containerd "github.com/containerd/console" | ||
) | ||
|
||
func TestConsole_New(t *testing.T) { | ||
mockFile, err := os.OpenFile(os.DevNull, os.O_RDWR, 0666) | ||
if err != nil { | ||
t.Fatalf("Unexpected error %v", err) | ||
} | ||
|
||
sut, err := NewConsole(mockFile) | ||
if err != nil { | ||
t.Errorf("Unexpected error %v", err) | ||
} | ||
|
||
if err = sut.Resize(containerd.WinSize{}); err != nil { | ||
t.Errorf("Unexpected erro for Resize: %v", err) | ||
} | ||
if err = sut.ResizeFrom(nil); err != nil { | ||
t.Errorf("Unexpected erro for Resize: %v", err) | ||
} | ||
if err = sut.SetRaw(); err != nil { | ||
t.Errorf("Unexpected erro for Resize: %v", err) | ||
} | ||
if err = sut.DisableEcho(); err != nil { | ||
t.Errorf("Unexpected erro for Resize: %v", err) | ||
} | ||
if err = sut.Reset(); err != nil { | ||
t.Errorf("Unexpected erro for Resize: %v", err) | ||
} | ||
windowSize, _ := sut.Size() | ||
if windowSize.Height != 24 { | ||
t.Errorf("Expected size 24 actual %d", windowSize.Height) | ||
} | ||
if windowSize.Width != 80 { | ||
t.Errorf("Expected size 80 actual %d", windowSize.Width) | ||
} | ||
h, w := sut.GetHeightWidth() | ||
if h != 24 { | ||
t.Errorf("Expected size 24 actual %d", h) | ||
} | ||
if w != 80 { | ||
t.Errorf("Expected size 80 actual %d", w) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.