本文整理汇总了Golang中github.com/pblaszczyk/go/spotify/Godeps/_workspace/src/github.com/rthornton128/goncurses.Window.GetChar方法的典型用法代码示例。如果您正苦于以下问题:Golang Window.GetChar方法的具体用法?Golang Window.GetChar怎么用?Golang Window.GetChar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pblaszczyk/go/spotify/Godeps/_workspace/src/github.com/rthornton128/goncurses.Window
的用法示例。
在下文中一共展示了Window.GetChar方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handleInput
func handleInput(stdscr *gc.Window, ship *Ship) bool {
lines, cols := stdscr.MaxYX()
y, x := ship.YX()
k := stdscr.GetChar()
switch byte(k) {
case 0:
break
case 'a':
x--
if x < 2 {
x = 2
}
case 'd':
x++
if x > cols-3 {
x = cols - 3
}
case 's':
y++
if y > lines-4 {
y = lines - 4
}
case 'w':
y--
if y < 2 {
y = 2
}
case ' ':
objects = append(objects, newBullet(y+1, x+4))
objects = append(objects, newBullet(y+3, x+4))
default:
return false
}
ship.MoveWindow(y, x)
return true
}
示例2: main
func main() {
stdscr, err := gc.Init()
if err != nil {
log.Fatal(err)
}
defer gc.End()
// Turn off character echo, hide the cursor and disable input buffering
gc.Echo(false)
gc.CBreak(true)
gc.Cursor(0)
stdscr.Print("Use arrow keys to move the window. Press 'q' to exit")
stdscr.NoutRefresh()
// Determine the center of the screen and offset those coordinates by
// half of the window size we are about to create. These coordinates will
// be used to move our window around the screen
rows, cols := stdscr.MaxYX()
height, width := 5, 10
y, x := (rows-height)/2, (cols-width)/2
// Create a new window centered on the screen and enable the use of the
// keypad on it so the arrow keys are available
var win *gc.Window
win, err = gc.NewWindow(height, width, y, x)
if err != nil {
log.Fatal(err)
}
win.Keypad(true)
main:
for {
// Clear the section of screen where the box is currently located so
// that it is blanked by calling Erase on the window and refreshing it
// so that the chances are sent to the virtual screen but not actually
// output to the terminal
win.Erase()
win.NoutRefresh()
// Move the window to it's new location (if any) and redraw it
win.MoveWindow(y, x)
win.Box(gc.ACS_VLINE, gc.ACS_HLINE)
win.NoutRefresh()
// Update will flush only the characters which have changed between the
// physical screen and the virtual screen, minimizing the number of
// characters which must be sent
gc.Update()
// In order for the window to display correctly, we must call GetChar()
// on it rather than stdscr
switch win.GetChar() {
case 'q':
break main
case gc.KEY_LEFT:
if x > 0 {
x--
}
case gc.KEY_RIGHT:
if x < cols-width {
x++
}
case gc.KEY_UP:
if y > 1 {
y--
}
case gc.KEY_DOWN:
if y < rows-height {
y++
}
}
}
win.Delete()
}