Remove more compat.go

pull/232/head
Simon Roberts 3 years ago
parent e91d298fe6
commit b49ff6cbdb
No known key found for this signature in database
GPG Key ID: 0F30F99E6B771FD4

@ -20,9 +20,9 @@ var (
)
// OutputMode represents the terminal's output mode (8 or 256 colors).
type OutputMode termbox.OutputMode
type OutputMode termbox.OutputMode // TODO: die
const (
const ( // TODO: die
// OutputNormal provides 8-colors terminal mode.
OutputNormal = OutputMode(termbox.OutputNormal)
@ -40,7 +40,7 @@ type Gui struct {
managers []Manager
keybindings []*keybinding
maxX, maxY int
outputMode OutputMode
outputMode OutputMode // TODO: die
// BgColor and FgColor allow to configure the background and foreground
// colors of the GUI.
@ -70,23 +70,34 @@ type Gui struct {
// The current event while in the handlers.
CurrentEvent tcell.Event
// The formerly-global Screen used by this gui.
Screen tcell.Screen
}
// NewGui returns a new Gui object with a given output mode.
func NewGui(mode OutputMode) (*Gui, error) {
if err := termbox.Init(); err != nil {
return nil, err
}
g := &Gui{}
//outMode = OutputNormal
if s, e := tcell.NewScreen(); e != nil {
return nil, e
} else if e = s.Init(); e != nil {
return nil, e
} else {
g.Screen = s
}
g.outputMode = mode
termbox.SetScreen(g.Screen) // ugly global
termbox.SetOutputMode(termbox.OutputMode(mode))
g.tbEvents = make(chan tcell.Event, 20)
g.userEvents = make(chan userEvent, 20)
g.maxX, g.maxY = termbox.Size()
g.maxX, g.maxY = g.Screen.Size()
g.BgColor, g.FgColor = ColorDefault, ColorDefault
g.SelBgColor, g.SelFgColor = ColorDefault, ColorDefault
@ -97,7 +108,7 @@ func NewGui(mode OutputMode) (*Gui, error) {
// Close finalizes the library. It should be called after a successful
// initialization and when gocui is not needed anymore.
func (g *Gui) Close() {
termbox.Close()
g.Screen.Fini()
}
// Size returns the terminal's size.
@ -376,14 +387,10 @@ func (g *Gui) MainLoop() error {
}
}()
inputMode := termbox.InputAlt
if g.InputEsc {
inputMode = termbox.InputEsc
}
if g.Mouse {
inputMode |= termbox.InputMouse
g.Screen.EnableMouse()
}
termbox.SetInputMode(inputMode)
// s.EnablePaste()
if err := g.flush(); err != nil {
return err
@ -443,7 +450,7 @@ func (g *Gui) handleEvent(ev tcell.Event) error {
func (g *Gui) flush() error {
termbox.Clear(termbox.Attribute(g.FgColor), termbox.Attribute(g.BgColor))
maxX, maxY := termbox.Size()
maxX, maxY := g.Screen.Size()
// if GUI's size has changed, we need to redraw all views
if maxX != g.maxX || maxY != g.maxY {
for _, v := range g.views {
@ -484,7 +491,7 @@ func (g *Gui) flush() error {
return err
}
}
termbox.Flush()
g.Screen.Show()
return nil
}
@ -589,13 +596,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 {
termbox.SetCursor(cx, cy)
g.Screen.ShowCursor(cx, cy)
} else {
termbox.HideCursor()
g.Screen.ShowCursor(-1, -1) // HideCursor
}
}
} else {
termbox.HideCursor()
g.Screen.ShowCursor(-1, -1) // HideCursor
}
v.clearRunes()

@ -20,46 +20,12 @@ import (
"github.com/gdamore/tcell/v2"
)
// Ugly globals
var screen tcell.Screen
var outMode OutputMode
// Init initializes the screen for use.
func Init() error {
outMode = OutputNormal
if s, e := tcell.NewScreen(); e != nil {
return e
} else if e = s.Init(); e != nil {
return e
} else {
screen = s
return nil
}
}
// Close cleans up the terminal, restoring terminal modes, etc.
func Close() {
screen.Fini()
}
// Flush updates the screen.
func Flush() error {
screen.Show()
return nil
}
// SetCursor displays the terminal cursor at the given location.
func SetCursor(x, y int) {
screen.ShowCursor(x, y)
}
// HideCursor hides the terminal cursor.
func HideCursor() {
SetCursor(-1, -1)
}
// Size returns the screen size as width, height in character cells.
func Size() (int, int) {
return screen.Size()
func SetScreen(s tcell.Screen) {
screen = s
}
// Attribute affects the presentation of characters, such as color, boldness,
@ -137,25 +103,6 @@ func Clear(fg, bg Attribute) {
}
}
// InputMode is not used.
type InputMode int
// Unused input modes; here for compatibility.
const (
InputCurrent InputMode = iota
InputEsc
InputAlt
InputMouse
)
// SetInputMode enables mouse if requested
func SetInputMode(mode InputMode) InputMode {
if mode&InputMouse != 0 {
screen.EnableMouse()
}
// We don't do anything else right now
return InputEsc
}
// OutputMode represents an output mode, which determines how colors
// are used. See the termbox documentation for an explanation.
@ -186,12 +133,6 @@ func SetOutputMode(mode OutputMode) OutputMode {
}
}
// Sync forces a resync of the screen.
func Sync() error {
screen.Sync()
return nil
}
// scaledColor returns a Color that is proportional to the x/y coordinates
func scaledColor(x, y int) tcell.Color {
w, h := screen.Size()
@ -229,10 +170,3 @@ const (
func PollEvent() tcell.Event {
return screen.PollEvent()
}
// Cell represents a single character cell on screen.
type Cell struct {
Ch rune
Fg Attribute
Bg Attribute
}

@ -4,29 +4,12 @@
package termui
import (
"image"
"io"
"sync"
"time"
"fmt"
"os"
"runtime/debug"
"bytes"
tm "github.com/cointop-sh/cointop/pkg/termbox"
"github.com/maruel/panicparse/stack"
)
// Bufferer should be implemented by all renderable components.
type Bufferer interface {
Buffer() Buffer
}
/*
// 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 {
@ -188,3 +171,4 @@ func Render(bs ...Bufferer) {
//go func() { renderJobs <- bs }()
renderJobs <- bs
}
*/

Loading…
Cancel
Save