summaryrefslogtreecommitdiffstats
path: root/termui/init.go
blob: a48ecfcccdd6f8d204accb015a4cf960c6e27846 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package termui

import (
	tb "github.com/nsf/termbox-go"
)

// Init initializes termui library. This function should be called before any others.
// After initialization, the library must be finalized by 'Close' function.
func Init() error {
	if err := tb.Init(); err != nil {
		return err
	}
	tb.SetInputMode(tb.InputEsc | tb.InputMouse)
	tb.SetOutputMode(tb.Output256)

	Body = NewGrid()
	Body.BgColor = Theme.Bg

	// renderLock.Lock()
	Body.Width, Body.Height = tb.Size()
	// renderLock.Unlock()

	return nil
}

// Close finalizes termui library,
// should be called after successful initialization when termui's functionality isn't required anymore.
func Close() {
	tb.Close()
}