Skip to content

Commit

Permalink
Use EnableVirtualTerminalProcessing in README.md and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Sep 20, 2022
1 parent c2a5320 commit 09de4e1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
8 changes: 6 additions & 2 deletions README.md
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions examples/color-chart/main.go
Expand Up @@ -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())

Expand Down
6 changes: 6 additions & 0 deletions examples/hello-world/main.go
Expand Up @@ -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",
Expand Down

0 comments on commit 09de4e1

Please sign in to comment.