mirror of https://github.com/mum4k/termdash.git
Termbox now starts in 256 color mode by default.
This commit is contained in:
parent
e9d04711cc
commit
18a99caf16
|
@ -39,7 +39,11 @@ func (o option) set(t *Terminal) {
|
|||
o(t)
|
||||
}
|
||||
|
||||
// DefaultColorMode is the default value for the ColorMode option.
|
||||
const DefaultColorMode = terminalapi.ColorMode256
|
||||
|
||||
// ColorMode sets the terminal color mode.
|
||||
// Defaults to DefaultColorMode.
|
||||
func ColorMode(cm terminalapi.ColorMode) Option {
|
||||
return option(func(t *Terminal) {
|
||||
t.colorMode = cm
|
||||
|
@ -60,6 +64,19 @@ type Terminal struct {
|
|||
colorMode terminalapi.ColorMode
|
||||
}
|
||||
|
||||
// newTerminal creates the terminal and applies the options.
|
||||
func newTerminal(opts ...Option) *Terminal {
|
||||
t := &Terminal{
|
||||
events: eventqueue.New(),
|
||||
done: make(chan struct{}),
|
||||
colorMode: DefaultColorMode,
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt.set(t)
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
// New returns a new termbox based Terminal.
|
||||
// Call Close() when the terminal isn't required anymore.
|
||||
func New(opts ...Option) (*Terminal, error) {
|
||||
|
@ -68,14 +85,7 @@ func New(opts ...Option) (*Terminal, error) {
|
|||
}
|
||||
tbx.SetInputMode(tbx.InputEsc | tbx.InputMouse)
|
||||
|
||||
t := &Terminal{
|
||||
events: eventqueue.New(),
|
||||
done: make(chan struct{}),
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt.set(t)
|
||||
}
|
||||
|
||||
t := newTerminal(opts...)
|
||||
om, err := colorMode(t.colorMode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package termbox
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/kylelemons/godebug/pretty"
|
||||
"github.com/mum4k/termdash/eventqueue"
|
||||
"github.com/mum4k/termdash/terminalapi"
|
||||
)
|
||||
|
||||
func TestNewTerminal(t *testing.T) {
|
||||
tests := []struct {
|
||||
desc string
|
||||
opts []Option
|
||||
want *Terminal
|
||||
}{
|
||||
{
|
||||
desc: "default options",
|
||||
want: &Terminal{
|
||||
events: eventqueue.New(),
|
||||
done: make(chan struct{}),
|
||||
colorMode: terminalapi.ColorMode256,
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "sets color mode",
|
||||
opts: []Option{
|
||||
ColorMode(terminalapi.ColorModeNormal),
|
||||
},
|
||||
want: &Terminal{
|
||||
events: eventqueue.New(),
|
||||
done: make(chan struct{}),
|
||||
colorMode: terminalapi.ColorModeNormal,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
got := newTerminal(tc.opts...)
|
||||
if diff := pretty.Compare(tc.want, got); diff != "" {
|
||||
t.Errorf("newTerminal => unexpected diff (-want, +got):\n%s", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue