Skip to content

Commit

Permalink
Minor refactoring tcell library from tui.go to tcell.go
Browse files Browse the repository at this point in the history
To prevent including tcell library in non-windows builds.
  • Loading branch information
vovcacik authored and junegunn committed Oct 2, 2021
1 parent 0ff8854 commit b8aa2d2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
9 changes: 6 additions & 3 deletions src/tui/tcell.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,11 @@ func (a Attr) Merge(b Attr) Attr {
return a | b
}

// handle the following as private members of FullscreenRenderer instance
// they are declared here to prevent introducing tcell library in non-windows builds
var (
_screen tcell.Screen
_screen tcell.Screen
_prevMouseButton tcell.ButtonMask
)

func (r *FullscreenRenderer) initScreen() {
Expand Down Expand Up @@ -193,8 +196,8 @@ func (r *FullscreenRenderer) GetChar() Event {
mod := ev.Modifiers() != 0

// since we dont have mouse down events (unlike LightRenderer), we need to track state in prevButton
prevButton, button := r.prevMouseButton, ev.Buttons()
r.prevMouseButton = button
prevButton, button := _prevMouseButton, ev.Buttons()
_prevMouseButton = button
drag := prevButton == button

switch {
Expand Down
24 changes: 10 additions & 14 deletions src/tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"os"
"strconv"
"time"

"github.com/gdamore/tcell"
)

// Types of user action
Expand Down Expand Up @@ -399,22 +397,20 @@ type Window interface {
}

type FullscreenRenderer struct {
theme *ColorTheme
mouse bool
forceBlack bool
prevDownTime time.Time
prevMouseButton tcell.ButtonMask
clickY []int
theme *ColorTheme
mouse bool
forceBlack bool
prevDownTime time.Time
clickY []int
}

func NewFullscreenRenderer(theme *ColorTheme, forceBlack bool, mouse bool) Renderer {
r := &FullscreenRenderer{
theme: theme,
mouse: mouse,
forceBlack: forceBlack,
prevDownTime: time.Unix(0, 0),
prevMouseButton: tcell.ButtonNone,
clickY: []int{}}
theme: theme,
mouse: mouse,
forceBlack: forceBlack,
prevDownTime: time.Unix(0, 0),
clickY: []int{}}
return r
}

Expand Down

0 comments on commit b8aa2d2

Please sign in to comment.