fix lblt to relative path
This commit is contained in:
parent
86298568c7
commit
fc68eb66d7
14
main.go
14
main.go
@ -1,7 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "log"
|
import "log"
|
||||||
import blt "bearlibterminal"
|
import (
|
||||||
|
blt "bearlibterminal"
|
||||||
|
"ui"
|
||||||
|
"util"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.Println("Starting...")
|
log.Println("Starting...")
|
||||||
@ -9,7 +13,11 @@ func main() {
|
|||||||
defer blt.Close()
|
defer blt.Close()
|
||||||
blt.Print(1, 1, "Hello, world!")
|
blt.Print(1, 1, "Hello, world!")
|
||||||
blt.Refresh()
|
blt.Refresh()
|
||||||
for blt.Read() != blt.TK_CLOSE {
|
var exit = false
|
||||||
|
for !exit {
|
||||||
|
exit, _ = util.InArray(blt.Read(), []int{blt.TK_CLOSE, blt.TK_ESCAPE})
|
||||||
|
blt.Print( 1, 3, "Key: " + ui.ReadKey() )
|
||||||
|
blt.Refresh()
|
||||||
}
|
}
|
||||||
|
log.Println("Closing...")
|
||||||
}
|
}
|
21
src/ui/ui.go
Normal file
21
src/ui/ui.go
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package ui
|
||||||
|
|
||||||
|
import blt "bearlibterminal"
|
||||||
|
import "util"
|
||||||
|
|
||||||
|
func ReadKey() (string) {
|
||||||
|
var key = blt.Read()
|
||||||
|
if !blt.HasInput() {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
var modifiers = []int{blt.TK_SHIFT, blt.TK_ALT, blt.TK_CONTROL}
|
||||||
|
modifierPressed, _ := util.InArray(key, modifiers)
|
||||||
|
var pressed = ""
|
||||||
|
if (modifierPressed) {
|
||||||
|
pressed ="modifier"
|
||||||
|
} else {
|
||||||
|
pressed = string(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
return pressed
|
||||||
|
}
|
24
src/util/util.go
Normal file
24
src/util/util.go
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
)
|
||||||
|
|
||||||
|
func InArray(val interface{}, array interface{}) (exists bool, index int) {
|
||||||
|
exists = false
|
||||||
|
index = -1
|
||||||
|
|
||||||
|
switch reflect.TypeOf(array).Kind() {
|
||||||
|
case reflect.Slice:
|
||||||
|
s := reflect.ValueOf(array)
|
||||||
|
|
||||||
|
for i := 0; i < s.Len(); i++ {
|
||||||
|
if reflect.DeepEqual(val, s.Index(i).Interface()) == true {
|
||||||
|
index = i
|
||||||
|
exists = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user