diff --git a/README.md b/README.md index bf6b9b9..57da224 100644 --- a/README.md +++ b/README.md @@ -338,13 +338,17 @@ terminal applications on Unix support ANSI styling out-of-the-box, on Windows you need to enable ANSI processing in your application first: ```go - mode, err := termenv.EnableWindowsANSIConsole() + restoreConsole, err := termenv.EnableVirtualTerminalProcessing(os.Stdout) if err != nil { panic(err) } - defer termenv.RestoreWindowsConsole(mode) + defer restoreConsole() ``` +The above code is safe to include on non-Windows systems or when os.Stdout does +not refer to a terminal (e.g. in tests). + + ## Color Chart ![ANSI color chart](https://github.com/muesli/termenv/raw/master/examples/color-chart/color-chart.png) diff --git a/examples/color-chart/main.go b/examples/color-chart/main.go index 860dd2b..1ea232c 100644 --- a/examples/color-chart/main.go +++ b/examples/color-chart/main.go @@ -7,6 +7,12 @@ import ( ) func main() { + restoreConsole, err := termenv.EnableVirtualTerminalProcessing(termenv.DefaultOutput()) + if err != nil { + panic(err) + } + defer restoreConsole() + // Basic ANSI colors 0 - 15 fmt.Println(termenv.String("Basic ANSI colors").Bold()) diff --git a/examples/hello-world/main.go b/examples/hello-world/main.go index 48633c8..eaab4ad 100644 --- a/examples/hello-world/main.go +++ b/examples/hello-world/main.go @@ -7,6 +7,12 @@ import ( ) func main() { + restoreConsole, err := termenv.EnableVirtualTerminalProcessing(termenv.DefaultOutput()) + if err != nil { + panic(err) + } + defer restoreConsole() + p := termenv.ColorProfile() fmt.Printf("\n\t%s %s %s %s %s",