当前位置: 首页>>代码示例>>Golang>>正文


Golang Window.GetChar方法代码示例

本文整理汇总了Golang中github.com/rthornton128/goncurses.Window.GetChar方法的典型用法代码示例。如果您正苦于以下问题:Golang Window.GetChar方法的具体用法?Golang Window.GetChar怎么用?Golang Window.GetChar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/rthornton128/goncurses.Window的用法示例。


在下文中一共展示了Window.GetChar方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: contactsWindowNavigation

// contact Menu Window Navigation input handler
func contactsWindowNavigation(contactsMenuWin *gc.Window, contactMenu *gc.Menu) int {
	var c gc.Char
	var rawInput gc.Key
	for {
		gc.Update()
		rawInput = contactsMenuWin.GetChar()
		c = gc.Char(rawInput)
		if rawInput == gc.KEY_TAB || rawInput == gc.KEY_RETURN {
			return 0
		} else if c == gc.Char(27) {
			return 1
		} else if c == gc.Char('j') || rawInput == gc.KEY_DOWN {
			contactMenu.Driver(gc.REQ_DOWN)
			changeContact(contactsMenuWin, contactMenu)
		} else if c == gc.Char('k') || rawInput == gc.KEY_UP {
			contactMenu.Driver(gc.REQ_UP)
			changeContact(contactsMenuWin, contactMenu)
		} else if c == gc.Char('g') {
			contactMenu.Driver(gc.REQ_FIRST)
			changeContact(contactsMenuWin, contactMenu)
		} else if c == gc.Char('G') {
			contactMenu.Driver(gc.REQ_LAST)
			changeContact(contactsMenuWin, contactMenu)
		} else {
			continue
		}
	}
}
开发者ID:AyaTech,项目名称:textsecure-client,代码行数:29,代码来源:input.go

示例2: display

func (c *Circuit) display() {
	stdscr, err := gc.Init()
	if err != nil {
		log.Println(err)
	}
	defer gc.End()

	rows, cols := stdscr.MaxYX()
	height, width := len(c.circuit)+1, len(c.circuit[0])+1
	y, x := (rows-height)/2, (cols-width)/2

	var win *gc.Window
	win, err = gc.NewWindow(height, width, y, x)
	if err != nil {
		log.Println(err)
	}
	defer win.Delete()

	win.Timeout(500)

	for i := 0; i != height-1; i++ {
		for j := 0; j != width-1; j++ {
			if c.circuit[i][j] == "" {
				continue
			}
			char := gc.Char([]rune(c.circuit[i][j])[0])
			win.MoveAddChar(i, j, char)
		}
	}

main:
	for {
		for _, com := range c.Components {
			com.Update()
		}

		for _, com := range c.Components {
			cx, cy, _, _ := com.Space()
			for coord, out := range com.Visual() {
				char := gc.Char([]rune(*out)[0])
				win.MoveAddChar(cx+coord.X, cy+coord.Y, char)
			}
		}

		win.NoutRefresh()
		gc.Update()

		switch win.GetChar() {
		case 'q':
			break main
		}
	}
}
开发者ID:furryfaust,项目名称:textelectronics,代码行数:53,代码来源:circuit.go

示例3: 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
}
开发者ID:trotha01,项目名称:goncurses,代码行数:37,代码来源:starfield.go

示例4: windw

func windw() {
	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 := 20, 40
	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)

windw:
	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 windw
		case 'h':
			if x > 0 {
				x--
			}
		case 'l':
			if x < cols-width {
				x++
			}
		case 'k':
			if y > 1 {
				y--
			}
		case 'j':
			if y < rows-height {
				y++
			}
		}
	}
	win.Delete()
}
开发者ID:kuzzmi,项目名称:monk,代码行数:74,代码来源:window.go

示例5: handleInput

func (cw *chatWin) handleInput(win *goncurses.Window) (line string) {
	k := win.GetChar()
	if k == 0 {
		return ""
	}

	// some systems send a DEL ASCII character instead of KEY_BACKSPACE
	// account for both just in case
	if k == 127 {
		k = goncurses.KEY_BACKSPACE
	}

	switch k {
	case goncurses.KEY_TAB: // tab
	// case goncurses.KEY_RETURN: // enter key vs. KEY_ENTER
	case goncurses.KEY_DOWN: // down arrow key
	case goncurses.KEY_UP: // up arrow key
	case goncurses.KEY_LEFT: // left arrow key
	case goncurses.KEY_RIGHT: // right arrow key
	case goncurses.KEY_HOME: // home key
	case goncurses.KEY_BACKSPACE: // backpace
		if len(cw.line) > 0 {
			cw.line = cw.line[:len(cw.line)-1]
		}
		y, x := win.CursorYX()
		// TODO: handle this more elegantly (e.g. tell ncurses not to print backspaces)
		// we have to do this three times because ncurses inserts two characters for backspace
		// this is likely wrong in some cases
		for i := 0; i < 3; i++ {
			y, x = cw.moveLeft(y, x)
			win.MoveDelChar(y, x)
		}
		win.Refresh()
	case goncurses.KEY_F1: // F1 key
	case goncurses.KEY_F2: // F2 key
	case goncurses.KEY_F3: // F3 key
	case goncurses.KEY_F4: // F4 key
	case goncurses.KEY_F5: // F5 key
	case goncurses.KEY_F6: // F6 key
	case goncurses.KEY_F7: // F7 key
	case goncurses.KEY_F8: // F8 key
	case goncurses.KEY_F9: // F9 key
	case goncurses.KEY_F10: // F10 key
	case goncurses.KEY_F11: // F11 key
	case goncurses.KEY_F12: // F12 key
	case goncurses.KEY_DL: // delete-line key
	case goncurses.KEY_IL: // insert-line key
	case goncurses.KEY_DC: // delete-character key
	case goncurses.KEY_IC: // insert-character key
	case goncurses.KEY_EIC: // sent by rmir or smir in insert mode
	case goncurses.KEY_CLEAR: // clear-screen or erase key3
	case goncurses.KEY_EOS: // clear-to-end-of-screen key
	case goncurses.KEY_EOL: // clear-to-end-of-line key
	case goncurses.KEY_SF: // scroll-forward key
	case goncurses.KEY_SR: // scroll-backward key
	case goncurses.KEY_PAGEDOWN: // page-down key (next-page)
	case goncurses.KEY_PAGEUP: // page-up key (prev-page)
	case goncurses.KEY_STAB: // set-tab key
	case goncurses.KEY_CTAB: // clear-tab key
	case goncurses.KEY_CATAB: // clear-all-tabs key
	case goncurses.KEY_RETURN: // enter key vs. KEY_ENTER
		fallthrough
	case goncurses.KEY_ENTER: // enter/send key
		line = cw.line
		cw.line = ""
		win.Erase()
		win.Print(PROMPT)
	case goncurses.KEY_PRINT: // print key
	case goncurses.KEY_LL: // lower-left key (home down)
	case goncurses.KEY_A1: // upper left of keypad
	case goncurses.KEY_A3: // upper right of keypad
	case goncurses.KEY_B2: // center of keypad
	case goncurses.KEY_C1: // lower left of keypad
	case goncurses.KEY_C3: // lower right of keypad
	case goncurses.KEY_BTAB: // back-tab key
	case goncurses.KEY_BEG: // begin key
	case goncurses.KEY_CANCEL: // cancel key
	case goncurses.KEY_CLOSE: // close key
	case goncurses.KEY_COMMAND: // command key
	case goncurses.KEY_COPY: // copy key
	case goncurses.KEY_CREATE: // create key
	case goncurses.KEY_END: // end key
	case goncurses.KEY_EXIT: // exit key
	case goncurses.KEY_FIND: // find key
	case goncurses.KEY_HELP: // help key
	case goncurses.KEY_MARK: // mark key
	case goncurses.KEY_MESSAGE: // message key
	case goncurses.KEY_MOVE: // move key
	case goncurses.KEY_NEXT: // next key
	case goncurses.KEY_OPEN: // open key
	case goncurses.KEY_OPTIONS: // options key
	case goncurses.KEY_PREVIOUS: // previous key
	case goncurses.KEY_REDO: // redo key
	case goncurses.KEY_REFERENCE: // reference key
	case goncurses.KEY_REFRESH: // refresh key
	case goncurses.KEY_REPLACE: // replace key
	case goncurses.KEY_RESTART: // restart key
	case goncurses.KEY_RESUME: // resume key
	case goncurses.KEY_SAVE: // save key
	case goncurses.KEY_SBEG: // shifted begin key
//.........这里部分代码省略.........
开发者ID:apcera,项目名称:sample-apps,代码行数:101,代码来源:chatwin.go

示例6: inputHandler

// handles keyboard input
func inputHandler(inputWin *gc.Window, stdscr *gc.Window, contactsMenuWin *gc.Window, contactMenu *gc.Menu, msgWin *gc.Window) {
	var NLlocate = map[int]newLine{}
	var c gc.Char
	var rawInput gc.Key
	max_y, max_x := inputWin.MaxYX()
	for {
		rawInput = inputWin.GetChar()
		c = gc.Char(rawInput)
		// debugLog.Println(rawInput)
		// debugLog.Println(c)

		//Escape to Quit
		if c == gc.Char(27) {
			break
		} else if rawInput == gc.KEY_BACKSPACE || c == gc.Char(127) {
			//Delete Key
			y, x := inputWin.CursorYX()
			var del = byte('F')
			if x != 0 {
				inputWin.MoveDelChar(y, x-1)
				del = inputBuffer[placer]
				copy(inputBuffer[placer:len(inputBuffer)-1], inputBuffer[placer+1:])
				inputBuffer = inputBuffer[0 : len(inputBuffer)-1]
				placer--
				if del != byte('\n') && NLlocate[y+scroll]._cursorX > x {
					temp := newLine{NLlocate[y+scroll]._cursorX - 1, NLlocate[y+scroll]._placer - 1}
					NLlocate[y+scroll] = temp
				}
				//debugLog.Println(inputBuffer)
			} else if y != 0 { //when x==0 and y!=0
				inputWin.Move(y-1, max_x-1)
				inputWin.MoveDelChar(y-1, max_x-1)
				del = inputBuffer[placer]
				copy(inputBuffer[placer:len(inputBuffer)-1], inputBuffer[placer+1:])
				inputBuffer = inputBuffer[0 : len(inputBuffer)-1]
				//debugLog.Println(inputBuffer)
				placer--
			}
			if del == byte('\n') {
				inputWin.Erase()
				inputWin.Print(string(inputBuffer))
				inputWin.Move(y-1, NLlocate[y-1+scroll]._cursorX)
				temp, check := NLlocate[y+scroll]
				var temp_cursor = temp._cursorX
				var temp_placer = temp._placer
				if check && NLlocate[y-1+scroll]._cursorX+temp_cursor >= max_x {
					_newLine := newLine{NLlocate[y-1+scroll]._cursorX + temp_cursor - max_x, NLlocate[y+scroll]._placer - 1}
					NLlocate[y+scroll] = _newLine
					delete(NLlocate, y-1)
				} else if check { // check if there are any '\n' this line
					var largest = -1          // if yes, select all '\n' and move
					for i := range NLlocate { // placer by 1 and adjust cursor
						if i >= y+scroll { // accordingly
							if next_nl, ok := NLlocate[i+1]; ok {
								new_nl := newLine{next_nl._cursorX, next_nl._placer - 1}
								NLlocate[i] = new_nl
							}
						}
						if i > largest {
							largest = i
						}
					}
					delete(NLlocate, largest) // delete last map entry
					_newLine := newLine{NLlocate[y-1+scroll]._cursorX + temp_cursor, NLlocate[y-1+scroll]._placer + temp_placer - 1}
					NLlocate[y-1+scroll] = _newLine
				} else {
					delete(NLlocate, y-1+scroll)
				}
			}
		} else if c == gc.KEY_PAGEDOWN {
			//debugLog.Println("HIT DOWN")
			msgWin.Scroll(-10)
			msgWin.Refresh()
			inputWin.Refresh()
		} else if c == gc.KEY_PAGEUP {
			//debugLog.Println("HIT UP")
			msgWin.Scroll(10)
			msgWin.Refresh()
			inputWin.Refresh()
		} else if c == gc.KEY_LEFT {
			y, x := inputWin.CursorYX()
			if x != 0 {
				inputWin.Move(y, x-1)
				placer--
			} else if y != 0 {
				inputWin.Move(y-1, max_x-1)
				placer--
			}
			if len(inputBuffer) > 0 && inputBuffer[placer+1] == byte('\n') {
				inputWin.Move(y-1, NLlocate[y-1+scroll]._cursorX)
			}
		} else if c == gc.KEY_RIGHT {
			y, x := inputWin.CursorYX()
			placer++
			if inputBuffer == nil || placer == len(inputBuffer) {
				inputBuffer = append(inputBuffer, byte(' '))
			}
			if inputBuffer[placer] == byte('\n') || x >= max_x-1 {
				inputWin.Move(y+1, 0)
//.........这里部分代码省略.........
开发者ID:AyaTech,项目名称:textsecure-client,代码行数:101,代码来源:input.go


注:本文中的github.com/rthornton128/goncurses.Window.GetChar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。