forked from TrueCloudLab/rclone
vendor: switch to using go1.11 modules
This commit is contained in:
parent
5c75453aba
commit
da1682a30e
6142 changed files with 390 additions and 5155875 deletions
300
vendor/github.com/nsf/termbox-go/_demos/editbox.go
generated
vendored
300
vendor/github.com/nsf/termbox-go/_demos/editbox.go
generated
vendored
|
@ -1,300 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattn/go-runewidth"
|
||||
"github.com/nsf/termbox-go"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
func tbprint(x, y int, fg, bg termbox.Attribute, msg string) {
|
||||
for _, c := range msg {
|
||||
termbox.SetCell(x, y, c, fg, bg)
|
||||
x += runewidth.RuneWidth(c)
|
||||
}
|
||||
}
|
||||
|
||||
func fill(x, y, w, h int, cell termbox.Cell) {
|
||||
for ly := 0; ly < h; ly++ {
|
||||
for lx := 0; lx < w; lx++ {
|
||||
termbox.SetCell(x+lx, y+ly, cell.Ch, cell.Fg, cell.Bg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func rune_advance_len(r rune, pos int) int {
|
||||
if r == '\t' {
|
||||
return tabstop_length - pos%tabstop_length
|
||||
}
|
||||
return runewidth.RuneWidth(r)
|
||||
}
|
||||
|
||||
func voffset_coffset(text []byte, boffset int) (voffset, coffset int) {
|
||||
text = text[:boffset]
|
||||
for len(text) > 0 {
|
||||
r, size := utf8.DecodeRune(text)
|
||||
text = text[size:]
|
||||
coffset += 1
|
||||
voffset += rune_advance_len(r, voffset)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func byte_slice_grow(s []byte, desired_cap int) []byte {
|
||||
if cap(s) < desired_cap {
|
||||
ns := make([]byte, len(s), desired_cap)
|
||||
copy(ns, s)
|
||||
return ns
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func byte_slice_remove(text []byte, from, to int) []byte {
|
||||
size := to - from
|
||||
copy(text[from:], text[to:])
|
||||
text = text[:len(text)-size]
|
||||
return text
|
||||
}
|
||||
|
||||
func byte_slice_insert(text []byte, offset int, what []byte) []byte {
|
||||
n := len(text) + len(what)
|
||||
text = byte_slice_grow(text, n)
|
||||
text = text[:n]
|
||||
copy(text[offset+len(what):], text[offset:])
|
||||
copy(text[offset:], what)
|
||||
return text
|
||||
}
|
||||
|
||||
const preferred_horizontal_threshold = 5
|
||||
const tabstop_length = 8
|
||||
|
||||
type EditBox struct {
|
||||
text []byte
|
||||
line_voffset int
|
||||
cursor_boffset int // cursor offset in bytes
|
||||
cursor_voffset int // visual cursor offset in termbox cells
|
||||
cursor_coffset int // cursor offset in unicode code points
|
||||
}
|
||||
|
||||
// Draws the EditBox in the given location, 'h' is not used at the moment
|
||||
func (eb *EditBox) Draw(x, y, w, h int) {
|
||||
eb.AdjustVOffset(w)
|
||||
|
||||
const coldef = termbox.ColorDefault
|
||||
fill(x, y, w, h, termbox.Cell{Ch: ' '})
|
||||
|
||||
t := eb.text
|
||||
lx := 0
|
||||
tabstop := 0
|
||||
for {
|
||||
rx := lx - eb.line_voffset
|
||||
if len(t) == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
if lx == tabstop {
|
||||
tabstop += tabstop_length
|
||||
}
|
||||
|
||||
if rx >= w {
|
||||
termbox.SetCell(x+w-1, y, '→',
|
||||
coldef, coldef)
|
||||
break
|
||||
}
|
||||
|
||||
r, size := utf8.DecodeRune(t)
|
||||
if r == '\t' {
|
||||
for ; lx < tabstop; lx++ {
|
||||
rx = lx - eb.line_voffset
|
||||
if rx >= w {
|
||||
goto next
|
||||
}
|
||||
|
||||
if rx >= 0 {
|
||||
termbox.SetCell(x+rx, y, ' ', coldef, coldef)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if rx >= 0 {
|
||||
termbox.SetCell(x+rx, y, r, coldef, coldef)
|
||||
}
|
||||
lx += runewidth.RuneWidth(r)
|
||||
}
|
||||
next:
|
||||
t = t[size:]
|
||||
}
|
||||
|
||||
if eb.line_voffset != 0 {
|
||||
termbox.SetCell(x, y, '←', coldef, coldef)
|
||||
}
|
||||
}
|
||||
|
||||
// Adjusts line visual offset to a proper value depending on width
|
||||
func (eb *EditBox) AdjustVOffset(width int) {
|
||||
ht := preferred_horizontal_threshold
|
||||
max_h_threshold := (width - 1) / 2
|
||||
if ht > max_h_threshold {
|
||||
ht = max_h_threshold
|
||||
}
|
||||
|
||||
threshold := width - 1
|
||||
if eb.line_voffset != 0 {
|
||||
threshold = width - ht
|
||||
}
|
||||
if eb.cursor_voffset-eb.line_voffset >= threshold {
|
||||
eb.line_voffset = eb.cursor_voffset + (ht - width + 1)
|
||||
}
|
||||
|
||||
if eb.line_voffset != 0 && eb.cursor_voffset-eb.line_voffset < ht {
|
||||
eb.line_voffset = eb.cursor_voffset - ht
|
||||
if eb.line_voffset < 0 {
|
||||
eb.line_voffset = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (eb *EditBox) MoveCursorTo(boffset int) {
|
||||
eb.cursor_boffset = boffset
|
||||
eb.cursor_voffset, eb.cursor_coffset = voffset_coffset(eb.text, boffset)
|
||||
}
|
||||
|
||||
func (eb *EditBox) RuneUnderCursor() (rune, int) {
|
||||
return utf8.DecodeRune(eb.text[eb.cursor_boffset:])
|
||||
}
|
||||
|
||||
func (eb *EditBox) RuneBeforeCursor() (rune, int) {
|
||||
return utf8.DecodeLastRune(eb.text[:eb.cursor_boffset])
|
||||
}
|
||||
|
||||
func (eb *EditBox) MoveCursorOneRuneBackward() {
|
||||
if eb.cursor_boffset == 0 {
|
||||
return
|
||||
}
|
||||
_, size := eb.RuneBeforeCursor()
|
||||
eb.MoveCursorTo(eb.cursor_boffset - size)
|
||||
}
|
||||
|
||||
func (eb *EditBox) MoveCursorOneRuneForward() {
|
||||
if eb.cursor_boffset == len(eb.text) {
|
||||
return
|
||||
}
|
||||
_, size := eb.RuneUnderCursor()
|
||||
eb.MoveCursorTo(eb.cursor_boffset + size)
|
||||
}
|
||||
|
||||
func (eb *EditBox) MoveCursorToBeginningOfTheLine() {
|
||||
eb.MoveCursorTo(0)
|
||||
}
|
||||
|
||||
func (eb *EditBox) MoveCursorToEndOfTheLine() {
|
||||
eb.MoveCursorTo(len(eb.text))
|
||||
}
|
||||
|
||||
func (eb *EditBox) DeleteRuneBackward() {
|
||||
if eb.cursor_boffset == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
eb.MoveCursorOneRuneBackward()
|
||||
_, size := eb.RuneUnderCursor()
|
||||
eb.text = byte_slice_remove(eb.text, eb.cursor_boffset, eb.cursor_boffset+size)
|
||||
}
|
||||
|
||||
func (eb *EditBox) DeleteRuneForward() {
|
||||
if eb.cursor_boffset == len(eb.text) {
|
||||
return
|
||||
}
|
||||
_, size := eb.RuneUnderCursor()
|
||||
eb.text = byte_slice_remove(eb.text, eb.cursor_boffset, eb.cursor_boffset+size)
|
||||
}
|
||||
|
||||
func (eb *EditBox) DeleteTheRestOfTheLine() {
|
||||
eb.text = eb.text[:eb.cursor_boffset]
|
||||
}
|
||||
|
||||
func (eb *EditBox) InsertRune(r rune) {
|
||||
var buf [utf8.UTFMax]byte
|
||||
n := utf8.EncodeRune(buf[:], r)
|
||||
eb.text = byte_slice_insert(eb.text, eb.cursor_boffset, buf[:n])
|
||||
eb.MoveCursorOneRuneForward()
|
||||
}
|
||||
|
||||
// Please, keep in mind that cursor depends on the value of line_voffset, which
|
||||
// is being set on Draw() call, so.. call this method after Draw() one.
|
||||
func (eb *EditBox) CursorX() int {
|
||||
return eb.cursor_voffset - eb.line_voffset
|
||||
}
|
||||
|
||||
var edit_box EditBox
|
||||
|
||||
const edit_box_width = 30
|
||||
|
||||
func redraw_all() {
|
||||
const coldef = termbox.ColorDefault
|
||||
termbox.Clear(coldef, coldef)
|
||||
w, h := termbox.Size()
|
||||
|
||||
midy := h / 2
|
||||
midx := (w - edit_box_width) / 2
|
||||
|
||||
// unicode box drawing chars around the edit box
|
||||
termbox.SetCell(midx-1, midy, '│', coldef, coldef)
|
||||
termbox.SetCell(midx+edit_box_width, midy, '│', coldef, coldef)
|
||||
termbox.SetCell(midx-1, midy-1, '┌', coldef, coldef)
|
||||
termbox.SetCell(midx-1, midy+1, '└', coldef, coldef)
|
||||
termbox.SetCell(midx+edit_box_width, midy-1, '┐', coldef, coldef)
|
||||
termbox.SetCell(midx+edit_box_width, midy+1, '┘', coldef, coldef)
|
||||
fill(midx, midy-1, edit_box_width, 1, termbox.Cell{Ch: '─'})
|
||||
fill(midx, midy+1, edit_box_width, 1, termbox.Cell{Ch: '─'})
|
||||
|
||||
edit_box.Draw(midx, midy, edit_box_width, 1)
|
||||
termbox.SetCursor(midx+edit_box.CursorX(), midy)
|
||||
|
||||
tbprint(midx+6, midy+3, coldef, coldef, "Press ESC to quit")
|
||||
termbox.Flush()
|
||||
}
|
||||
|
||||
func main() {
|
||||
err := termbox.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer termbox.Close()
|
||||
termbox.SetInputMode(termbox.InputEsc)
|
||||
|
||||
redraw_all()
|
||||
mainloop:
|
||||
for {
|
||||
switch ev := termbox.PollEvent(); ev.Type {
|
||||
case termbox.EventKey:
|
||||
switch ev.Key {
|
||||
case termbox.KeyEsc:
|
||||
break mainloop
|
||||
case termbox.KeyArrowLeft, termbox.KeyCtrlB:
|
||||
edit_box.MoveCursorOneRuneBackward()
|
||||
case termbox.KeyArrowRight, termbox.KeyCtrlF:
|
||||
edit_box.MoveCursorOneRuneForward()
|
||||
case termbox.KeyBackspace, termbox.KeyBackspace2:
|
||||
edit_box.DeleteRuneBackward()
|
||||
case termbox.KeyDelete, termbox.KeyCtrlD:
|
||||
edit_box.DeleteRuneForward()
|
||||
case termbox.KeyTab:
|
||||
edit_box.InsertRune('\t')
|
||||
case termbox.KeySpace:
|
||||
edit_box.InsertRune(' ')
|
||||
case termbox.KeyCtrlK:
|
||||
edit_box.DeleteTheRestOfTheLine()
|
||||
case termbox.KeyHome, termbox.KeyCtrlA:
|
||||
edit_box.MoveCursorToBeginningOfTheLine()
|
||||
case termbox.KeyEnd, termbox.KeyCtrlE:
|
||||
edit_box.MoveCursorToEndOfTheLine()
|
||||
default:
|
||||
if ev.Ch != 0 {
|
||||
edit_box.InsertRune(ev.Ch)
|
||||
}
|
||||
}
|
||||
case termbox.EventError:
|
||||
panic(ev.Err)
|
||||
}
|
||||
redraw_all()
|
||||
}
|
||||
}
|
69
vendor/github.com/nsf/termbox-go/_demos/interrupt.go
generated
vendored
69
vendor/github.com/nsf/termbox-go/_demos/interrupt.go
generated
vendored
|
@ -1,69 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/nsf/termbox-go"
|
||||
"time"
|
||||
)
|
||||
|
||||
func tbPrint(x, y int, fg, bg termbox.Attribute, msg string) {
|
||||
for _, c := range msg {
|
||||
termbox.SetCell(x, y, c, fg, bg)
|
||||
x++
|
||||
}
|
||||
}
|
||||
|
||||
func draw(i int) {
|
||||
termbox.Clear(termbox.ColorDefault, termbox.ColorDefault)
|
||||
defer termbox.Flush()
|
||||
|
||||
w, h := termbox.Size()
|
||||
s := fmt.Sprintf("count = %d", i)
|
||||
|
||||
tbPrint((w/2)-(len(s)/2), h/2, termbox.ColorRed, termbox.ColorDefault, s)
|
||||
}
|
||||
|
||||
func main() {
|
||||
err := termbox.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
termbox.SetInputMode(termbox.InputEsc)
|
||||
|
||||
go func() {
|
||||
time.Sleep(5 * time.Second)
|
||||
termbox.Interrupt()
|
||||
|
||||
// This should never run - the Interrupt(), above, should cause the event
|
||||
// loop below to exit, which then exits the process. If something goes
|
||||
// wrong, this panic will trigger and show what happened.
|
||||
time.Sleep(1 * time.Second)
|
||||
panic("this should never run")
|
||||
}()
|
||||
|
||||
var count int
|
||||
|
||||
draw(count)
|
||||
mainloop:
|
||||
for {
|
||||
switch ev := termbox.PollEvent(); ev.Type {
|
||||
case termbox.EventKey:
|
||||
if ev.Ch == '+' {
|
||||
count++
|
||||
} else if ev.Ch == '-' {
|
||||
count--
|
||||
}
|
||||
|
||||
case termbox.EventError:
|
||||
panic(ev.Err)
|
||||
|
||||
case termbox.EventInterrupt:
|
||||
break mainloop
|
||||
}
|
||||
|
||||
draw(count)
|
||||
}
|
||||
termbox.Close()
|
||||
|
||||
fmt.Println("Finished")
|
||||
}
|
722
vendor/github.com/nsf/termbox-go/_demos/keyboard.go
generated
vendored
722
vendor/github.com/nsf/termbox-go/_demos/keyboard.go
generated
vendored
|
@ -1,722 +0,0 @@
|
|||
package main
|
||||
|
||||
import "github.com/nsf/termbox-go"
|
||||
import "fmt"
|
||||
|
||||
type key struct {
|
||||
x int
|
||||
y int
|
||||
ch rune
|
||||
}
|
||||
|
||||
var K_ESC = []key{{1, 1, 'E'}, {2, 1, 'S'}, {3, 1, 'C'}}
|
||||
var K_F1 = []key{{6, 1, 'F'}, {7, 1, '1'}}
|
||||
var K_F2 = []key{{9, 1, 'F'}, {10, 1, '2'}}
|
||||
var K_F3 = []key{{12, 1, 'F'}, {13, 1, '3'}}
|
||||
var K_F4 = []key{{15, 1, 'F'}, {16, 1, '4'}}
|
||||
var K_F5 = []key{{19, 1, 'F'}, {20, 1, '5'}}
|
||||
var K_F6 = []key{{22, 1, 'F'}, {23, 1, '6'}}
|
||||
var K_F7 = []key{{25, 1, 'F'}, {26, 1, '7'}}
|
||||
var K_F8 = []key{{28, 1, 'F'}, {29, 1, '8'}}
|
||||
var K_F9 = []key{{33, 1, 'F'}, {34, 1, '9'}}
|
||||
var K_F10 = []key{{36, 1, 'F'}, {37, 1, '1'}, {38, 1, '0'}}
|
||||
var K_F11 = []key{{40, 1, 'F'}, {41, 1, '1'}, {42, 1, '1'}}
|
||||
var K_F12 = []key{{44, 1, 'F'}, {45, 1, '1'}, {46, 1, '2'}}
|
||||
var K_PRN = []key{{50, 1, 'P'}, {51, 1, 'R'}, {52, 1, 'N'}}
|
||||
var K_SCR = []key{{54, 1, 'S'}, {55, 1, 'C'}, {56, 1, 'R'}}
|
||||
var K_BRK = []key{{58, 1, 'B'}, {59, 1, 'R'}, {60, 1, 'K'}}
|
||||
var K_LED1 = []key{{66, 1, '-'}}
|
||||
var K_LED2 = []key{{70, 1, '-'}}
|
||||
var K_LED3 = []key{{74, 1, '-'}}
|
||||
var K_TILDE = []key{{1, 4, '`'}}
|
||||
var K_TILDE_SHIFT = []key{{1, 4, '~'}}
|
||||
var K_1 = []key{{4, 4, '1'}}
|
||||
var K_1_SHIFT = []key{{4, 4, '!'}}
|
||||
var K_2 = []key{{7, 4, '2'}}
|
||||
var K_2_SHIFT = []key{{7, 4, '@'}}
|
||||
var K_3 = []key{{10, 4, '3'}}
|
||||
var K_3_SHIFT = []key{{10, 4, '#'}}
|
||||
var K_4 = []key{{13, 4, '4'}}
|
||||
var K_4_SHIFT = []key{{13, 4, '$'}}
|
||||
var K_5 = []key{{16, 4, '5'}}
|
||||
var K_5_SHIFT = []key{{16, 4, '%'}}
|
||||
var K_6 = []key{{19, 4, '6'}}
|
||||
var K_6_SHIFT = []key{{19, 4, '^'}}
|
||||
var K_7 = []key{{22, 4, '7'}}
|
||||
var K_7_SHIFT = []key{{22, 4, '&'}}
|
||||
var K_8 = []key{{25, 4, '8'}}
|
||||
var K_8_SHIFT = []key{{25, 4, '*'}}
|
||||
var K_9 = []key{{28, 4, '9'}}
|
||||
var K_9_SHIFT = []key{{28, 4, '('}}
|
||||
var K_0 = []key{{31, 4, '0'}}
|
||||
var K_0_SHIFT = []key{{31, 4, ')'}}
|
||||
var K_MINUS = []key{{34, 4, '-'}}
|
||||
var K_MINUS_SHIFT = []key{{34, 4, '_'}}
|
||||
var K_EQUALS = []key{{37, 4, '='}}
|
||||
var K_EQUALS_SHIFT = []key{{37, 4, '+'}}
|
||||
var K_BACKSLASH = []key{{40, 4, '\\'}}
|
||||
var K_BACKSLASH_SHIFT = []key{{40, 4, '|'}}
|
||||
var K_BACKSPACE = []key{{44, 4, 0x2190}, {45, 4, 0x2500}, {46, 4, 0x2500}}
|
||||
var K_INS = []key{{50, 4, 'I'}, {51, 4, 'N'}, {52, 4, 'S'}}
|
||||
var K_HOM = []key{{54, 4, 'H'}, {55, 4, 'O'}, {56, 4, 'M'}}
|
||||
var K_PGU = []key{{58, 4, 'P'}, {59, 4, 'G'}, {60, 4, 'U'}}
|
||||
var K_K_NUMLOCK = []key{{65, 4, 'N'}}
|
||||
var K_K_SLASH = []key{{68, 4, '/'}}
|
||||
var K_K_STAR = []key{{71, 4, '*'}}
|
||||
var K_K_MINUS = []key{{74, 4, '-'}}
|
||||
var K_TAB = []key{{1, 6, 'T'}, {2, 6, 'A'}, {3, 6, 'B'}}
|
||||
var K_q = []key{{6, 6, 'q'}}
|
||||
var K_Q = []key{{6, 6, 'Q'}}
|
||||
var K_w = []key{{9, 6, 'w'}}
|
||||
var K_W = []key{{9, 6, 'W'}}
|
||||
var K_e = []key{{12, 6, 'e'}}
|
||||
var K_E = []key{{12, 6, 'E'}}
|
||||
var K_r = []key{{15, 6, 'r'}}
|
||||
var K_R = []key{{15, 6, 'R'}}
|
||||
var K_t = []key{{18, 6, 't'}}
|
||||
var K_T = []key{{18, 6, 'T'}}
|
||||
var K_y = []key{{21, 6, 'y'}}
|
||||
var K_Y = []key{{21, 6, 'Y'}}
|
||||
var K_u = []key{{24, 6, 'u'}}
|
||||
var K_U = []key{{24, 6, 'U'}}
|
||||
var K_i = []key{{27, 6, 'i'}}
|
||||
var K_I = []key{{27, 6, 'I'}}
|
||||
var K_o = []key{{30, 6, 'o'}}
|
||||
var K_O = []key{{30, 6, 'O'}}
|
||||
var K_p = []key{{33, 6, 'p'}}
|
||||
var K_P = []key{{33, 6, 'P'}}
|
||||
var K_LSQB = []key{{36, 6, '['}}
|
||||
var K_LCUB = []key{{36, 6, '{'}}
|
||||
var K_RSQB = []key{{39, 6, ']'}}
|
||||
var K_RCUB = []key{{39, 6, '}'}}
|
||||
var K_ENTER = []key{
|
||||
{43, 6, 0x2591}, {44, 6, 0x2591}, {45, 6, 0x2591}, {46, 6, 0x2591},
|
||||
{43, 7, 0x2591}, {44, 7, 0x2591}, {45, 7, 0x21B5}, {46, 7, 0x2591},
|
||||
{41, 8, 0x2591}, {42, 8, 0x2591}, {43, 8, 0x2591}, {44, 8, 0x2591},
|
||||
{45, 8, 0x2591}, {46, 8, 0x2591},
|
||||
}
|
||||
var K_DEL = []key{{50, 6, 'D'}, {51, 6, 'E'}, {52, 6, 'L'}}
|
||||
var K_END = []key{{54, 6, 'E'}, {55, 6, 'N'}, {56, 6, 'D'}}
|
||||
var K_PGD = []key{{58, 6, 'P'}, {59, 6, 'G'}, {60, 6, 'D'}}
|
||||
var K_K_7 = []key{{65, 6, '7'}}
|
||||
var K_K_8 = []key{{68, 6, '8'}}
|
||||
var K_K_9 = []key{{71, 6, '9'}}
|
||||
var K_K_PLUS = []key{{74, 6, ' '}, {74, 7, '+'}, {74, 8, ' '}}
|
||||
var K_CAPS = []key{{1, 8, 'C'}, {2, 8, 'A'}, {3, 8, 'P'}, {4, 8, 'S'}}
|
||||
var K_a = []key{{7, 8, 'a'}}
|
||||
var K_A = []key{{7, 8, 'A'}}
|
||||
var K_s = []key{{10, 8, 's'}}
|
||||
var K_S = []key{{10, 8, 'S'}}
|
||||
var K_d = []key{{13, 8, 'd'}}
|
||||
var K_D = []key{{13, 8, 'D'}}
|
||||
var K_f = []key{{16, 8, 'f'}}
|
||||
var K_F = []key{{16, 8, 'F'}}
|
||||
var K_g = []key{{19, 8, 'g'}}
|
||||
var K_G = []key{{19, 8, 'G'}}
|
||||
var K_h = []key{{22, 8, 'h'}}
|
||||
var K_H = []key{{22, 8, 'H'}}
|
||||
var K_j = []key{{25, 8, 'j'}}
|
||||
var K_J = []key{{25, 8, 'J'}}
|
||||
var K_k = []key{{28, 8, 'k'}}
|
||||
var K_K = []key{{28, 8, 'K'}}
|
||||
var K_l = []key{{31, 8, 'l'}}
|
||||
var K_L = []key{{31, 8, 'L'}}
|
||||
var K_SEMICOLON = []key{{34, 8, ';'}}
|
||||
var K_PARENTHESIS = []key{{34, 8, ':'}}
|
||||
var K_QUOTE = []key{{37, 8, '\''}}
|
||||
var K_DOUBLEQUOTE = []key{{37, 8, '"'}}
|
||||
var K_K_4 = []key{{65, 8, '4'}}
|
||||
var K_K_5 = []key{{68, 8, '5'}}
|
||||
var K_K_6 = []key{{71, 8, '6'}}
|
||||
var K_LSHIFT = []key{{1, 10, 'S'}, {2, 10, 'H'}, {3, 10, 'I'}, {4, 10, 'F'}, {5, 10, 'T'}}
|
||||
var K_z = []key{{9, 10, 'z'}}
|
||||
var K_Z = []key{{9, 10, 'Z'}}
|
||||
var K_x = []key{{12, 10, 'x'}}
|
||||
var K_X = []key{{12, 10, 'X'}}
|
||||
var K_c = []key{{15, 10, 'c'}}
|
||||
var K_C = []key{{15, 10, 'C'}}
|
||||
var K_v = []key{{18, 10, 'v'}}
|
||||
var K_V = []key{{18, 10, 'V'}}
|
||||
var K_b = []key{{21, 10, 'b'}}
|
||||
var K_B = []key{{21, 10, 'B'}}
|
||||
var K_n = []key{{24, 10, 'n'}}
|
||||
var K_N = []key{{24, 10, 'N'}}
|
||||
var K_m = []key{{27, 10, 'm'}}
|
||||
var K_M = []key{{27, 10, 'M'}}
|
||||
var K_COMMA = []key{{30, 10, ','}}
|
||||
var K_LANB = []key{{30, 10, '<'}}
|
||||
var K_PERIOD = []key{{33, 10, '.'}}
|
||||
var K_RANB = []key{{33, 10, '>'}}
|
||||
var K_SLASH = []key{{36, 10, '/'}}
|
||||
var K_QUESTION = []key{{36, 10, '?'}}
|
||||
var K_RSHIFT = []key{{42, 10, 'S'}, {43, 10, 'H'}, {44, 10, 'I'}, {45, 10, 'F'}, {46, 10, 'T'}}
|
||||
var K_ARROW_UP = []key{{54, 10, '('}, {55, 10, 0x2191}, {56, 10, ')'}}
|
||||
var K_K_1 = []key{{65, 10, '1'}}
|
||||
var K_K_2 = []key{{68, 10, '2'}}
|
||||
var K_K_3 = []key{{71, 10, '3'}}
|
||||
var K_K_ENTER = []key{{74, 10, 0x2591}, {74, 11, 0x2591}, {74, 12, 0x2591}}
|
||||
var K_LCTRL = []key{{1, 12, 'C'}, {2, 12, 'T'}, {3, 12, 'R'}, {4, 12, 'L'}}
|
||||
var K_LWIN = []key{{6, 12, 'W'}, {7, 12, 'I'}, {8, 12, 'N'}}
|
||||
var K_LALT = []key{{10, 12, 'A'}, {11, 12, 'L'}, {12, 12, 'T'}}
|
||||
var K_SPACE = []key{
|
||||
{14, 12, ' '}, {15, 12, ' '}, {16, 12, ' '}, {17, 12, ' '}, {18, 12, ' '},
|
||||
{19, 12, 'S'}, {20, 12, 'P'}, {21, 12, 'A'}, {22, 12, 'C'}, {23, 12, 'E'},
|
||||
{24, 12, ' '}, {25, 12, ' '}, {26, 12, ' '}, {27, 12, ' '}, {28, 12, ' '},
|
||||
}
|
||||
var K_RALT = []key{{30, 12, 'A'}, {31, 12, 'L'}, {32, 12, 'T'}}
|
||||
var K_RWIN = []key{{34, 12, 'W'}, {35, 12, 'I'}, {36, 12, 'N'}}
|
||||
var K_RPROP = []key{{38, 12, 'P'}, {39, 12, 'R'}, {40, 12, 'O'}, {41, 12, 'P'}}
|
||||
var K_RCTRL = []key{{43, 12, 'C'}, {44, 12, 'T'}, {45, 12, 'R'}, {46, 12, 'L'}}
|
||||
var K_ARROW_LEFT = []key{{50, 12, '('}, {51, 12, 0x2190}, {52, 12, ')'}}
|
||||
var K_ARROW_DOWN = []key{{54, 12, '('}, {55, 12, 0x2193}, {56, 12, ')'}}
|
||||
var K_ARROW_RIGHT = []key{{58, 12, '('}, {59, 12, 0x2192}, {60, 12, ')'}}
|
||||
var K_K_0 = []key{{65, 12, ' '}, {66, 12, '0'}, {67, 12, ' '}, {68, 12, ' '}}
|
||||
var K_K_PERIOD = []key{{71, 12, '.'}}
|
||||
|
||||
type combo struct {
|
||||
keys [][]key
|
||||
}
|
||||
|
||||
var combos = []combo{
|
||||
{[][]key{K_TILDE, K_2, K_SPACE, K_LCTRL, K_RCTRL}},
|
||||
{[][]key{K_A, K_LCTRL, K_RCTRL}},
|
||||
{[][]key{K_B, K_LCTRL, K_RCTRL}},
|
||||
{[][]key{K_C, K_LCTRL, K_RCTRL}},
|
||||
{[][]key{K_D, K_LCTRL, K_RCTRL}},
|
||||
{[][]key{K_E, K_LCTRL, K_RCTRL}},
|
||||
{[][]key{K_F, K_LCTRL, K_RCTRL}},
|
||||
{[][]key{K_G, K_LCTRL, K_RCTRL}},
|
||||
{[][]key{K_H, K_BACKSPACE, K_LCTRL, K_RCTRL}},
|
||||
{[][]key{K_I, K_TAB, K_LCTRL, K_RCTRL}},
|
||||
{[][]key{K_J, K_LCTRL, K_RCTRL}},
|
||||
{[][]key{K_K, K_LCTRL, K_RCTRL}},
|
||||
{[][]key{K_L, K_LCTRL, K_RCTRL}},
|
||||
{[][]key{K_M, K_ENTER, K_K_ENTER, K_LCTRL, K_RCTRL}},
|
||||
{[][]key{K_N, K_LCTRL, K_RCTRL}},
|
||||
{[][]key{K_O, K_LCTRL, K_RCTRL}},
|
||||
{[][]key{K_P, K_LCTRL, K_RCTRL}},
|
||||
{[][]key{K_Q, K_LCTRL, K_RCTRL}},
|
||||
{[][]key{K_R, K_LCTRL, K_RCTRL}},
|
||||
{[][]key{K_S, K_LCTRL, K_RCTRL}},
|
||||
{[][]key{K_T, K_LCTRL, K_RCTRL}},
|
||||
{[][]key{K_U, K_LCTRL, K_RCTRL}},
|
||||
{[][]key{K_V, K_LCTRL, K_RCTRL}},
|
||||
{[][]key{K_W, K_LCTRL, K_RCTRL}},
|
||||
{[][]key{K_X, K_LCTRL, K_RCTRL}},
|
||||
{[][]key{K_Y, K_LCTRL, K_RCTRL}},
|
||||
{[][]key{K_Z, K_LCTRL, K_RCTRL}},
|
||||
{[][]key{K_LSQB, K_ESC, K_3, K_LCTRL, K_RCTRL}},
|
||||
{[][]key{K_4, K_BACKSLASH, K_LCTRL, K_RCTRL}},
|
||||
{[][]key{K_RSQB, K_5, K_LCTRL, K_RCTRL}},
|
||||
{[][]key{K_6, K_LCTRL, K_RCTRL}},
|
||||
{[][]key{K_7, K_SLASH, K_MINUS_SHIFT, K_LCTRL, K_RCTRL}},
|
||||
{[][]key{K_SPACE}},
|
||||
{[][]key{K_1_SHIFT, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_DOUBLEQUOTE, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_3_SHIFT, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_4_SHIFT, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_5_SHIFT, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_7_SHIFT, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_QUOTE}},
|
||||
{[][]key{K_9_SHIFT, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_0_SHIFT, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_8_SHIFT, K_K_STAR, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_EQUALS_SHIFT, K_K_PLUS, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_COMMA}},
|
||||
{[][]key{K_MINUS, K_K_MINUS}},
|
||||
{[][]key{K_PERIOD, K_K_PERIOD}},
|
||||
{[][]key{K_SLASH, K_K_SLASH}},
|
||||
{[][]key{K_0, K_K_0}},
|
||||
{[][]key{K_1, K_K_1}},
|
||||
{[][]key{K_2, K_K_2}},
|
||||
{[][]key{K_3, K_K_3}},
|
||||
{[][]key{K_4, K_K_4}},
|
||||
{[][]key{K_5, K_K_5}},
|
||||
{[][]key{K_6, K_K_6}},
|
||||
{[][]key{K_7, K_K_7}},
|
||||
{[][]key{K_8, K_K_8}},
|
||||
{[][]key{K_9, K_K_9}},
|
||||
{[][]key{K_PARENTHESIS, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_SEMICOLON}},
|
||||
{[][]key{K_LANB, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_EQUALS}},
|
||||
{[][]key{K_RANB, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_QUESTION, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_2_SHIFT, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_A, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_B, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_C, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_D, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_E, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_F, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_G, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_H, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_I, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_J, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_K, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_L, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_M, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_N, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_O, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_P, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_Q, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_R, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_S, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_T, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_U, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_V, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_W, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_X, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_Y, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_Z, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_LSQB}},
|
||||
{[][]key{K_BACKSLASH}},
|
||||
{[][]key{K_RSQB}},
|
||||
{[][]key{K_6_SHIFT, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_MINUS_SHIFT, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_TILDE}},
|
||||
{[][]key{K_a}},
|
||||
{[][]key{K_b}},
|
||||
{[][]key{K_c}},
|
||||
{[][]key{K_d}},
|
||||
{[][]key{K_e}},
|
||||
{[][]key{K_f}},
|
||||
{[][]key{K_g}},
|
||||
{[][]key{K_h}},
|
||||
{[][]key{K_i}},
|
||||
{[][]key{K_j}},
|
||||
{[][]key{K_k}},
|
||||
{[][]key{K_l}},
|
||||
{[][]key{K_m}},
|
||||
{[][]key{K_n}},
|
||||
{[][]key{K_o}},
|
||||
{[][]key{K_p}},
|
||||
{[][]key{K_q}},
|
||||
{[][]key{K_r}},
|
||||
{[][]key{K_s}},
|
||||
{[][]key{K_t}},
|
||||
{[][]key{K_u}},
|
||||
{[][]key{K_v}},
|
||||
{[][]key{K_w}},
|
||||
{[][]key{K_x}},
|
||||
{[][]key{K_y}},
|
||||
{[][]key{K_z}},
|
||||
{[][]key{K_LCUB, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_BACKSLASH_SHIFT, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_RCUB, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_TILDE_SHIFT, K_LSHIFT, K_RSHIFT}},
|
||||
{[][]key{K_8, K_BACKSPACE, K_LCTRL, K_RCTRL}},
|
||||
}
|
||||
|
||||
var func_combos = []combo{
|
||||
{[][]key{K_F1}},
|
||||
{[][]key{K_F2}},
|
||||
{[][]key{K_F3}},
|
||||
{[][]key{K_F4}},
|
||||
{[][]key{K_F5}},
|
||||
{[][]key{K_F6}},
|
||||
{[][]key{K_F7}},
|
||||
{[][]key{K_F8}},
|
||||
{[][]key{K_F9}},
|
||||
{[][]key{K_F10}},
|
||||
{[][]key{K_F11}},
|
||||
{[][]key{K_F12}},
|
||||
{[][]key{K_INS}},
|
||||
{[][]key{K_DEL}},
|
||||
{[][]key{K_HOM}},
|
||||
{[][]key{K_END}},
|
||||
{[][]key{K_PGU}},
|
||||
{[][]key{K_PGD}},
|
||||
{[][]key{K_ARROW_UP}},
|
||||
{[][]key{K_ARROW_DOWN}},
|
||||
{[][]key{K_ARROW_LEFT}},
|
||||
{[][]key{K_ARROW_RIGHT}},
|
||||
}
|
||||
|
||||
func print_tb(x, y int, fg, bg termbox.Attribute, msg string) {
|
||||
for _, c := range msg {
|
||||
termbox.SetCell(x, y, c, fg, bg)
|
||||
x++
|
||||
}
|
||||
}
|
||||
|
||||
func printf_tb(x, y int, fg, bg termbox.Attribute, format string, args ...interface{}) {
|
||||
s := fmt.Sprintf(format, args...)
|
||||
print_tb(x, y, fg, bg, s)
|
||||
}
|
||||
|
||||
func draw_key(k []key, fg, bg termbox.Attribute) {
|
||||
for _, k := range k {
|
||||
termbox.SetCell(k.x+2, k.y+4, k.ch, fg, bg)
|
||||
}
|
||||
}
|
||||
|
||||
func draw_keyboard() {
|
||||
termbox.SetCell(0, 0, 0x250C, termbox.ColorWhite, termbox.ColorBlack)
|
||||
termbox.SetCell(79, 0, 0x2510, termbox.ColorWhite, termbox.ColorBlack)
|
||||
termbox.SetCell(0, 23, 0x2514, termbox.ColorWhite, termbox.ColorBlack)
|
||||
termbox.SetCell(79, 23, 0x2518, termbox.ColorWhite, termbox.ColorBlack)
|
||||
|
||||
for i := 1; i < 79; i++ {
|
||||
termbox.SetCell(i, 0, 0x2500, termbox.ColorWhite, termbox.ColorBlack)
|
||||
termbox.SetCell(i, 23, 0x2500, termbox.ColorWhite, termbox.ColorBlack)
|
||||
termbox.SetCell(i, 17, 0x2500, termbox.ColorWhite, termbox.ColorBlack)
|
||||
termbox.SetCell(i, 4, 0x2500, termbox.ColorWhite, termbox.ColorBlack)
|
||||
}
|
||||
for i := 1; i < 23; i++ {
|
||||
termbox.SetCell(0, i, 0x2502, termbox.ColorWhite, termbox.ColorBlack)
|
||||
termbox.SetCell(79, i, 0x2502, termbox.ColorWhite, termbox.ColorBlack)
|
||||
}
|
||||
termbox.SetCell(0, 17, 0x251C, termbox.ColorWhite, termbox.ColorBlack)
|
||||
termbox.SetCell(79, 17, 0x2524, termbox.ColorWhite, termbox.ColorBlack)
|
||||
termbox.SetCell(0, 4, 0x251C, termbox.ColorWhite, termbox.ColorBlack)
|
||||
termbox.SetCell(79, 4, 0x2524, termbox.ColorWhite, termbox.ColorBlack)
|
||||
for i := 5; i < 17; i++ {
|
||||
termbox.SetCell(1, i, 0x2588, termbox.ColorYellow, termbox.ColorYellow)
|
||||
termbox.SetCell(78, i, 0x2588, termbox.ColorYellow, termbox.ColorYellow)
|
||||
}
|
||||
|
||||
draw_key(K_ESC, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_F1, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_F2, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_F3, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_F4, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_F5, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_F6, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_F7, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_F8, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_F9, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_F10, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_F11, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_F12, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_PRN, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_SCR, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_BRK, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_LED1, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_LED2, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_LED3, termbox.ColorWhite, termbox.ColorBlue)
|
||||
|
||||
draw_key(K_TILDE, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_1, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_2, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_3, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_4, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_5, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_6, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_7, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_8, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_9, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_0, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_MINUS, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_EQUALS, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_BACKSLASH, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_BACKSPACE, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_INS, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_HOM, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_PGU, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_K_NUMLOCK, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_K_SLASH, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_K_STAR, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_K_MINUS, termbox.ColorWhite, termbox.ColorBlue)
|
||||
|
||||
draw_key(K_TAB, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_q, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_w, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_e, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_r, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_t, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_y, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_u, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_i, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_o, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_p, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_LSQB, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_RSQB, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_ENTER, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_DEL, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_END, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_PGD, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_K_7, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_K_8, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_K_9, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_K_PLUS, termbox.ColorWhite, termbox.ColorBlue)
|
||||
|
||||
draw_key(K_CAPS, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_a, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_s, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_d, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_f, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_g, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_h, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_j, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_k, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_l, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_SEMICOLON, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_QUOTE, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_K_4, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_K_5, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_K_6, termbox.ColorWhite, termbox.ColorBlue)
|
||||
|
||||
draw_key(K_LSHIFT, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_z, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_x, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_c, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_v, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_b, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_n, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_m, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_COMMA, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_PERIOD, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_SLASH, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_RSHIFT, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_ARROW_UP, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_K_1, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_K_2, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_K_3, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_K_ENTER, termbox.ColorWhite, termbox.ColorBlue)
|
||||
|
||||
draw_key(K_LCTRL, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_LWIN, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_LALT, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_SPACE, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_RCTRL, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_RPROP, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_RWIN, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_RALT, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_ARROW_LEFT, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_ARROW_DOWN, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_ARROW_RIGHT, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_K_0, termbox.ColorWhite, termbox.ColorBlue)
|
||||
draw_key(K_K_PERIOD, termbox.ColorWhite, termbox.ColorBlue)
|
||||
|
||||
printf_tb(33, 1, termbox.ColorMagenta|termbox.AttrBold, termbox.ColorBlack, "Keyboard demo!")
|
||||
printf_tb(21, 2, termbox.ColorMagenta, termbox.ColorBlack, "(press CTRL+X and then CTRL+Q to exit)")
|
||||
printf_tb(15, 3, termbox.ColorMagenta, termbox.ColorBlack, "(press CTRL+X and then CTRL+C to change input mode)")
|
||||
|
||||
inputmode := termbox.SetInputMode(termbox.InputCurrent)
|
||||
inputmode_str := ""
|
||||
switch {
|
||||
case inputmode&termbox.InputEsc != 0:
|
||||
inputmode_str = "termbox.InputEsc"
|
||||
case inputmode&termbox.InputAlt != 0:
|
||||
inputmode_str = "termbox.InputAlt"
|
||||
}
|
||||
|
||||
if inputmode&termbox.InputMouse != 0 {
|
||||
inputmode_str += " | termbox.InputMouse"
|
||||
}
|
||||
printf_tb(3, 18, termbox.ColorWhite, termbox.ColorBlack, "Input mode: %s", inputmode_str)
|
||||
}
|
||||
|
||||
var fcmap = []string{
|
||||
"CTRL+2, CTRL+~",
|
||||
"CTRL+A",
|
||||
"CTRL+B",
|
||||
"CTRL+C",
|
||||
"CTRL+D",
|
||||
"CTRL+E",
|
||||
"CTRL+F",
|
||||
"CTRL+G",
|
||||
"CTRL+H, BACKSPACE",
|
||||
"CTRL+I, TAB",
|
||||
"CTRL+J",
|
||||
"CTRL+K",
|
||||
"CTRL+L",
|
||||
"CTRL+M, ENTER",
|
||||
"CTRL+N",
|
||||
"CTRL+O",
|
||||
"CTRL+P",
|
||||
"CTRL+Q",
|
||||
"CTRL+R",
|
||||
"CTRL+S",
|
||||
"CTRL+T",
|
||||
"CTRL+U",
|
||||
"CTRL+V",
|
||||
"CTRL+W",
|
||||
"CTRL+X",
|
||||
"CTRL+Y",
|
||||
"CTRL+Z",
|
||||
"CTRL+3, ESC, CTRL+[",
|
||||
"CTRL+4, CTRL+\\",
|
||||
"CTRL+5, CTRL+]",
|
||||
"CTRL+6",
|
||||
"CTRL+7, CTRL+/, CTRL+_",
|
||||
"SPACE",
|
||||
}
|
||||
|
||||
var fkmap = []string{
|
||||
"F1",
|
||||
"F2",
|
||||
"F3",
|
||||
"F4",
|
||||
"F5",
|
||||
"F6",
|
||||
"F7",
|
||||
"F8",
|
||||
"F9",
|
||||
"F10",
|
||||
"F11",
|
||||
"F12",
|
||||
"INSERT",
|
||||
"DELETE",
|
||||
"HOME",
|
||||
"END",
|
||||
"PGUP",
|
||||
"PGDN",
|
||||
"ARROW UP",
|
||||
"ARROW DOWN",
|
||||
"ARROW LEFT",
|
||||
"ARROW RIGHT",
|
||||
}
|
||||
|
||||
func funckeymap(k termbox.Key) string {
|
||||
if k == termbox.KeyCtrl8 {
|
||||
return "CTRL+8, BACKSPACE 2" /* 0x7F */
|
||||
} else if k >= termbox.KeyArrowRight && k <= 0xFFFF {
|
||||
return fkmap[0xFFFF-k]
|
||||
} else if k <= termbox.KeySpace {
|
||||
return fcmap[k]
|
||||
}
|
||||
return "UNKNOWN"
|
||||
}
|
||||
|
||||
func pretty_print_press(ev *termbox.Event) {
|
||||
printf_tb(3, 19, termbox.ColorWhite, termbox.ColorBlack, "Key: ")
|
||||
printf_tb(8, 19, termbox.ColorYellow, termbox.ColorBlack, "decimal: %d", ev.Key)
|
||||
printf_tb(8, 20, termbox.ColorGreen, termbox.ColorBlack, "hex: 0x%X", ev.Key)
|
||||
printf_tb(8, 21, termbox.ColorCyan, termbox.ColorBlack, "octal: 0%o", ev.Key)
|
||||
printf_tb(8, 22, termbox.ColorRed, termbox.ColorBlack, "string: %s", funckeymap(ev.Key))
|
||||
|
||||
printf_tb(54, 19, termbox.ColorWhite, termbox.ColorBlack, "Char: ")
|
||||
printf_tb(60, 19, termbox.ColorYellow, termbox.ColorBlack, "decimal: %d", ev.Ch)
|
||||
printf_tb(60, 20, termbox.ColorGreen, termbox.ColorBlack, "hex: 0x%X", ev.Ch)
|
||||
printf_tb(60, 21, termbox.ColorCyan, termbox.ColorBlack, "octal: 0%o", ev.Ch)
|
||||
printf_tb(60, 22, termbox.ColorRed, termbox.ColorBlack, "string: %s", string(ev.Ch))
|
||||
|
||||
modifier := "none"
|
||||
if ev.Mod != 0 {
|
||||
modifier = "termbox.ModAlt"
|
||||
}
|
||||
printf_tb(54, 18, termbox.ColorWhite, termbox.ColorBlack, "Modifier: %s", modifier)
|
||||
}
|
||||
|
||||
func pretty_print_resize(ev *termbox.Event) {
|
||||
printf_tb(3, 19, termbox.ColorWhite, termbox.ColorBlack, "Resize event: %d x %d", ev.Width, ev.Height)
|
||||
}
|
||||
|
||||
var counter = 0
|
||||
|
||||
func pretty_print_mouse(ev *termbox.Event) {
|
||||
printf_tb(3, 19, termbox.ColorWhite, termbox.ColorBlack, "Mouse event: %d x %d", ev.MouseX, ev.MouseY)
|
||||
button := ""
|
||||
switch ev.Key {
|
||||
case termbox.MouseLeft:
|
||||
button = "MouseLeft: %d"
|
||||
case termbox.MouseMiddle:
|
||||
button = "MouseMiddle: %d"
|
||||
case termbox.MouseRight:
|
||||
button = "MouseRight: %d"
|
||||
case termbox.MouseWheelUp:
|
||||
button = "MouseWheelUp: %d"
|
||||
case termbox.MouseWheelDown:
|
||||
button = "MouseWheelDown: %d"
|
||||
case termbox.MouseRelease:
|
||||
button = "MouseRelease: %d"
|
||||
}
|
||||
if ev.Mod&termbox.ModMotion != 0 {
|
||||
button += "*"
|
||||
}
|
||||
counter++
|
||||
printf_tb(43, 19, termbox.ColorWhite, termbox.ColorBlack, "Key: ")
|
||||
printf_tb(48, 19, termbox.ColorYellow, termbox.ColorBlack, button, counter)
|
||||
}
|
||||
|
||||
func dispatch_press(ev *termbox.Event) {
|
||||
if ev.Mod&termbox.ModAlt != 0 {
|
||||
draw_key(K_LALT, termbox.ColorWhite, termbox.ColorRed)
|
||||
draw_key(K_RALT, termbox.ColorWhite, termbox.ColorRed)
|
||||
}
|
||||
|
||||
var k *combo
|
||||
if ev.Key >= termbox.KeyArrowRight {
|
||||
k = &func_combos[0xFFFF-ev.Key]
|
||||
} else if ev.Ch < 128 {
|
||||
if ev.Ch == 0 && ev.Key < 128 {
|
||||
k = &combos[ev.Key]
|
||||
} else {
|
||||
k = &combos[ev.Ch]
|
||||
}
|
||||
}
|
||||
if k == nil {
|
||||
return
|
||||
}
|
||||
|
||||
keys := k.keys
|
||||
for _, k := range keys {
|
||||
draw_key(k, termbox.ColorWhite, termbox.ColorRed)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
err := termbox.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer termbox.Close()
|
||||
|
||||
termbox.SetInputMode(termbox.InputEsc | termbox.InputMouse)
|
||||
|
||||
termbox.Clear(termbox.ColorDefault, termbox.ColorDefault)
|
||||
draw_keyboard()
|
||||
termbox.Flush()
|
||||
inputmode := 0
|
||||
ctrlxpressed := false
|
||||
loop:
|
||||
for {
|
||||
switch ev := termbox.PollEvent(); ev.Type {
|
||||
case termbox.EventKey:
|
||||
if ev.Key == termbox.KeyCtrlS && ctrlxpressed {
|
||||
termbox.Sync()
|
||||
}
|
||||
if ev.Key == termbox.KeyCtrlQ && ctrlxpressed {
|
||||
break loop
|
||||
}
|
||||
if ev.Key == termbox.KeyCtrlC && ctrlxpressed {
|
||||
chmap := []termbox.InputMode{
|
||||
termbox.InputEsc | termbox.InputMouse,
|
||||
termbox.InputAlt | termbox.InputMouse,
|
||||
termbox.InputEsc,
|
||||
termbox.InputAlt,
|
||||
}
|
||||
inputmode++
|
||||
if inputmode >= len(chmap) {
|
||||
inputmode = 0
|
||||
}
|
||||
termbox.SetInputMode(chmap[inputmode])
|
||||
}
|
||||
if ev.Key == termbox.KeyCtrlX {
|
||||
ctrlxpressed = true
|
||||
} else {
|
||||
ctrlxpressed = false
|
||||
}
|
||||
|
||||
termbox.Clear(termbox.ColorDefault, termbox.ColorDefault)
|
||||
draw_keyboard()
|
||||
dispatch_press(&ev)
|
||||
pretty_print_press(&ev)
|
||||
termbox.Flush()
|
||||
case termbox.EventResize:
|
||||
termbox.Clear(termbox.ColorDefault, termbox.ColorDefault)
|
||||
draw_keyboard()
|
||||
pretty_print_resize(&ev)
|
||||
termbox.Flush()
|
||||
case termbox.EventMouse:
|
||||
termbox.Clear(termbox.ColorDefault, termbox.ColorDefault)
|
||||
draw_keyboard()
|
||||
pretty_print_mouse(&ev)
|
||||
termbox.Flush()
|
||||
case termbox.EventError:
|
||||
panic(ev.Err)
|
||||
}
|
||||
}
|
||||
}
|
228
vendor/github.com/nsf/termbox-go/_demos/output.go
generated
vendored
228
vendor/github.com/nsf/termbox-go/_demos/output.go
generated
vendored
|
@ -1,228 +0,0 @@
|
|||
package main
|
||||
|
||||
import "github.com/mattn/go-runewidth"
|
||||
import "github.com/nsf/termbox-go"
|
||||
|
||||
const chars = "nnnnnnnnnbbbbbbbbbuuuuuuuuuBBBBBBBBB"
|
||||
|
||||
var output_mode = termbox.OutputNormal
|
||||
|
||||
func next_char(current int) int {
|
||||
current++
|
||||
if current >= len(chars) {
|
||||
return 0
|
||||
}
|
||||
return current
|
||||
}
|
||||
|
||||
func print_combinations_table(sx, sy int, attrs []termbox.Attribute) {
|
||||
var bg termbox.Attribute
|
||||
current_char := 0
|
||||
y := sy
|
||||
|
||||
all_attrs := []termbox.Attribute{
|
||||
0,
|
||||
termbox.AttrBold,
|
||||
termbox.AttrUnderline,
|
||||
termbox.AttrBold | termbox.AttrUnderline,
|
||||
}
|
||||
|
||||
draw_line := func() {
|
||||
x := sx
|
||||
for _, a := range all_attrs {
|
||||
for c := termbox.ColorDefault; c <= termbox.ColorWhite; c++ {
|
||||
fg := a | c
|
||||
termbox.SetCell(x, y, rune(chars[current_char]), fg, bg)
|
||||
current_char = next_char(current_char)
|
||||
x++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, a := range attrs {
|
||||
for c := termbox.ColorDefault; c <= termbox.ColorWhite; c++ {
|
||||
bg = a | c
|
||||
draw_line()
|
||||
y++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func print_wide(x, y int, s string) {
|
||||
red := false
|
||||
for _, r := range s {
|
||||
c := termbox.ColorDefault
|
||||
if red {
|
||||
c = termbox.ColorRed
|
||||
}
|
||||
termbox.SetCell(x, y, r, termbox.ColorDefault, c)
|
||||
w := runewidth.RuneWidth(r)
|
||||
if w == 0 || (w == 2 && runewidth.IsAmbiguousWidth(r)) {
|
||||
w = 1
|
||||
}
|
||||
x += w
|
||||
|
||||
red = !red
|
||||
}
|
||||
}
|
||||
|
||||
const hello_world = "こんにちは世界"
|
||||
|
||||
func draw_all() {
|
||||
termbox.Clear(termbox.ColorDefault, termbox.ColorDefault)
|
||||
|
||||
switch output_mode {
|
||||
|
||||
case termbox.OutputNormal:
|
||||
print_combinations_table(1, 1, []termbox.Attribute{
|
||||
0,
|
||||
termbox.AttrBold,
|
||||
})
|
||||
print_combinations_table(2+len(chars), 1, []termbox.Attribute{
|
||||
termbox.AttrReverse,
|
||||
})
|
||||
print_wide(2+len(chars), 11, hello_world)
|
||||
|
||||
case termbox.OutputGrayscale:
|
||||
for y := 0; y < 26; y++ {
|
||||
for x := 0; x < 26; x++ {
|
||||
termbox.SetCell(x, y, 'n',
|
||||
termbox.Attribute(x+1),
|
||||
termbox.Attribute(y+1))
|
||||
termbox.SetCell(x+27, y, 'b',
|
||||
termbox.Attribute(x+1)|termbox.AttrBold,
|
||||
termbox.Attribute(26-y))
|
||||
termbox.SetCell(x+54, y, 'u',
|
||||
termbox.Attribute(x+1)|termbox.AttrUnderline,
|
||||
termbox.Attribute(y+1))
|
||||
}
|
||||
termbox.SetCell(82, y, 'd',
|
||||
termbox.Attribute(y+1),
|
||||
termbox.ColorDefault)
|
||||
termbox.SetCell(83, y, 'd',
|
||||
termbox.ColorDefault,
|
||||
termbox.Attribute(26-y))
|
||||
}
|
||||
|
||||
case termbox.Output216:
|
||||
for r := 0; r < 6; r++ {
|
||||
for g := 0; g < 6; g++ {
|
||||
for b := 0; b < 6; b++ {
|
||||
y := r
|
||||
x := g + 6*b
|
||||
c1 := termbox.Attribute(1 + r*36 + g*6 + b)
|
||||
bg := termbox.Attribute(1 + g*36 + b*6 + r)
|
||||
c2 := termbox.Attribute(1 + b*36 + r*6 + g)
|
||||
bc1 := c1 | termbox.AttrBold
|
||||
uc1 := c1 | termbox.AttrUnderline
|
||||
bc2 := c2 | termbox.AttrBold
|
||||
uc2 := c2 | termbox.AttrUnderline
|
||||
termbox.SetCell(x, y, 'n', c1, bg)
|
||||
termbox.SetCell(x, y+6, 'b', bc1, bg)
|
||||
termbox.SetCell(x, y+12, 'u', uc1, bg)
|
||||
termbox.SetCell(x, y+18, 'B', bc1|uc1, bg)
|
||||
termbox.SetCell(x+37, y, 'n', c2, bg)
|
||||
termbox.SetCell(x+37, y+6, 'b', bc2, bg)
|
||||
termbox.SetCell(x+37, y+12, 'u', uc2, bg)
|
||||
termbox.SetCell(x+37, y+18, 'B', bc2|uc2, bg)
|
||||
}
|
||||
c1 := termbox.Attribute(1 + g*6 + r*36)
|
||||
c2 := termbox.Attribute(6 + g*6 + r*36)
|
||||
termbox.SetCell(74+g, r, 'd', c1, termbox.ColorDefault)
|
||||
termbox.SetCell(74+g, r+6, 'd', c2, termbox.ColorDefault)
|
||||
termbox.SetCell(74+g, r+12, 'd', termbox.ColorDefault, c1)
|
||||
termbox.SetCell(74+g, r+18, 'd', termbox.ColorDefault, c2)
|
||||
}
|
||||
}
|
||||
|
||||
case termbox.Output256:
|
||||
for y := 0; y < 4; y++ {
|
||||
for x := 0; x < 8; x++ {
|
||||
for z := 0; z < 8; z++ {
|
||||
bg := termbox.Attribute(1 + y*64 + x*8 + z)
|
||||
c1 := termbox.Attribute(256 - y*64 - x*8 - z)
|
||||
c2 := termbox.Attribute(1 + y*64 + z*8 + x)
|
||||
c3 := termbox.Attribute(256 - y*64 - z*8 - x)
|
||||
c4 := termbox.Attribute(1 + y*64 + x*4 + z*4)
|
||||
bold := c2 | termbox.AttrBold
|
||||
under := c3 | termbox.AttrUnderline
|
||||
both := c1 | termbox.AttrBold | termbox.AttrUnderline
|
||||
termbox.SetCell(z+8*x, y, ' ', 0, bg)
|
||||
termbox.SetCell(z+8*x, y+5, 'n', c4, bg)
|
||||
termbox.SetCell(z+8*x, y+10, 'b', bold, bg)
|
||||
termbox.SetCell(z+8*x, y+15, 'u', under, bg)
|
||||
termbox.SetCell(z+8*x, y+20, 'B', both, bg)
|
||||
}
|
||||
}
|
||||
}
|
||||
for x := 0; x < 12; x++ {
|
||||
for y := 0; y < 2; y++ {
|
||||
c1 := termbox.Attribute(233 + y*12 + x)
|
||||
termbox.SetCell(66+x, y, 'd', c1, termbox.ColorDefault)
|
||||
termbox.SetCell(66+x, 2+y, 'd', termbox.ColorDefault, c1)
|
||||
}
|
||||
}
|
||||
for x := 0; x < 6; x++ {
|
||||
for y := 0; y < 6; y++ {
|
||||
c1 := termbox.Attribute(17 + x*6 + y*36)
|
||||
c2 := termbox.Attribute(17 + 5 + x*6 + y*36)
|
||||
termbox.SetCell(66+x, 6+y, 'd', c1, termbox.ColorDefault)
|
||||
termbox.SetCell(66+x, 12+y, 'd', c2, termbox.ColorDefault)
|
||||
termbox.SetCell(72+x, 6+y, 'd', termbox.ColorDefault, c1)
|
||||
termbox.SetCell(72+x, 12+y, 'd', termbox.ColorDefault, c2)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
termbox.Flush()
|
||||
}
|
||||
|
||||
var available_modes = []termbox.OutputMode{
|
||||
termbox.OutputNormal,
|
||||
termbox.OutputGrayscale,
|
||||
termbox.Output216,
|
||||
termbox.Output256,
|
||||
}
|
||||
|
||||
var output_mode_index = 0
|
||||
|
||||
func switch_output_mode(direction int) {
|
||||
output_mode_index += direction
|
||||
if output_mode_index < 0 {
|
||||
output_mode_index = len(available_modes) - 1
|
||||
} else if output_mode_index >= len(available_modes) {
|
||||
output_mode_index = 0
|
||||
}
|
||||
output_mode = termbox.SetOutputMode(available_modes[output_mode_index])
|
||||
termbox.Clear(termbox.ColorDefault, termbox.ColorDefault)
|
||||
termbox.Sync()
|
||||
}
|
||||
|
||||
func main() {
|
||||
err := termbox.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer termbox.Close()
|
||||
|
||||
draw_all()
|
||||
loop:
|
||||
for {
|
||||
switch ev := termbox.PollEvent(); ev.Type {
|
||||
case termbox.EventKey:
|
||||
switch ev.Key {
|
||||
case termbox.KeyEsc:
|
||||
break loop
|
||||
case termbox.KeyArrowUp, termbox.KeyArrowRight:
|
||||
switch_output_mode(1)
|
||||
draw_all()
|
||||
case termbox.KeyArrowDown, termbox.KeyArrowLeft:
|
||||
switch_output_mode(-1)
|
||||
draw_all()
|
||||
}
|
||||
case termbox.EventResize:
|
||||
draw_all()
|
||||
}
|
||||
}
|
||||
}
|
105
vendor/github.com/nsf/termbox-go/_demos/paint.go
generated
vendored
105
vendor/github.com/nsf/termbox-go/_demos/paint.go
generated
vendored
|
@ -1,105 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/nsf/termbox-go"
|
||||
)
|
||||
|
||||
var curCol = 0
|
||||
var curRune = 0
|
||||
var backbuf []termbox.Cell
|
||||
var bbw, bbh int
|
||||
|
||||
var runes = []rune{' ', '░', '▒', '▓', '█'}
|
||||
var colors = []termbox.Attribute{
|
||||
termbox.ColorBlack,
|
||||
termbox.ColorRed,
|
||||
termbox.ColorGreen,
|
||||
termbox.ColorYellow,
|
||||
termbox.ColorBlue,
|
||||
termbox.ColorMagenta,
|
||||
termbox.ColorCyan,
|
||||
termbox.ColorWhite,
|
||||
}
|
||||
|
||||
type attrFunc func(int) (rune, termbox.Attribute, termbox.Attribute)
|
||||
|
||||
func updateAndDrawButtons(current *int, x, y int, mx, my int, n int, attrf attrFunc) {
|
||||
lx, ly := x, y
|
||||
for i := 0; i < n; i++ {
|
||||
if lx <= mx && mx <= lx+3 && ly <= my && my <= ly+1 {
|
||||
*current = i
|
||||
}
|
||||
r, fg, bg := attrf(i)
|
||||
termbox.SetCell(lx+0, ly+0, r, fg, bg)
|
||||
termbox.SetCell(lx+1, ly+0, r, fg, bg)
|
||||
termbox.SetCell(lx+2, ly+0, r, fg, bg)
|
||||
termbox.SetCell(lx+3, ly+0, r, fg, bg)
|
||||
termbox.SetCell(lx+0, ly+1, r, fg, bg)
|
||||
termbox.SetCell(lx+1, ly+1, r, fg, bg)
|
||||
termbox.SetCell(lx+2, ly+1, r, fg, bg)
|
||||
termbox.SetCell(lx+3, ly+1, r, fg, bg)
|
||||
lx += 4
|
||||
}
|
||||
lx, ly = x, y
|
||||
for i := 0; i < n; i++ {
|
||||
if *current == i {
|
||||
fg := termbox.ColorRed | termbox.AttrBold
|
||||
bg := termbox.ColorDefault
|
||||
termbox.SetCell(lx+0, ly+2, '^', fg, bg)
|
||||
termbox.SetCell(lx+1, ly+2, '^', fg, bg)
|
||||
termbox.SetCell(lx+2, ly+2, '^', fg, bg)
|
||||
termbox.SetCell(lx+3, ly+2, '^', fg, bg)
|
||||
}
|
||||
lx += 4
|
||||
}
|
||||
}
|
||||
|
||||
func update_and_redraw_all(mx, my int) {
|
||||
termbox.Clear(termbox.ColorDefault, termbox.ColorDefault)
|
||||
if mx != -1 && my != -1 {
|
||||
backbuf[bbw*my+mx] = termbox.Cell{Ch: runes[curRune], Fg: colors[curCol]}
|
||||
}
|
||||
copy(termbox.CellBuffer(), backbuf)
|
||||
_, h := termbox.Size()
|
||||
updateAndDrawButtons(&curRune, 0, 0, mx, my, len(runes), func(i int) (rune, termbox.Attribute, termbox.Attribute) {
|
||||
return runes[i], termbox.ColorDefault, termbox.ColorDefault
|
||||
})
|
||||
updateAndDrawButtons(&curCol, 0, h-3, mx, my, len(colors), func(i int) (rune, termbox.Attribute, termbox.Attribute) {
|
||||
return ' ', termbox.ColorDefault, colors[i]
|
||||
})
|
||||
termbox.Flush()
|
||||
}
|
||||
|
||||
func reallocBackBuffer(w, h int) {
|
||||
bbw, bbh = w, h
|
||||
backbuf = make([]termbox.Cell, w*h)
|
||||
}
|
||||
|
||||
func main() {
|
||||
err := termbox.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer termbox.Close()
|
||||
termbox.SetInputMode(termbox.InputEsc | termbox.InputMouse)
|
||||
reallocBackBuffer(termbox.Size())
|
||||
update_and_redraw_all(-1, -1)
|
||||
|
||||
mainloop:
|
||||
for {
|
||||
mx, my := -1, -1
|
||||
switch ev := termbox.PollEvent(); ev.Type {
|
||||
case termbox.EventKey:
|
||||
if ev.Key == termbox.KeyEsc {
|
||||
break mainloop
|
||||
}
|
||||
case termbox.EventMouse:
|
||||
if ev.Key == termbox.MouseLeft {
|
||||
mx, my = ev.MouseX, ev.MouseY
|
||||
}
|
||||
case termbox.EventResize:
|
||||
reallocBackBuffer(ev.Width, ev.Height)
|
||||
}
|
||||
update_and_redraw_all(mx, my)
|
||||
}
|
||||
}
|
46
vendor/github.com/nsf/termbox-go/_demos/random_output.go
generated
vendored
46
vendor/github.com/nsf/termbox-go/_demos/random_output.go
generated
vendored
|
@ -1,46 +0,0 @@
|
|||
package main
|
||||
|
||||
import "github.com/nsf/termbox-go"
|
||||
import "math/rand"
|
||||
import "time"
|
||||
|
||||
func draw() {
|
||||
w, h := termbox.Size()
|
||||
termbox.Clear(termbox.ColorDefault, termbox.ColorDefault)
|
||||
for y := 0; y < h; y++ {
|
||||
for x := 0; x < w; x++ {
|
||||
termbox.SetCell(x, y, ' ', termbox.ColorDefault,
|
||||
termbox.Attribute(rand.Int()%8)+1)
|
||||
}
|
||||
}
|
||||
termbox.Flush()
|
||||
}
|
||||
|
||||
func main() {
|
||||
err := termbox.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer termbox.Close()
|
||||
|
||||
event_queue := make(chan termbox.Event)
|
||||
go func() {
|
||||
for {
|
||||
event_queue <- termbox.PollEvent()
|
||||
}
|
||||
}()
|
||||
|
||||
draw()
|
||||
loop:
|
||||
for {
|
||||
select {
|
||||
case ev := <-event_queue:
|
||||
if ev.Type == termbox.EventKey && ev.Key == termbox.KeyEsc {
|
||||
break loop
|
||||
}
|
||||
default:
|
||||
draw()
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
}
|
109
vendor/github.com/nsf/termbox-go/_demos/raw_input.go
generated
vendored
109
vendor/github.com/nsf/termbox-go/_demos/raw_input.go
generated
vendored
|
@ -1,109 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/nsf/termbox-go"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func tbprint(x, y int, fg, bg termbox.Attribute, msg string) {
|
||||
for _, c := range msg {
|
||||
termbox.SetCell(x, y, c, fg, bg)
|
||||
x++
|
||||
}
|
||||
}
|
||||
|
||||
var current string
|
||||
var curev termbox.Event
|
||||
|
||||
func mouse_button_str(k termbox.Key) string {
|
||||
switch k {
|
||||
case termbox.MouseLeft:
|
||||
return "MouseLeft"
|
||||
case termbox.MouseMiddle:
|
||||
return "MouseMiddle"
|
||||
case termbox.MouseRight:
|
||||
return "MouseRight"
|
||||
case termbox.MouseRelease:
|
||||
return "MouseRelease"
|
||||
case termbox.MouseWheelUp:
|
||||
return "MouseWheelUp"
|
||||
case termbox.MouseWheelDown:
|
||||
return "MouseWheelDown"
|
||||
}
|
||||
return "Key"
|
||||
}
|
||||
|
||||
func mod_str(m termbox.Modifier) string {
|
||||
var out []string
|
||||
if m&termbox.ModAlt != 0 {
|
||||
out = append(out, "ModAlt")
|
||||
}
|
||||
if m&termbox.ModMotion != 0 {
|
||||
out = append(out, "ModMotion")
|
||||
}
|
||||
return strings.Join(out, " | ")
|
||||
}
|
||||
|
||||
func redraw_all() {
|
||||
const coldef = termbox.ColorDefault
|
||||
termbox.Clear(coldef, coldef)
|
||||
tbprint(0, 0, termbox.ColorMagenta, coldef, "Press 'q' to quit")
|
||||
tbprint(0, 1, coldef, coldef, current)
|
||||
switch curev.Type {
|
||||
case termbox.EventKey:
|
||||
tbprint(0, 2, coldef, coldef,
|
||||
fmt.Sprintf("EventKey: k: %d, c: %c, mod: %s", curev.Key, curev.Ch, mod_str(curev.Mod)))
|
||||
case termbox.EventMouse:
|
||||
tbprint(0, 2, coldef, coldef,
|
||||
fmt.Sprintf("EventMouse: x: %d, y: %d, b: %s, mod: %s",
|
||||
curev.MouseX, curev.MouseY, mouse_button_str(curev.Key), mod_str(curev.Mod)))
|
||||
case termbox.EventNone:
|
||||
tbprint(0, 2, coldef, coldef, "EventNone")
|
||||
}
|
||||
tbprint(0, 3, coldef, coldef, fmt.Sprintf("%d", curev.N))
|
||||
termbox.Flush()
|
||||
}
|
||||
|
||||
func main() {
|
||||
err := termbox.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer termbox.Close()
|
||||
termbox.SetInputMode(termbox.InputAlt | termbox.InputMouse)
|
||||
redraw_all()
|
||||
|
||||
data := make([]byte, 0, 64)
|
||||
mainloop:
|
||||
for {
|
||||
if cap(data)-len(data) < 32 {
|
||||
newdata := make([]byte, len(data), len(data)+32)
|
||||
copy(newdata, data)
|
||||
data = newdata
|
||||
}
|
||||
beg := len(data)
|
||||
d := data[beg : beg+32]
|
||||
switch ev := termbox.PollRawEvent(d); ev.Type {
|
||||
case termbox.EventRaw:
|
||||
data = data[:beg+ev.N]
|
||||
current = fmt.Sprintf("%q", data)
|
||||
if current == `"q"` {
|
||||
break mainloop
|
||||
}
|
||||
|
||||
for {
|
||||
ev := termbox.ParseEvent(data)
|
||||
if ev.N == 0 {
|
||||
break
|
||||
}
|
||||
curev = ev
|
||||
copy(data, data[curev.N:])
|
||||
data = data[:len(data)-curev.N]
|
||||
}
|
||||
case termbox.EventError:
|
||||
panic(ev.Err)
|
||||
}
|
||||
redraw_all()
|
||||
}
|
||||
}
|
0
vendor/github.com/nsf/termbox-go/collect_terminfo.py
generated
vendored
Executable file → Normal file
0
vendor/github.com/nsf/termbox-go/collect_terminfo.py
generated
vendored
Executable file → Normal file
Loading…
Add table
Add a link
Reference in a new issue