Closed johnSchnake closed 9 years ago
@johnSchnake I made the PR #8 Is the problem still remains?
@shiena is there anything I should be aware for the color (https://github.com/fatih/color) package?
@fatih Maybe, there is no problem. The following is a simple difference. Please note the divided escape sequence and the non-color escape sequence.
package main
import (
"fmt"
"io"
"os"
"github.com/shiena/ansicolor"
)
func main() {
outputEscseq(ansicolor.NewAnsiColorWriter(os.Stdout))
outputEscseq(ansicolor.NewModeAnsiColorWriter(os.Stdout, ansicolor.OutputNonColorEscSeq))
}
func outputEscseq(w io.Writer) {
fmt.Fprint(w, "\x1b[31m")
fmt.Fprint(w, "fg red,")
fmt.Fprint(w, "\x1b")
fmt.Fprint(w, "[")
fmt.Fprint(w, "3")
fmt.Fprint(w, "2")
fmt.Fprint(w, "m") // divided escape sequence
fmt.Fprint(w, "fg green,")
fmt.Fprint(w, "\x1b[0m") // reset color
fmt.Fprint(w, "\x1b[3C") // non-color escape sequence
fmt.Fprint(w, "3step forward")
fmt.Fprintln(w)
}
in the case of cmd
in the case of mintty(no windows console)
Sorry for the delay but it looks like this works; I'll let you know if I stumble onto another problem.
OK. This issue was interesting.
Problem was discovered when using golangs ssh package. If an application tries to output escape sequences not recognized by ansicolor (e.g. if
$TERM=xterm
and you runtop
) then ashort write
error occurs and the stdout pipe would break (though the connection and stdin pipe still function).Preferably, the unrecognized sequences would just be placed into the buffer untouched.