-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: simplify reader with manager and messenger
Signed-off-by: Terry Howe <[email protected]>
- Loading branch information
Showing
11 changed files
with
318 additions
and
68 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
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,74 @@ | ||
/* | ||
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) | ||
} | ||
if sut.Fd() != os.Stderr.Fd() { | ||
t.Errorf("Expected size %d actual %d", sut.Fd(), os.Stderr.Fd()) | ||
} | ||
if sut.Name() != os.DevNull { | ||
t.Errorf("Expected size %s actual %s", sut.Name(), os.DevNull) | ||
} | ||
sut.OutputTo(0, "ignored") | ||
sut.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
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
Oops, something went wrong.