예제 #1
0
파일: kvmtop.go 프로젝트: cha87de/kvmtop
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()))
	}
}
예제 #2
0
파일: init.go 프로젝트: trotha01/goncurses
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()
}
예제 #3
0
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()
}
예제 #4
0
파일: pad.go 프로젝트: trotha01/goncurses
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()
}
예제 #5
0
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
}
예제 #6
0
파일: hello.go 프로젝트: trotha01/goncurses
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()
}
예제 #7
0
파일: ncurses.go 프로젝트: aubm/gotris
func initStdscr() {
	var err error
	stdscr, err = gc.Init()
	if err != nil {
		log.Fatal("init:", err)
	}
	stdscr.NoutRefresh()
}
예제 #8
0
파일: files.go 프로젝트: kuzzmi/monk
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()
}
예제 #9
0
// 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)
}
예제 #10
0
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()
}
예제 #11
0
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
			}
		}
	}
}
예제 #12
0
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
		}
	}
}
예제 #13
0
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()
		}
	}
}
예제 #14
0
파일: screen.go 프로젝트: Tondorf/gosl
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
}
예제 #15
0
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()
}
예제 #16
0
파일: color.go 프로젝트: trotha01/goncurses
func main() {
	stdscr, err := gc.Init()
	if err != nil {
		log.Fatal("init:", err)
	}
	defer gc.End()

	// HasColors can be used to determine whether the current terminal
	// has the capability of using colours. You could then chose whether or
	// not to use some other mechanism, like using A_REVERSE, instead
	if !gc.HasColors() {
		log.Fatal("Example requires a colour capable terminal")
	}

	// Must be called after Init but before using any colour related functions
	if err := gc.StartColor(); err != nil {
		log.Fatal(err)
	}

	gc.Echo(false)

	// Initialize a colour pair. Should only fail if an improper pair value
	// is given
	if err := gc.InitPair(1, gc.C_RED, gc.C_WHITE); err != nil {
		log.Fatal("InitPair failed: ", err)
	}
	gc.InitPair(2, gc.C_BLACK, gc.C_CYAN)

	stdscr.Println("Type any key to proceed and again to exit")

	// An example of trying to set an invalid color pair
	err = gc.InitPair(-1, gc.C_BLACK, gc.C_CYAN)
	stdscr.Println("An intentional error:", err)

	stdscr.Keypad(true)
	stdscr.MovePrint(12, 30, "Hello, World!!!")
	stdscr.Refresh()
	stdscr.GetChar()
	// Note that background doesn't just accept colours but will fill
	// any blank positions with the supplied character too. Note that newly
	// added text with spaces in it will have the blanks converted to the fill
	// character, if given
	stdscr.SetBackground(gc.Char('*') | gc.ColorPair(2))
	// ColorOn/Off is a shortcut to calling AttrOn/Off(gc.ColorPair(pair))
	stdscr.ColorOn(1)
	stdscr.MovePrint(13, 30, "Hello, World in Color!!!")
	stdscr.ColorOff(1)
	stdscr.Refresh()
	stdscr.GetChar()
}
예제 #17
0
파일: acs.go 프로젝트: trotha01/goncurses
func main() {
	stdscr, err := gc.Init()
	if err != nil {
		log.Fatal(err)
	}
	defer gc.End()

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

	stdscr.Print("A reversed plus-minus symbol: ")
	stdscr.AddChar(gc.ACS_PLMINUS | gc.A_REVERSE)
	stdscr.Refresh()
	stdscr.GetChar()
}
예제 #18
0
func NewCursesView() (i view.Interface, err error) {
	v := new(CursesView)
	if v.win, err = cur.Init(); err != nil {
		return
	}
	cur.Echo(false)
	cur.Cursor(0)

	if err = v.initCursesColors(); err != nil {
		return
	}

	i = v
	return
}
예제 #19
0
func main() {
	stdscr, err := gc.Init()
	if err != nil {
		log.Fatal(err)
	}
	defer gc.End()

	gc.StartColor()
	gc.Echo(false)
	gc.Raw(true)

	var colours = []int16{gc.C_BLACK, gc.C_BLUE, gc.C_CYAN, gc.C_GREEN,
		gc.C_MAGENTA, gc.C_RED, gc.C_WHITE, gc.C_YELLOW}
	var attributes = []struct {
		attr gc.Char
		text string
	}{
		{gc.A_NORMAL, "normal"},
		{gc.A_STANDOUT, "standout"},
		{gc.A_UNDERLINE | gc.A_BOLD, "underline"},
		{gc.A_REVERSE, "reverse"},
		{gc.A_BLINK, "blink"},
		{gc.A_DIM, "dim"},
		{gc.A_BOLD, "bold"},
	}
	stdscr.MovePrint(0, 0, "Normal terminal colors: ")
	for i, c := range colours {
		gc.InitPair(int16(i), c, c)
		stdscr.ColorOn(int16(i))
		stdscr.AddChar(' ')
		stdscr.ColorOff(int16(i))
	}
	stdscr.MovePrint(1, 0, "Bold terminal colors:   ")
	stdscr.AttrOn(gc.A_BLINK)
	for i, _ := range colours {
		stdscr.ColorOn(int16(i))
		stdscr.AddChar(' ')
		stdscr.ColorOff(int16(i))
	}
	stdscr.AttrOff(gc.A_BLINK)
	stdscr.Move(2, 0)
	for _, a := range attributes {
		stdscr.AttrOn(a.attr)
		stdscr.Println(a.text)
		stdscr.AttrOff(a.attr)
	}
	stdscr.GetChar()
}
예제 #20
0
파일: print.go 프로젝트: trotha01/goncurses
func main() {
	stdscr, _ := gc.Init()
	defer gc.End()

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

	stdscr.MovePrintf(row-3, 0, "This screen has %d rows and %d columns. ",
		row, col)
	stdscr.Println()
	stdscr.Print("Try resizing your terminal window and then " +
		"run this program again.")
	stdscr.Refresh()
	stdscr.GetChar()
}
예제 #21
0
파일: menu.go 프로젝트: trotha01/goncurses
func main() {
	stdscr, err := goncurses.Init()
	if err != nil {
		log.Fatal("init:", err)
	}
	defer goncurses.End()

	goncurses.Raw(true)
	goncurses.Echo(false)
	goncurses.Cursor(0)
	stdscr.Clear()
	stdscr.Keypad(true)

	menu_items := []string{"Choice 1", "Choice 2", "Choice 3", "Choice 4",
		"Exit"}
	items := make([]*goncurses.MenuItem, len(menu_items))
	for i, val := range menu_items {
		items[i], _ = goncurses.NewItem(val, "")
		defer items[i].Free()
	}

	menu, err := goncurses.NewMenu(items)
	if err != nil {
		stdscr.Print(err)
		return
	}
	defer menu.Free()

	menu.Post()

	stdscr.MovePrint(20, 0, "'q' to exit")
	stdscr.Refresh()

	for {
		goncurses.Update()
		ch := stdscr.GetChar()

		switch goncurses.KeyString(ch) {
		case "q":
			return
		case "down":
			menu.Driver(goncurses.REQ_DOWN)
		case "up":
			menu.Driver(goncurses.REQ_UP)
		}
	}
}
예제 #22
0
func main() {
	scr, err := gc.Init()
	if err != nil {
		log.Fatal("init:", err)
	}
	defer gc.End()

	gc.Echo(false)

	scr.Println("Type characters to have them appear on the screen.")
	scr.Println("Press 'q' to exit.")
	scr.Println()

	// Accept input concurrently via a goroutine and connect a channel
	in := make(chan gc.Char)
	ready := make(chan bool)
	go func(w *gc.Window, ch chan<- gc.Char) {
		for {
			// Block until all write operations are complete
			<-ready
			// Send typed character down the channel (which is blocking
			// in the main loop)
			ch <- gc.Char(w.GetChar())
		}
	}(scr, in)

	// Once a character has been received on the 'in' channel the
	// 'ready' channel will block until it recieves another piece of data.
	// This happens only once the received character has been written to
	// the screen. The 'in' channel then blocks on the next loop until
	// another 'true' is sent down the 'ready' channel signalling to the
	// input goroutine that it's okay to receive input
	for {
		var c gc.Char
		select {
		case c = <-in: // blocks while waiting for input from goroutine
			scr.Print(string(c))
			scr.Refresh()
		case ready <- true: // sends once above block completes
		}
		// Exit when 'q' is pressed
		if c == gc.Char('q') {
			break
		}
	}
}
예제 #23
0
파일: screen.go 프로젝트: Tondorf/gosl
func InitNC(killchan chan<- os.Signal) {
	var err error
	winMutex.Lock()
	win, err = nc.Init()
	if err != nil {
		log.Fatal(err)
		os.Exit(1)
	}
	win.Timeout(1)
	winMutex.Unlock()
	go func() {
		select {
		case <-ncquit:
			log.Println("Exiting NC")
			killchan <- os.Kill
		}
	}()
}
예제 #24
0
파일: panel.go 프로젝트: trotha01/goncurses
func main() {
	stdscr, _ := gc.Init()
	defer gc.End()

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

	for i := 0; i < 3; i++ {
		window, _ := gc.NewWindow(10, 40, y+i, x+(i*5))
		window.Box(0, 0)
		panels[i] = gc.NewPanel(window)
	}

	gc.UpdatePanels()
	gc.Update()

	stdscr.GetChar()
}
예제 #25
0
파일: slk.go 프로젝트: trotha01/goncurses
func main() {
	gc.SlkInit(gc.SLK_323)
	scr, err := gc.Init()
	if err != nil {
		log.Fatal("INIT:", err)
	}
	defer gc.End()

	gc.StartColor()
	gc.InitPair(SOFTKEYS, gc.C_YELLOW, gc.C_BLUE)

	scr.Print("Type any key to exit...")
	labels := [...]string{"ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN",
		"EIGHT"}
	for i := range labels {
		gc.SlkSet(i+1, labels[i], gc.SLK_CENTER)
	}
	gc.SlkColor(SOFTKEYS)
	gc.SlkNoutRefresh()
	scr.Refresh()
	scr.GetChar()
}
예제 #26
0
파일: hncli.go 프로젝트: kawakami-o3/hn
//Returns an instance of the CLI. Call once
func GetCli() hncli {
	if !singleDone {
		hc = hncli{}

		root, e := goncurses.Init()

		if e != nil {
			goncurses.End()
			log.Fatal(e)
		}

		h, w := root.MaxYX()

		hc.root = root
		hc.main = root.Sub(h-MENU_HEIGHT, w, 0, 0)
		hc.help = root.Sub(MENU_HEIGHT, w, h-MENU_HEIGHT, 0)

		hc.Height = h - MENU_HEIGHT

		singleDone = true
	}

	return hc
}
예제 #27
0
func main() {
	stdscr, _ := gc.Init()
	defer gc.End()

	gc.StartColor()
	gc.Raw(true)
	gc.Echo(false)
	gc.Cursor(0)
	stdscr.Keypad(true)

	// build the menu items
	menu_items := []string{
		"Choice 1",
		"Choice 2",
		"Choice 3",
		"Choice 4",
		"Choice 5",
		"Choice 6",
		"Choice 7",
		"Exit"}
	items := make([]*gc.MenuItem, len(menu_items))
	for i, val := range menu_items {
		items[i], _ = gc.NewItem(val, "")
		defer items[i].Free()
	}

	// create the menu
	menu, _ := gc.NewMenu(items)
	defer menu.Free()

	menu.Option(gc.O_ONEVALUE, false)

	y, _ := stdscr.MaxYX()
	stdscr.MovePrint(y-3, 0, "Use up/down arrows to move, spacebar to "+
		"toggle and enter to print. 'q' to exit")
	stdscr.Refresh()

	menu.Post()
	defer menu.UnPost()

	for {
		gc.Update()
		ch := stdscr.GetChar()

		switch ch {
		case 'q':
			return
		case ' ':
			menu.Driver(gc.REQ_TOGGLE)
		case gc.KEY_RETURN, gc.KEY_ENTER:
			var list string
			for _, item := range menu.Items() {
				if item.Value() {
					list += "\"" + item.Name() + "\" "
				}
			}
			stdscr.Move(20, 0)
			stdscr.ClearToEOL()
			stdscr.MovePrint(20, 0, list)
			stdscr.Refresh()
		default:
			menu.Driver(gc.DriverActions[ch])
		}
	}
}
예제 #28
0
func main() {
	stdscr, err := gc.Init()
	if err != nil {
		log.Fatal("init:", err)
	}
	defer gc.End()

	gc.StartColor()
	gc.Raw(true)
	gc.Echo(false)
	gc.Cursor(0)
	stdscr.Keypad(true)
	gc.InitPair(1, gc.C_RED, gc.C_BLACK)
	gc.InitPair(2, gc.C_GREEN, gc.C_BLACK)
	gc.InitPair(3, gc.C_MAGENTA, gc.C_BLACK)

	// build the menu items
	menu_items := []string{
		"Choice 1",
		"Choice 2",
		"Choice 3",
		"Choice 4",
		"Choice 5",
		"Exit"}
	items := make([]*gc.MenuItem, len(menu_items))
	for i, val := range menu_items {
		items[i], _ = gc.NewItem(val, "")
		defer items[i].Free()

		if i == 2 || i == 4 {
			items[i].Selectable(false)
		}
	}

	// create the menu
	menu, _ := gc.NewMenu(items)
	defer menu.Free()

	y, _ := stdscr.MaxYX()
	stdscr.MovePrint(y-3, 0, "Use up/down arrows to move; 'q' to exit")
	stdscr.Refresh()

	menu.SetForeground(gc.ColorPair(1) | gc.A_REVERSE)
	menu.SetBackground(gc.ColorPair(2) | gc.A_BOLD)
	menu.Grey(gc.ColorPair(3) | gc.A_BOLD)

	menu.Post()
	defer menu.UnPost()

	for {
		gc.Update()
		ch := stdscr.GetChar()
		switch ch {
		case ' ':
			menu.Driver(gc.REQ_TOGGLE)
		case 'q':
			return
		case gc.KEY_RETURN:
			stdscr.Move(20, 0)
			stdscr.ClearToEOL()
			stdscr.Printf("Item selected is: %s", menu.Current(nil).Name())
			menu.PositionCursor()
		default:
			menu.Driver(gc.DriverActions[ch])
		}
	}
}
예제 #29
0
func main() {
	f, err := os.Create("err.log")
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	log.SetOutput(f)

	var stdscr *gc.Window
	stdscr, err = gc.Init()
	if err != nil {
		log.Println("Init:", err)
	}
	defer gc.End()

	rand.Seed(time.Now().Unix())
	gc.StartColor()
	gc.Cursor(0)
	gc.Echo(false)
	gc.HalfDelay(1)

	gc.InitPair(1, gc.C_WHITE, gc.C_BLACK)
	gc.InitPair(2, gc.C_YELLOW, gc.C_BLACK)
	gc.InitPair(3, gc.C_MAGENTA, gc.C_BLACK)
	gc.InitPair(4, gc.C_RED, gc.C_BLACK)

	gc.InitPair(5, gc.C_BLUE, gc.C_BLACK)
	gc.InitPair(6, gc.C_GREEN, gc.C_BLACK)

	lines, cols := stdscr.MaxYX()
	pl, pc := lines, cols*3

	ship := newShip(lines/2, 5)
	objects = append(objects, ship)

	field := genStarfield(pl, pc)
	text := stdscr.Duplicate()

	c := time.NewTicker(time.Second / 2)
	c2 := time.NewTicker(time.Second / 16)
	px := 0

loop:
	for {
		text.MovePrintf(0, 0, "Life: [%-5s]", lifeToText(ship.life))
		stdscr.Erase()
		stdscr.Copy(field.Window, 0, px, 0, 0, lines-1, cols-1, true)
		drawObjects(stdscr)
		stdscr.Overlay(text)
		stdscr.Refresh()
		select {
		case <-c.C:
			spawnAsteroid(stdscr.MaxYX())
			if px+cols >= pc {
				break loop
			}
			px++
		case <-c2.C:
			updateObjects(stdscr.MaxYX())
			drawObjects(stdscr)
		default:
			if !handleInput(stdscr, ship) || ship.Expired(-1, -1) {
				break loop
			}
		}
	}
	msg := "Game Over"
	end, err := gc.NewWindow(5, len(msg)+4, (lines/2)-2, (cols-len(msg))/2)
	if err != nil {
		log.Fatal("game over:", err)
	}
	end.MovePrint(2, 2, msg)
	end.Box(gc.ACS_VLINE, gc.ACS_HLINE)
	end.Refresh()
	gc.Nap(2000)
}
예제 #30
0
파일: window.go 프로젝트: kuzzmi/monk
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()
}