diff options
author | Marco Vedovati <mvedovati@suse.com> | 2018-06-19 12:28:01 +0200 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-06-19 19:03:12 +0000 |
commit | f228cf73e0318f48c94ec4cd1b9b3115cfbb763a (patch) | |
tree | d013f9b6b9e627ca40054a1085128775fdac8719 /cmd/podman | |
parent | 2d0d1c4b5f12b50904728f764f4ac36f00ccace0 (diff) | |
download | podman-f228cf73e0318f48c94ec4cd1b9b3115cfbb763a.tar.gz podman-f228cf73e0318f48c94ec4cd1b9b3115cfbb763a.tar.bz2 podman-f228cf73e0318f48c94ec4cd1b9b3115cfbb763a.zip |
Add carriage return to log message when using --tty flag
Signed-off-by: Marco Vedovati <mvedovati@suse.com>
Add a raw text formatter for logrus to be used when terminal is in raw
mode (i.e. when allocating a pseudo-TTY for the container). The raw text
formatter terminates the log messages with the corret \r\n sequence.
Closes: #967
Approved by: rhatdan
Diffstat (limited to 'cmd/podman')
-rw-r--r-- | cmd/podman/utils.go | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/cmd/podman/utils.go b/cmd/podman/utils.go index 227426c18..fdb720cec 100644 --- a/cmd/podman/utils.go +++ b/cmd/podman/utils.go @@ -14,6 +14,9 @@ import ( "k8s.io/client-go/tools/remotecommand" ) +type RawTtyFormatter struct { +} + // Attach to a container func attachCtr(ctr *libpod.Container, stdout, stderr, stdin *os.File, detachKeys string, sigProxy bool) error { resize := make(chan remotecommand.TerminalSize) @@ -37,9 +40,10 @@ func attachCtr(ctr *libpod.Container, stdout, stderr, stdin *os.File, detachKeys return errors.Wrapf(err, "unable to save terminal state") } + logrus.SetFormatter(&RawTtyFormatter{}) term.SetRawTerminal(os.Stdin.Fd()) - defer term.RestoreTerminal(os.Stdin.Fd(), oldTermState) + defer restoreTerminal(oldTermState) } streams := new(libpod.AttachStreams) @@ -93,9 +97,10 @@ func startAttachCtr(ctr *libpod.Container, stdout, stderr, stdin *os.File, detac return errors.Wrapf(err, "unable to save terminal state") } + logrus.SetFormatter(&RawTtyFormatter{}) term.SetRawTerminal(os.Stdin.Fd()) - defer term.RestoreTerminal(os.Stdin.Fd(), oldTermState) + defer restoreTerminal(oldTermState) } streams := new(libpod.AttachStreams) @@ -171,3 +176,19 @@ func resizeTty(resize chan remotecommand.TerminalSize, resizeTerminate chan inte } }() } + +func restoreTerminal(state *term.State) error { + logrus.SetFormatter(&logrus.TextFormatter{}) + return term.RestoreTerminal(os.Stdin.Fd(), state) +} + +func (f *RawTtyFormatter) Format(entry *logrus.Entry) ([]byte, error) { + textFormatter := logrus.TextFormatter{} + bytes, err := textFormatter.Format(entry) + + if err == nil { + bytes = append(bytes, '\r') + } + + return bytes, err +} |