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


Golang goncurses.Init函数代码示例

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


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

示例1: main

func main() {

	defineFlags()
	if SHOW_VERSION {
		fmt.Println("kvmtop version " + VERSION)
		return
	}
	if !OUT_BATCH {
		screenx, err := goncurses.Init()
		if err != nil {
			log.Fatal("init", err)
		}
		screen = screenx
		defer goncurses.End()
	}

	initialize()
	for n := -1; RUNCOUNT == -1 || n < RUNCOUNT; n++ {
		start := time.Now()
		measureVirtualMachines(n)
		nextRun := start.Add(time.Duration(FREQUENCY) * time.Second)
		updateVirtualMachineLists()
		time.Sleep(nextRun.Sub(time.Now()))
	}
}
开发者ID:cha87de,项目名称:kvmtop,代码行数:25,代码来源:kvmtop.go

示例2: main

func main() {
	stdscr, err := goncurses.Init()
	if err != nil {
		log.Fatal("init", err)
	}
	defer goncurses.End()

	goncurses.Raw(true)   // turn on raw "uncooked" input
	goncurses.Echo(false) // turn echoing of typed characters off
	goncurses.Cursor(0)   // hide cursor
	stdscr.Keypad(true)   // allow keypad input

	stdscr.Print("Press a key...")
	stdscr.Refresh()

	if ch := stdscr.GetChar(); ch == goncurses.KEY_F2 {
		stdscr.Print("The F2 key was pressed.")
	} else {
		stdscr.Print("The key pressed is: ")
		stdscr.AttrOn(goncurses.A_BOLD)
		stdscr.AddChar(goncurses.Char(ch))
		stdscr.AttrOff(goncurses.A_BOLD)
	}
	stdscr.Refresh()
	stdscr.GetChar()
}
开发者ID:trotha01,项目名称:goncurses,代码行数:26,代码来源:init.go

示例3: main

func main() {
	stdscr, err := gc.Init()
	if err != nil {
		log.Fatal("init:", err)
	}
	defer gc.End()

	msg := "Enter a string: "
	row, col := stdscr.MaxYX()
	row, col = (row/2)-1, (col-len(msg))/2
	stdscr.MovePrint(row, col, msg)

	/* GetString will only retieve the specified number of characters. Any
	attempts by the user to enter more characters will elicit an audiable
	beep */
	var str string
	str, err = stdscr.GetString(10)
	if err != nil {
		stdscr.MovePrint(row+1, col, "GetString Error:", err)
	} else {
		stdscr.MovePrintf(row+1, col, "You entered: %s", str)
	}

	stdscr.Refresh()
	stdscr.GetChar()
}
开发者ID:trotha01,项目名称:goncurses,代码行数:26,代码来源:getstr.go

示例4: main

func main() {
	_, err := gc.Init()
	if err != nil {
		log.Fatal(err)
	}
	defer gc.End()

	// create a new pad of 50 rows and 200 columns...
	var pad *gc.Pad
	pad, err = gc.NewPad(50, 200)
	if err != nil {
		log.Fatal(err)
	}
	// ...and fill it with some characters
	for x := 0; x < 50; x++ {
		pad.MovePrint(x, x, "This is a pad.")
	}
	// Refresh the pad to show only a portion of the pad. Understanding
	// what these coordinates mean can be a bit tricky. The first two
	// coordinates are the position in the pad, in this case 0,5 (remember
	// the coordinates in ncurses are y,x). The second set of numbers are the
	// coordinates on the screen on which to display the content, so row 5,
	// column 10. The last set of numbers tell how high and how wide the
	// rectangle to displayed should be, in this case 15 rows long and 25
	// columns wide.
	pad.Refresh(0, 5, 5, 10, 15, 25)
	pad.GetChar()
}
开发者ID:trotha01,项目名称:goncurses,代码行数:28,代码来源:pad.go

示例5: InitNcurseUi

func InitNcurseUi() (ui *NcurseUi) {
	ui = &NcurseUi{}

	var err error
	ui.contents, err = goncurses.Init()
	HandleErr(err)

	y, x := ui.contents.MaxYX()

	ui.initColors()

	ui.contents.Resize(y-1, x-MENU_WIDTH)
	ui.contents.MoveWindow(1, MENU_WIDTH)
	ui.contents.Keypad(true)

	ui.titleBar, err = goncurses.NewWindow(1, x, 0, 0)
	HandleErr(err)
	ui.menuBar, err = goncurses.NewWindow(y-1, MENU_WIDTH, 1, 0)
	HandleErr(err)

	ui.menuBar.Border(' ', '|', ' ', ' ', ' ', '|', ' ', ' ')

	ui.titleBar.ColorOn(10)
	ui.titleBar.SetBackground(goncurses.Char('.') | goncurses.ColorPair(10))

	return
}
开发者ID:FreekingDean,项目名称:Gotex,代码行数:27,代码来源:ncurse.go

示例6: main

func main() {
	// Initialize goncurses. It's essential End() is called to ensure the
	// terminal isn't altered after the program ends
	stdscr, err := goncurses.Init()
	if err != nil {
		log.Fatal("init", err)
	}
	defer goncurses.End()

	// (Go)ncurses draws by cursor position and uses reverse cartisian
	// coordinate system (y,x). Initially, the cursor is positioned at the
	// coordinates 0,0 so the first call to Print will output the text at the
	// top, left position of the screen since stdscr is a window which
	// represents the terminal's screen size.
	stdscr.Print("Hello, World!")
	stdscr.MovePrint(3, 0, "Press any key to continue")

	// Refresh() flushes output to the screen. Internally, it is the same as
	// calling NoutRefresh() on the window followed by a call to Update()
	stdscr.Refresh()

	// GetChar will block execution until an input event, like typing a
	// character on your keyboard, is received
	stdscr.GetChar()
}
开发者ID:trotha01,项目名称:goncurses,代码行数:25,代码来源:hello.go

示例7: initStdscr

func initStdscr() {
	var err error
	stdscr, err = gc.Init()
	if err != nil {
		log.Fatal("init:", err)
	}
	stdscr.NoutRefresh()
}
开发者ID:aubm,项目名称:gotris,代码行数:8,代码来源:ncurses.go

示例8: main

func main() {
	stdscr, err := gc.Init()
	if err != nil {
		log.Fatal(err)
	}
	defer gc.End()

	gc.Echo(false)
	gc.CBreak(true)
	gc.Cursor(0)

	var panels [2]fp.FilePanel
	rows, cols := stdscr.MaxYX()
	height, width := rows, cols/2
	y, x := 0, 0
	activePanel := 0

	panels[0] = fp.FilePanel{Height: height, Width: width, Y: y, X: x, Directory: "./", Selected: 0, IsActive: true}
	panels[1] = fp.FilePanel{Height: height, Width: width, Y: y, X: x + width, Directory: "/home/kuzzmi/", Selected: 2, IsActive: false}

	panels[0].Draw()
	panels[1].Draw()

	gc.UpdatePanels()
	gc.Update()

	stdscr.Keypad(true)
	// stdscr.GetChar()

main:
	for {
		switch panels[activePanel].Panel.Window().GetChar() {
		case 'q':
			break main
		case gc.KEY_RETURN:
			panels[activePanel].Execute()
		case gc.KEY_TAB:
			panels[0].ToggleActivity()
			panels[1].ToggleActivity()
			gc.UpdatePanels()
			gc.Update()
			if activePanel == 0 {
				activePanel = 1
			} else {
				activePanel = 0
			}
		case 'u':
			panels[activePanel].GoUp()
		case 'k':
			panels[activePanel].Select(panels[activePanel].Selected - 1)
		case 'j':
			panels[activePanel].Select(panels[activePanel].Selected + 1)
		case 'i':
			panels[activePanel].HideHidden()
		}
	}
	stdscr.Delete()
}
开发者ID:kuzzmi,项目名称:monk,代码行数:58,代码来源:files.go

示例9: main

// creates a curses based TUI for the textsecure library
func main() {
	stdscr, err := gc.Init()
	if err != nil {
		log.Fatal("Error initializing curses:", err)
	}
	defer gc.End()
	configCurses(stdscr)

	client := &ts.Client{
		GetConfig:           getConfig,
		GetLocalContacts:    getLocalContacts,
		GetVerificationCode: getVerificationCode,
		GetStoragePassword:  passphraseUnlock,
		MessageHandler:      recieveMessage,
		RegistrationDone:    registrationDone,
	}
	err = ts.Setup(client)
	if err != nil {
		log.Fatal("Could not initialize textsecure library", err)
	}

	db = setupDatabase()

	contacts, err := ts.GetRegisteredContacts()
	if err != nil {
		log.Fatal("Could not get contacts: %s\n", err)
	}

	telToName = make(map[string]string)
	for _, c := range contacts {
		telToName[c.Tel] = c.Name
	}
	nameToTel = make(map[string]string)
	for _, c := range contacts {
		nameToTel[c.Name] = c.Tel
	}

	contactsWin, messageWinBorder, msgWin, inputBorderWin, inputWin := createMainWindows(stdscr)
	menu_items, contactMenu, contactsMenuWin := makeContactsMenu(contacts, contactsWin)
	globalInputWin = inputWin
	globalMsgWin = msgWin

	contactsMenuWin.Touch()
	contactMenu.Post()
	contactsWin.Refresh()
	messageWinBorder.Refresh()
	inputBorderWin.Refresh()
	msgWin.Refresh()
	msgWinSize_y, msgWinSize_x = msgWin.MaxYX()

	currentContact = getTel(contactMenu.Current(nil).Name())
	changeContact(contactsMenuWin, contactMenu)
	inputWin.Move(0, 0)
	go ts.StartListening()
	inputHandler(inputWin, stdscr, contactsMenuWin, contactMenu, msgWin)
	cleanup(menu_items, contactMenu)
}
开发者ID:AyaTech,项目名称:textsecure-client,代码行数:58,代码来源:main.go

示例10: main

func main() {
	stdscr, err := gc.Init()
	if err != nil {
		return
	}
	defer gc.End()

	stdscr.Border(gc.ACS_VLINE, gc.ACS_VLINE, gc.ACS_HLINE, gc.ACS_HLINE,
		gc.ACS_ULCORNER, gc.ACS_URCORNER, gc.ACS_LLCORNER, gc.ACS_LRCORNER)
	stdscr.GetChar()
}
开发者ID:trotha01,项目名称:goncurses,代码行数:11,代码来源:border.go

示例11: dialog

func (cw *chatWin) dialog(messages chan message) {
	stdscr, err := goncurses.Init()
	if err != nil {
		log.Fatal("init:", err)
	}
	defer goncurses.End()

	goncurses.Raw(false)
	stdscr.ScrollOk(true)

	rows, cols := stdscr.MaxYX()
	chats, err := goncurses.NewWindow(rows-MESSAGE_WIN_SIZE, cols, 0, 0)
	if err != nil {
		log.Fatal("Error setting up chat window")
	}

	chats.ScrollOk(true)
	chats.Box(goncurses.ACS_VLINE, goncurses.ACS_HLINE)
	chats.Refresh()

	messageWin, err := goncurses.NewWindow(MESSAGE_WIN_SIZE, cols, rows-MESSAGE_WIN_SIZE, 0)
	if err != nil {
		log.Fatal("Error setting up chat window")
	}
	cw.msgRows, cw.msgCols = messageWin.MaxYX()
	// allow special characters to come through (e.g. arrow keys)
	messageWin.Keypad(true)
	// sets terminal to non-blocking
	// this also seems to print characters as they're typed, which causes some weird workarounds
	goncurses.HalfDelay(1)

	messageWin.Print(PROMPT)
	for {
		select {
		case msg := <-messages:
			y, _ := chats.CursorYX()
			chats.MovePrint(y+1, 1, fmt.Sprintf("%s: %s", msg.From, msg.Message))
			chats.Refresh()
			messageWin.Refresh()
		default:
			line := cw.handleInput(messageWin)
			if line != "" {
				log.Println("Entered message:", line)
				msg := message{From: cw.username, Message: line}
				// TODO: uncomment once turnpike is fixed to not send events to the sender
				// y, _ := chats.CursorYX()
				// chats.MovePrint(y+1, 1, fmt.Sprintf("%s: %s", msg.From, msg.Message))
				// chats.Refresh()
				cw.msgs <- msg
			}
		}
	}
}
开发者ID:apcera,项目名称:sample-apps,代码行数:53,代码来源:chatwin.go

示例12: 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

示例13: main

func main() {
	stdscr, _ := gc.Init()
	defer gc.End()

	gc.StartColor()
	gc.CBreak(true)
	gc.Echo(true)
	stdscr.Keypad(true)
	stdscr.Print("Hit 'tab' to cycle through windows, 'q' to quit")

	gc.InitPair(1, gc.C_RED, gc.C_BLACK)
	gc.InitPair(2, gc.C_GREEN, gc.C_BLACK)
	gc.InitPair(3, gc.C_BLUE, gc.C_BLACK)
	gc.InitPair(4, gc.C_CYAN, gc.C_BLACK)

	var panels [3]*gc.Panel
	y, x := 4, 10

	for i := 0; i < 3; i++ {
		h, w := 10, 40
		title := "Window Number %d"

		window, _ := gc.NewWindow(h, w, y+(i*4), x+(i*10))
		window.Box(0, 0)
		window.MoveAddChar(2, 0, gc.ACS_LTEE)
		window.HLine(2, 1, gc.ACS_HLINE, w-2)
		window.MoveAddChar(2, w-1, gc.ACS_RTEE)
		window.ColorOn(int16(i + 1))
		window.MovePrintf(1, (w/2)-(len(title)/2), title, i+1)
		window.ColorOff(int16(i + 1))
		panels[i] = gc.NewPanel(window)

	}

	active := 2

	for {
		gc.UpdatePanels()
		gc.Update()

		switch stdscr.GetChar() {
		case 'q':
			return
		case gc.KEY_TAB:
			active += 1
			if active > 2 {
				active = 0
			}
			panels[active].Top()
		}
	}
}
开发者ID:trotha01,项目名称:goncurses,代码行数:52,代码来源:panel2.go

示例14: GetXY

func GetXY() (int, int) {
	win, err := nc.Init()
	if err != nil {
		log.Fatal(err)
		os.Exit(1)
	}
	win.Clear()
	h, w := win.MaxYX()
	nc.End()
	fmt.Printf("screen: %d x %d\n", w, h)

	return w, h
}
开发者ID:Tondorf,项目名称:gosl,代码行数:13,代码来源:screen.go

示例15: ExampleInit

func ExampleInit() {
	// You should always test to make sure ncurses has initialized properly.
	// In order for your error messages to be visible on the terminal you will
	// need to either log error messages or output them to to stderr.
	stdscr, err := goncurses.Init()
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	defer goncurses.End()
	stdscr.Print("Press enter to continue...")
	stdscr.Refresh()
}
开发者ID:kovetskiy,项目名称:goncurses,代码行数:13,代码来源:example_test.go


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