These Go Console APIs provide a level of abstraction over virtual terminals, implement testable io.Writer
, and support color schemes.
You can create a new console using os
streams:
package main
import (
"fmt"
"github.com/heaths/go-console"
)
func main() {
con := console.System()
fmt.Fprintln(con.Stdout(), "Hello, world!")
}
You can also create a new fake console that uses bytes.Buffer
you can access from Stdout()
as well:
package main
import (
"fmt"
"github.com/heaths/go-console"
)
func main() {
fake := console.Fake()
fmt.Fprintln(fake.Stdout(), "Hello, fake!")
fmt.Println(fake.Stdout().String())
}
This project is licensed under the MIT license.