Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI via GitHub Actions #230

Merged
merged 34 commits into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ffdb045
display a table of the available 256 colors
scrouthtv Nov 5, 2020
27749c4
basic rgb usage working
scrouthtv Nov 5, 2020
d347a0b
added rgb demo
scrouthtv Nov 5, 2020
dcc430d
moved two new functions to a better place
scrouthtv Nov 5, 2020
6f2281e
slight performance increase
scrouthtv Nov 5, 2020
33a762c
documentation for public methods
scrouthtv Nov 5, 2020
b53f34a
extra attributes wip
scrouthtv Nov 5, 2020
bf2abfc
cursive mode working
scrouthtv Nov 5, 2020
a08d44e
implemented dim, blink hidden
scrouthtv Nov 5, 2020
8d78c26
code cleanup
scrouthtv Nov 5, 2020
a9ebf8a
added option to turn off rgb mode for testing dim
scrouthtv Nov 6, 2020
e139417
Added a max_attr at the end of the attribute list.
scrouthtv Nov 6, 2020
8093db4
Added brighter colors
scrouthtv Nov 6, 2020
694f63e
added demo for brighter colors
scrouthtv Nov 6, 2020
a325f32
fix for python 3.8
scrouthtv Nov 6, 2020
5951683
Minor fix to allow drawing in the default color in RGB mode
scrouthtv Nov 6, 2020
e788edd
moved the function to have a compilable windows version
scrouthtv Nov 6, 2020
788cdd7
Update README.md
scrouthtv Nov 7, 2020
018e6e1
minor fix to one of the examples
scrouthtv Nov 6, 2020
1d5051b
quit demo with any key
scrouthtv Nov 6, 2020
6acdded
fixed an issue where closing termbox multiple times would lock up the…
scrouthtv Nov 7, 2020
06a5ffe
bugfix
scrouthtv Nov 8, 2020
14551e6
Merge pull request #1 from nsf/master
scrouthtv Nov 23, 2020
bff17c8
Create test-ubuntu.yml
scrouthtv Nov 23, 2020
400cbc2
Update test-ubuntu.yml
scrouthtv Nov 23, 2020
f1efd79
Added an hello world file
scrouthtv Nov 23, 2020
4bba5f6
Update test-ubuntu.yml
scrouthtv Nov 23, 2020
c62478d
added support for go modules
scrouthtv Nov 24, 2020
c7a5c2c
Can't run hello world in the GitHub container
scrouthtv Nov 24, 2020
b544ea2
Ported CI to macos, windows
scrouthtv Nov 24, 2020
28c7400
better names, macos should be working now
scrouthtv Nov 24, 2020
57c627f
fix for windows ci
scrouthtv Nov 24, 2020
a8e7236
fix for windows ci 2/?
scrouthtv Nov 24, 2020
e880207
CI via GitHub Actions working
scrouthtv Nov 24, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
basic rgb usage working
  • Loading branch information
scrouthtv committed Nov 5, 2020
commit 27749c4038b72008e2bfba9d15ff859d5c857dad
65 changes: 65 additions & 0 deletions _demos/rgbcolor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package main

import (
"github.com/nsf/termbox-go"
"strconv"
)

var currentR int = 150
var currentG int = 100
var currentB int = 50

func draw_red_text() {
termbox.SetCell(5, 5, 'H', termbox.ColorRed, termbox.ColorDefault)
termbox.Flush()
}

func draw_colored_text() {
termbox.SetOutputMode(termbox.OutputRGB)
fg := termbox.RGBToAttribute(uint8(currentR), uint8(currentG), uint8(currentB))
bg := termbox.RGBToAttribute(5, 5, 5)
//panic("old color is " + fmt.Sprint(uint32(attr)))
// 9779300
for i, v := range "Here is some rgb text in #" + strconv.Itoa(currentR) + ";" + strconv.Itoa(currentG) + ";" + strconv.Itoa(currentB) + "; " {
termbox.SetCell(5+i, 5, v, fg, bg)
}
termbox.Flush()
}

func main() {
err := termbox.Init()
if err != nil {
panic(err)
}
defer termbox.Close()
termbox.SetInputMode(termbox.InputEsc)

draw_colored_text()
//draw_red_text()
mainloop:
for {
switch ev := termbox.PollEvent(); ev.Type {
case termbox.EventKey:
switch ev.Key {
case termbox.KeyEsc:
break mainloop
case termbox.KeyArrowLeft, termbox.KeyCtrlB:
currentR = currentR - 10
case termbox.KeyArrowRight, termbox.KeyCtrlF:
currentR = currentR + 10
case termbox.KeyArrowUp:
currentG = currentG - 10
case termbox.KeyArrowDown:
currentG = currentG + 10
default:
if ev.Ch == 'q' {
break mainloop
}
}
case termbox.EventError:
panic(ev.Err)
}
draw_colored_text()
//draw_red_text()
}
}
3 changes: 2 additions & 1 deletion api_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type (
EventType uint8
Modifier uint8
Key uint16
Attribute uint16
Attribute uint64
)

// This type represents a termbox event. The 'Mod', 'Key' and 'Ch' fields are
Expand Down Expand Up @@ -173,6 +173,7 @@ const (
Output256
Output216
OutputGrayscale
OutputRGB
)

// Event type. See Event.Type field.
Expand Down
48 changes: 48 additions & 0 deletions termbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ func write_sgr_fg(a Attribute) {
outbuf.WriteString("\033[38;5;")
outbuf.Write(strconv.AppendUint(intbuf, uint64(a-1), 10))
outbuf.WriteString("m")
case OutputRGB:
r, g, b := AttributeToRGB(a)
outbuf.WriteString(escapeRGB(false, r, g, b))
default:
outbuf.WriteString("\033[3")
outbuf.Write(strconv.AppendUint(intbuf, uint64(a-1), 10))
Expand All @@ -115,6 +118,9 @@ func write_sgr_bg(a Attribute) {
outbuf.WriteString("\033[48;5;")
outbuf.Write(strconv.AppendUint(intbuf, uint64(a-1), 10))
outbuf.WriteString("m")
case OutputRGB:
r, g, b := AttributeToRGB(a)
outbuf.WriteString(escapeRGB(false, r, g, b))
default:
outbuf.WriteString("\033[4")
outbuf.Write(strconv.AppendUint(intbuf, uint64(a-1), 10))
Expand All @@ -131,6 +137,11 @@ func write_sgr(fg, bg Attribute) {
outbuf.WriteString("\033[48;5;")
outbuf.Write(strconv.AppendUint(intbuf, uint64(bg-1), 10))
outbuf.WriteString("m")
case OutputRGB:
r, g, b := AttributeToRGB(fg)
outbuf.WriteString(escapeRGB(true, r, g, b))
r, g, b = AttributeToRGB(bg)
outbuf.WriteString(escapeRGB(false, r, g, b))
default:
outbuf.WriteString("\033[3")
outbuf.Write(strconv.AppendUint(intbuf, uint64(fg-1), 10))
Expand All @@ -140,6 +151,40 @@ func write_sgr(fg, bg Attribute) {
}
}

func escapeRGB(fg bool, r uint8, g uint8, b uint8) string {
var escape string = "\033["
if fg {
escape += "38"
} else {
escape += "48"
}
escape += ";2;"
escape += strconv.FormatUint(uint64(r), 10)
escape += ";"
escape += strconv.FormatUint(uint64(g), 10)
escape += ";"
escape += strconv.FormatUint(uint64(b), 10)
escape += "m"
return escape
}

func AttributeToRGB(attr Attribute) (uint8, uint8, uint8) {
var color uint64 = uint64(attr) / uint64(AttrReverse)
// Have to right-shift with the highest attribute bit
var b uint8 = uint8(color % 256)
var g uint8 = uint8(color >> 8 % 256)
var r uint8 = uint8(color >> 16 % 256)
return r, g, b
}

func RGBToAttribute(r uint8, g uint8, b uint8) Attribute {
var color uint64 = uint64(b)
color += uint64(g) << 8
color += uint64(r) << 16
color = color * uint64(AttrReverse)
return Attribute(color)
}

type winsize struct {
rows uint16
cols uint16
Expand Down Expand Up @@ -197,6 +242,9 @@ func send_attr(fg, bg Attribute) {
if bgcol != ColorDefault {
bgcol = grayscale[bgcol]
}
case OutputRGB:
fgcol = fg
bgcol = bg
default:
fgcol = fg & 0x0F
bgcol = bg & 0x0F
Expand Down