Rename st to style for tcell.Style

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

@ -113,7 +113,7 @@ func (g *Gui) Size() (x, y int) {
}
// temporary kludge for the pretty
func (g *Gui) prettyColor(x, y int, st tcell.Style) tcell.Style {
func (g *Gui) prettyColor(x, y int, style tcell.Style) tcell.Style {
if true {
w, h := g.screen.Size()
@ -121,27 +121,27 @@ func (g *Gui) prettyColor(x, y int, st tcell.Style) tcell.Style {
red := int32(0)
grn := int32(0)
blu := int32(50 * float64(y) / float64(h))
st = st.Background(tcell.NewRGBColor(red, grn, blu))
style = style.Background(tcell.NewRGBColor(red, grn, blu))
// two-axis green-blue gradient
red = int32(200)
grn = int32(255 * float64(y) / float64(h))
blu = int32(255 * float64(x) / float64(w))
st = st.Foreground(tcell.NewRGBColor(red, grn, blu))
style = style.Foreground(tcell.NewRGBColor(red, grn, blu))
}
return st
return style
}
// SetRune writes a rune at the given point, relative to the top-left
// corner of the terminal. It checks if the position is valid and applies
// the given colors.
func (g *Gui) SetRune(x, y int, ch rune, st tcell.Style) error {
func (g *Gui) SetRune(x, y int, ch rune, style tcell.Style) error {
if x < 0 || y < 0 || x >= g.maxX || y >= g.maxY {
return errors.New("invalid point")
}
// temporary kludge for the pretty
// st = g.prettyColor(x, y, st)
g.screen.SetContent(x, y, ch, nil, st)
g.screen.SetContent(x, y, ch, nil, style)
return nil
}
@ -524,7 +524,7 @@ func (g *Gui) flush() error {
}
// drawFrameEdges draws the horizontal and vertical edges of a view.
func (g *Gui) drawFrameEdges(v *View, st tcell.Style) error {
func (g *Gui) drawFrameEdges(v *View, style tcell.Style) error {
runeH, runeV := '─', '│'
if g.ASCII {
runeH, runeV = '-', '|'
@ -535,12 +535,12 @@ func (g *Gui) drawFrameEdges(v *View, st tcell.Style) error {
continue
}
if v.y0 > -1 && v.y0 < g.maxY {
if err := g.SetRune(x, v.y0, runeH, st); err != nil {
if err := g.SetRune(x, v.y0, runeH, style); err != nil {
return err
}
}
if v.y1 > -1 && v.y1 < g.maxY {
if err := g.SetRune(x, v.y1, runeH, st); err != nil {
if err := g.SetRune(x, v.y1, runeH, style); err != nil {
return err
}
}
@ -550,12 +550,12 @@ func (g *Gui) drawFrameEdges(v *View, st tcell.Style) error {
continue
}
if v.x0 > -1 && v.x0 < g.maxX {
if err := g.SetRune(v.x0, y, runeV, st); err != nil {
if err := g.SetRune(v.x0, y, runeV, style); err != nil {
return err
}
}
if v.x1 > -1 && v.x1 < g.maxX {
if err := g.SetRune(v.x1, y, runeV, st); err != nil {
if err := g.SetRune(v.x1, y, runeV, style); err != nil {
return err
}
}
@ -564,7 +564,7 @@ func (g *Gui) drawFrameEdges(v *View, st tcell.Style) error {
}
// drawFrameCorners draws the corners of the view.
func (g *Gui) drawFrameCorners(v *View, st tcell.Style) error {
func (g *Gui) drawFrameCorners(v *View, style tcell.Style) error {
runeTL, runeTR, runeBL, runeBR := '┌', '┐', '└', '┘'
if g.ASCII {
runeTL, runeTR, runeBL, runeBR = '+', '+', '+', '+'
@ -577,7 +577,7 @@ func (g *Gui) drawFrameCorners(v *View, st tcell.Style) error {
for _, c := range corners {
if c.x >= 0 && c.y >= 0 && c.x < g.maxX && c.y < g.maxY {
if err := g.SetRune(c.x, c.y, c.ch, st); err != nil {
if err := g.SetRune(c.x, c.y, c.ch, style); err != nil {
return err
}
}
@ -586,7 +586,7 @@ func (g *Gui) drawFrameCorners(v *View, st tcell.Style) error {
}
// drawTitle draws the title of the view.
func (g *Gui) drawTitle(v *View, st tcell.Style) error {
func (g *Gui) drawTitle(v *View, style tcell.Style) error {
if v.y0 < 0 || v.y0 >= g.maxY {
return nil
}
@ -598,7 +598,7 @@ func (g *Gui) drawTitle(v *View, st tcell.Style) error {
} else if x > v.x1-2 || x >= g.maxX {
break
}
if err := g.SetRune(x, v.y0, ch, st); err != nil {
if err := g.SetRune(x, v.y0, ch, style); err != nil {
return err
}
}

@ -128,7 +128,7 @@ func (v *View) Name() string {
// setRune sets a rune at the given point relative to the view. It applies the
// specified colors, taking into account if the cell must be highlighted. Also,
// it checks if the position is valid.
func (v *View) setRune(x, y int, ch rune, st tcell.Style) error {
func (v *View) setRune(x, y int, ch rune, style tcell.Style) error {
maxX, maxY := v.Size()
if x < 0 || x >= maxX || y < 0 || y >= maxY {
return errors.New("invalid point")
@ -150,13 +150,13 @@ func (v *View) setRune(x, y int, ch rune, st tcell.Style) error {
}
if v.Mask != 0 {
st = v.Style
style = v.Style
ch = v.Mask
} else if v.Highlight && ry == rcy {
st = v.SelStyle
style = v.SelStyle
}
v.g.SetRune(v.x0+x+1, v.y0+y+1, ch, st)
v.g.SetRune(v.x0+x+1, v.y0+y+1, ch, style)
return nil
}

@ -28,8 +28,8 @@ func (ui *UI) GetGocui() *gocui.Gui {
}
// SetFgColor sets the default style
func (ui *UI) SetStyle(st tcell.Style) {
ui.g.Style = st
func (ui *UI) SetStyle(style tcell.Style) {
ui.g.Style = style
}
// SetInputEsc enables the escape key

@ -215,16 +215,16 @@ func (view *View) SetWrap(enabled bool) error {
}
// SetStyle sets the text style for the view
func (view *View) SetStyle(st tcell.Style) {
func (view *View) SetStyle(style tcell.Style) {
if view.HasBacking() {
view.backing.Style = st
view.backing.Style = style
}
}
// SetStyle sets the selection text style for the view
func (view *View) SetSelStyle(st tcell.Style) {
func (view *View) SetSelStyle(style tcell.Style) {
if view.HasBacking() {
view.backing.SelStyle = st
view.backing.SelStyle = style
}
}

Loading…
Cancel
Save