Skip to content

Commit

Permalink
Change tcell calls to private
Browse files Browse the repository at this point in the history
  • Loading branch information
dankox committed Nov 8, 2020
1 parent a81de49 commit 765f780
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 42 deletions.
26 changes: 13 additions & 13 deletions gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ type Gui struct {

// NewGui returns a new Gui object with a given output mode.
func NewGui(mode OutputMode, supportOverlaps bool) (*Gui, error) {
err := Init()
err := tcellInit()
if err != nil {
return nil, err
}

g := &Gui{}

g.outputMode = mode
SetOutputMode(OutputMode(mode))
tcellSetOutputMode(OutputMode(mode))

g.stop = make(chan struct{})

Expand All @@ -102,7 +102,7 @@ func NewGui(mode OutputMode, supportOverlaps bool) (*Gui, error) {
return nil, err
}
} else {
g.maxX, g.maxY = Size()
g.maxX, g.maxY = tcellSize()
}

g.BgColor, g.FgColor, g.FrameColor = ColorDefault, ColorDefault, ColorDefault
Expand All @@ -121,7 +121,7 @@ func (g *Gui) Close() {
go func() {
g.stop <- struct{}{}
}()
Close()
tcellClose()
}

// Size returns the terminal's size.
Expand All @@ -136,7 +136,7 @@ func (g *Gui) SetRune(x, y int, ch rune, fgColor, bgColor Attribute) error {
if x < 0 || y < 0 || x >= g.maxX || y >= g.maxY {
return errors.New("invalid point")
}
SetCell(x, y, ch, Attribute(fgColor), Attribute(bgColor))
tcellSetCell(x, y, ch, fgColor, bgColor)
return nil
}

Expand Down Expand Up @@ -435,7 +435,7 @@ func (g *Gui) MainLoop() error {
case <-g.stop:
return
default:
g.tbEvents <- PollEvent()
g.tbEvents <- tcellPollEvent()
}
}
}()
Expand All @@ -447,7 +447,7 @@ func (g *Gui) MainLoop() error {
if g.Mouse {
inputMode |= InputMouse
}
SetInputMode(inputMode)
tcellSetInputMode(inputMode)

if err := g.flush(); err != nil {
return err
Expand Down Expand Up @@ -508,9 +508,9 @@ func (g *Gui) handleEvent(ev *Event) error {

// flush updates the gui, re-drawing frames and buffers.
func (g *Gui) flush() error {
Clear(Attribute(g.FgColor), Attribute(g.BgColor))
tcellClear(Attribute(g.FgColor), Attribute(g.BgColor))

maxX, maxY := Size()
maxX, maxY := tcellSize()
// if GUI's size has changed, we need to redraw all views
if maxX != g.maxX || maxY != g.maxY {
for _, v := range g.views {
Expand Down Expand Up @@ -569,7 +569,7 @@ func (g *Gui) flush() error {
return err
}
}
Flush()
tcellFlush()
return nil
}

Expand Down Expand Up @@ -784,13 +784,13 @@ func (g *Gui) draw(v *View) error {
gMaxX, gMaxY := g.Size()
cx, cy := curview.x0+curview.cx+1, curview.y0+curview.cy+1
if cx >= 0 && cx < gMaxX && cy >= 0 && cy < gMaxY {
SetCursor(cx, cy)
tcellSetCursor(cx, cy)
} else {
HideCursor()
tcellHideCursor()
}
}
} else {
HideCursor()
tcellHideCursor()
}

v.clearRunes()
Expand Down
50 changes: 25 additions & 25 deletions tcell_compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
var screen tcell.Screen
var outMode OutputMode

// Init initializes the screen for use.
func Init() error {
// tcellInit initializes the screen for use.
func tcellInit() error {
outMode = OutputNormal
if s, e := tcell.NewScreen(); e != nil {
return e
Expand All @@ -38,29 +38,29 @@ func Init() error {
}
}

// Close cleans up the terminal, restoring terminal modes, etc.
func Close() {
// tcellClose cleans up the terminal, restoring terminal modes, etc.
func tcellClose() {
screen.Fini()
}

// Flush updates the screen.
func Flush() error {
// tcellFlush updates the screen.
func tcellFlush() error {
screen.Show()
return nil
}

// SetCursor displays the terminal cursor at the given location.
func SetCursor(x, y int) {
// tcellSetCursor displays the terminal cursor at the given location.
func tcellSetCursor(x, y int) {
screen.ShowCursor(x, y)
}

// HideCursor hides the terminal cursor.
func HideCursor() {
SetCursor(-1, -1)
// tcellHideCursor hides the terminal cursor.
func tcellHideCursor() {
tcellSetCursor(-1, -1)
}

// Size returns the screen size as width, height in character cells.
func Size() (int, int) {
// tcellSize returns the screen size as width, height in character cells.
func tcellSize() (int, int) {
return screen.Size()
}

Expand Down Expand Up @@ -189,8 +189,8 @@ func GetColor(color string) Attribute {
return ColorDefault
}

// Clear clears the screen with the given attributes.
func Clear(fg, bg Attribute) {
// tcellClear clears the screen with the given attributes.
func tcellClear(fg, bg Attribute) {
st := mkStyle(fg, bg)
w, h := screen.Size()
for row := 0; row < h; row++ {
Expand All @@ -211,8 +211,8 @@ const (
InputCurrent InputMode = 0
)

// SetInputMode does not do anything in this version.
func SetInputMode(mode InputMode) InputMode {
// tcellSetInputMode does not do anything in this version.
func tcellSetInputMode(mode InputMode) InputMode {
if mode&InputMouse != 0 {
screen.EnableMouse()
return InputEsc | InputMouse
Expand All @@ -235,8 +235,8 @@ const (
OutputTrue
)

// SetOutputMode is used to set the color palette used.
func SetOutputMode(mode OutputMode) OutputMode {
// tcellSetOutputMode is used to set the color palette used.
func tcellSetOutputMode(mode OutputMode) OutputMode {
if screen.Colors() < 256 {
mode = OutputNormal
}
Expand All @@ -251,15 +251,15 @@ func SetOutputMode(mode OutputMode) OutputMode {
}
}

// Sync forces a resync of the screen.
func Sync() error {
// tcellSync forces a resync of the screen.
func tcellSync() error {
screen.Sync()
return nil
}

// SetCell sets the character cell at a given location to the given
// tcellSetCell sets the character cell at a given location to the given
// content (rune) and attributes.
func SetCell(x, y int, ch rune, fg, bg Attribute) {
func tcellSetCell(x, y int, ch rune, fg, bg Attribute) {
st := mkStyle(fg, bg)
screen.SetContent(x, y, ch, nil, st)
}
Expand Down Expand Up @@ -480,8 +480,8 @@ func makeEvent(tev tcell.Event) Event {
}
}

// PollEvent blocks until an event is ready, and then returns it.
func PollEvent() Event {
// tcellPollEvent blocks until an event is ready, and then returns it.
func tcellPollEvent() Event {
ev := screen.PollEvent()
return makeEvent(ev)
}
6 changes: 2 additions & 4 deletions view.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,7 @@ func (v *View) setRune(x, y int, ch rune, fgColor, bgColor Attribute) error {
ch = ' '
}

SetCell(v.x0+x+1, v.y0+y+1, ch,
Attribute(fgColor), Attribute(bgColor))
tcellSetCell(v.x0+x+1, v.y0+y+1, ch, fgColor, bgColor)

return nil
}
Expand Down Expand Up @@ -632,8 +631,7 @@ func (v *View) clearRunes() {
maxX, maxY := v.Size()
for x := 0; x < maxX; x++ {
for y := 0; y < maxY; y++ {
SetCell(v.x0+x+1, v.y0+y+1, ' ',
Attribute(v.FgColor), Attribute(v.BgColor))
tcellSetCell(v.x0+x+1, v.y0+y+1, ' ', v.FgColor, v.BgColor)
}
}
}
Expand Down

0 comments on commit 765f780

Please sign in to comment.