Skip to content

Commit

Permalink
Update to latest textGrid API with background colour support
Browse files Browse the repository at this point in the history
Update our colour parsing to handle backgrounds as well
  • Loading branch information
andydotxyz committed Mar 13, 2020
1 parent a449646 commit 5f95108
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 40 deletions.
88 changes: 77 additions & 11 deletions escape.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"fyne.io/fyne/theme"
)

var currentFG color.Color
var currentFG, currentBG color.Color

func (t *Terminal) handleEscape(code string) {
switch code { // exact matches
Expand Down Expand Up @@ -42,33 +42,99 @@ func (t *Terminal) handleEscape(code string) {
}
case "m":
if message == "" || message == "0" {
currentBG = nil
currentFG = nil
return
}

modes := strings.Split(message, ";")
bright := false

mode := modes[0]
if mode == "1" {
bright = true
if len(modes) <= 1 {
break
}
mode = modes[1]
} else if len(modes) >= 2 && modes[1] == "1" {
bright = true
}
for _, mode := range modes {
switch mode {
case "1": // ignore, handled above
case "7": // reverse
currentFG = theme.BackgroundColor()
currentBG, currentFG = theme.TextColor(), theme.ButtonColor() //currentFG, currentBG
case "27": // reverse off
currentFG = nil
currentBG, currentFG = nil, nil //currentFG, currentBG
case "30":
currentFG = color.Black
if bright {
currentFG = &color.RGBA{85, 85, 85, 255}
} else {
currentFG = color.Black
}
case "31":
currentFG = &color.RGBA{255, 0, 0, 255}
if bright {
currentFG = &color.RGBA{255, 85, 85, 255}
} else {
currentFG = &color.RGBA{170, 0, 0, 255}
}
case "32":
currentFG = &color.RGBA{0, 255, 0, 255}
if bright {
currentFG = &color.RGBA{85, 255, 255, 255}
} else {
currentFG = &color.RGBA{0, 170, 0, 255}
}
case "33":
currentFG = &color.RGBA{255, 255, 0, 255}
if bright {
currentFG = &color.RGBA{255, 255, 85, 255}
} else {
currentFG = &color.RGBA{170, 170, 0, 255}
}
case "34":
currentFG = &color.RGBA{0, 0, 255, 255}
if bright {
currentFG = &color.RGBA{85, 85, 255, 255}
} else {
currentFG = &color.RGBA{0, 0, 170, 255}
}
case "35":
currentFG = &color.RGBA{255, 0, 255, 255}
if bright {
currentFG = &color.RGBA{255, 85, 255, 255}
} else {
currentFG = &color.RGBA{170, 0, 170, 255}
}
case "36":
currentFG = &color.RGBA{0, 255, 255, 255}
if bright {
currentFG = &color.RGBA{85, 255, 255, 255}
} else {
currentFG = &color.RGBA{0, 170, 170, 255}
}
case "37":
currentFG = color.White
if bright {
currentFG = &color.RGBA{255, 255, 255, 255}
} else {
currentFG = &color.RGBA{170, 170, 170, 255}
}
case "39":
currentFG = nil
case "40":
currentBG = color.Black
case "41":
currentBG = &color.RGBA{170, 0, 0, 255}
case "42":
currentBG = &color.RGBA{0, 170, 0, 255}
case "43":
currentBG = &color.RGBA{170, 170, 0, 255}
case "44":
currentBG = &color.RGBA{0, 0, 170, 255}
case "45":
currentBG = &color.RGBA{170, 0, 170, 255}
case "46":
currentBG = &color.RGBA{0, 255, 255, 255}
case "47":
currentBG = &color.RGBA{170, 170, 170, 255}
case "49":
currentBG = nil
default:
log.Println("Unsupported graphics mode", mode)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/fyne-io/terminal
go 1.13

require (
fyne.io/fyne v1.2.1-0.20200304180127-bc298b8dc3f3
fyne.io/fyne v1.2.4-0.20200313223516-cb7580fb5e97
github.com/creack/pty v1.1.9
github.com/stretchr/testify v1.3.1-0.20190311161405-34c6fa2dc709
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fyne.io/fyne v1.2.1-0.20200304180127-bc298b8dc3f3 h1:IYq4KcnC5+C6R+zB6Y1qL+JGvcO1nBQnFqEFeeDm6nY=
fyne.io/fyne v1.2.1-0.20200304180127-bc298b8dc3f3/go.mod h1:5nHgSQyRojVlrXE7qrNeRfVNXD8OUDaRt/Dudk5D0us=
fyne.io/fyne v1.2.4-0.20200313223516-cb7580fb5e97 h1:i9TdVFQ90MT3WZkOR7d9V1o1yv+ttj06dCSp8oc5zqU=
fyne.io/fyne v1.2.4-0.20200313223516-cb7580fb5e97/go.mod h1:5nHgSQyRojVlrXE7qrNeRfVNXD8OUDaRt/Dudk5D0us=
github.com/Kodeworks/golang-image-ico v0.0.0-20141118225523-73f0f4cfade9/go.mod h1:7uhhqiBaR4CpN0k9rMjOtjpcfGd6DG2m04zQxKnWQ0I=
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/creack/pty v1.1.9 h1:uDmaGzcdjhF4i/plgjmEsriH11Y0o7RKapEf/LDaM3w=
Expand Down
6 changes: 3 additions & 3 deletions output.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (t *Terminal) handleOutput(buf []byte) {
default:
if currentFG != nil {
// TODO not if we discard out
t.setCellStyle(t.cursorRow, t.cursorCol+len(out), currentFG)
t.setCellStyle(t.cursorRow, t.cursorCol+len(out), currentFG, currentBG)
}
out += string(r)
}
Expand All @@ -128,7 +128,7 @@ func (t *Terminal) handleOutput(buf []byte) {
t.Refresh()
}

func (t *Terminal) setCellStyle(row, col int, fgStyle color.Color) {
func (t *Terminal) setCellStyle(row, col int, fgStyle, bgStyle color.Color) {
if row < 0 {
return
}
Expand All @@ -145,7 +145,7 @@ func (t *Terminal) setCellStyle(row, col int, fgStyle color.Color) {
line = append(line, widget.TextGridCell{})
}
t.content.SetRow(row, line)
line[col].TextColor = fgStyle
t.content.SetStyle(row, col, &widget.CustomTextGridStyle{FGColor: fgStyle, BGColor: bgStyle})
}

func (t *Terminal) ringBell() {
Expand Down
120 changes: 97 additions & 23 deletions vendor/fyne.io/fyne/widget/textgrid.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5f95108

Please sign in to comment.