forked from docker/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract streams helpers from command package to their own package to …
…remove a cyclic dependency from command to internal/containerizedengine Aliasing old types * streams.InStream -> streams.In * streams.NewInStream -> streams.NewIn * streams.OutStream -> streams.Out * streams.NewOutStream -> streams.NewOut Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
- Loading branch information
1 parent
81e7426
commit eb0ba4f
Showing
17 changed files
with
136 additions
and
108 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
This file was deleted.
Oops, something went wrong.
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,23 @@ | ||
package command | ||
|
||
import ( | ||
"github.com/docker/cli/cli/streams" | ||
) | ||
|
||
// InStream is an input stream used by the DockerCli to read user input | ||
// Deprecated: Use github.com/docker/cli/cli/streams.In instead | ||
type InStream = streams.In | ||
|
||
// OutStream is an output stream used by the DockerCli to write normal program | ||
// output. | ||
// Deprecated: Use github.com/docker/cli/cli/streams.Out instead | ||
type OutStream = streams.Out | ||
|
||
var ( | ||
// NewInStream returns a new InStream object from a ReadCloser | ||
// Deprecated: Use github.com/docker/cli/cli/streams.NewIn instead | ||
NewInStream = streams.NewIn | ||
// NewOutStream returns a new OutStream object from a Writer | ||
// Deprecated: Use github.com/docker/cli/cli/streams.NewOut instead | ||
NewOutStream = streams.NewOut | ||
) |
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
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,50 @@ | ||
package streams | ||
|
||
import ( | ||
"io" | ||
"os" | ||
|
||
"github.com/docker/docker/pkg/term" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// Out is an output stream used by the DockerCli to write normal program | ||
// output. | ||
type Out struct { | ||
commonStream | ||
out io.Writer | ||
} | ||
|
||
func (o *Out) Write(p []byte) (int, error) { | ||
return o.out.Write(p) | ||
} | ||
|
||
// SetRawTerminal sets raw mode on the input terminal | ||
func (o *Out) SetRawTerminal() (err error) { | ||
if os.Getenv("NORAW") != "" || !o.commonStream.isTerminal { | ||
return nil | ||
} | ||
o.commonStream.state, err = term.SetRawTerminalOutput(o.commonStream.fd) | ||
return err | ||
} | ||
|
||
// GetTtySize returns the height and width in characters of the tty | ||
func (o *Out) GetTtySize() (uint, uint) { | ||
if !o.isTerminal { | ||
return 0, 0 | ||
} | ||
ws, err := term.GetWinsize(o.fd) | ||
if err != nil { | ||
logrus.Debugf("Error getting size: %s", err) | ||
if ws == nil { | ||
return 0, 0 | ||
} | ||
} | ||
return uint(ws.Height), uint(ws.Width) | ||
} | ||
|
||
// NewOut returns a new Out object from a Writer | ||
func NewOut(out io.Writer) *Out { | ||
fd, isTerminal := term.GetFdInfo(out) | ||
return &Out{commonStream: commonStream{fd: fd, isTerminal: isTerminal}, out: out} | ||
} |
Oops, something went wrong.