Skip to content

Instantly share code, notes, and snippets.

@syossan27
Last active December 11, 2017 11:06
Show Gist options
  • Select an option

  • Save syossan27/5fce7dddde6c58e6264cbd9babd8eece to your computer and use it in GitHub Desktop.

Select an option

Save syossan27/5fce7dddde6c58e6264cbd9babd8eece to your computer and use it in GitHub Desktop.
package main
import (
"github.com/nsf/termbox-go"
)
func main() {
defer termbox.Close()
err := termbox.Init()
if err != nil {
panic(err)
}
// 入力モードはキー入力の他にマウス入力も有り
termbox.SetInputMode(termbox.InputAlt)
// 画面をクリア
termbox.Clear(termbox.ColorDefault, termbox.ColorDefault)
// termboxはrune単位で表示することが出来るので、
// stringをruneに分解して都度表示している
x := 0
for _, c := range "hello, world" {
termbox.SetCell(x, 0, c, termbox.ColorDefault, termbox.ColorDefault)
x++
}
// 結果を画面に反映
termbox.Flush()
// キーイベントを監視し、Ctrl + Cが押下されれば、ループ脱出
loop:
for {
switch ev := termbox.PollEvent(); ev.Type {
case termbox.EventKey:
switch ev.Key {
case termbox.KeyCtrlC:
break loop
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment