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) } } }
func createFileList(stdscr *gc.Window) *gc.Menu { // build the menu items menu_items := getFiles() items := make([]*gc.MenuItem, len(menu_items)) i := 0 for key, val := range menu_items { items[i], _ = gc.NewItem(key, val) // defer items[i].Free() i++ } menu, _ := gc.NewMenu(items) defer menu.Free() rows, cols := stdscr.MaxYX() // menuwin, _ := gc.NewWindow(rows, cols/2, 3, 1) menuwin, _ := gc.NewWindow(rows, cols/2, 0, 0) menuwin.Keypad(true) menu.SetWindow(menuwin) dwin := menuwin.Derived(29, 50, 3, 1) menu.SubWindow(dwin) menu.Option(gc.O_SHOWDESC, true) menu.Mark(" * ") menu.Option(gc.O_ONEVALUE, false) // Print centered menu title _, x := menuwin.MaxYX() title := "My Menu" menuwin.Box(0, 0) menuwin.ColorOn(1) menuwin.MovePrint(1, (x/2)-(len(title)/2), title) menuwin.ColorOff(1) menuwin.MoveAddChar(2, 0, gc.ACS_LTEE) menuwin.HLine(2, 1, gc.ACS_HLINE, x-3) menuwin.MoveAddChar(2, x-2, gc.ACS_RTEE) gc.NewPanel(menuwin) menu.Post() //defer menu.UnPost() menu.Window().Refresh() return menu }
func main() { stdscr, _ := gc.Init() 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) // build the menu items menu_items := []string{"Choice 1", "Choice 2", "Choice 3", "Choice 4", "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() menuwin, _ := gc.NewWindow(10, 40, 4, 14) menuwin.Keypad(true) menu.SetWindow(menuwin) dwin := menuwin.Derived(6, 38, 3, 1) menu.SubWindow(dwin) menu.Mark(" * ") // Print centered menu title y, x := menuwin.MaxYX() title := "My Menu" menuwin.Box(0, 0) menuwin.ColorOn(1) menuwin.MovePrint(1, (x/2)-(len(title)/2), title) menuwin.ColorOff(1) menuwin.MoveAddChar(2, 0, gc.ACS_LTEE) menuwin.HLine(2, 1, gc.ACS_HLINE, x-3) menuwin.MoveAddChar(2, x-2, gc.ACS_RTEE) y, x = stdscr.MaxYX() stdscr.MovePrint(y-2, 1, "'q' to exit") stdscr.Refresh() menu.Post() defer menu.UnPost() menuwin.Refresh() for { gc.Update() ch := menuwin.GetChar() switch ch { case 'q': return case gc.KEY_DOWN: menu.Driver(gc.REQ_DOWN) case gc.KEY_UP: menu.Driver(gc.REQ_UP) } } }
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]) } } }
func main() { stdscr, _ := gc.Init() 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_CYAN, gc.C_BLACK) // build the menu items menu_items := []string{ "Choice 1", "Choice 2", "Choice 3", "Choice 4", "Choice 5", "Choice 6", "Choice 7", "Choice 8", "Choice 9", "Choice 10", "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() menuwin, _ := gc.NewWindow(HEIGHT, WIDTH, 4, 14) menuwin.Keypad(true) menu.SetWindow(menuwin) dwin := menuwin.Derived(6, 38, 3, 1) menu.SubWindow(dwin) menu.Format(5, 1) menu.Mark(" * ") // Print centered menu title title := "My Menu" menuwin.Box(0, 0) menuwin.ColorOn(1) menuwin.MovePrint(1, (WIDTH/2)-(len(title)/2), title) menuwin.ColorOff(1) menuwin.MoveAddChar(2, 0, gc.ACS_LTEE) menuwin.HLine(2, 1, gc.ACS_HLINE, WIDTH-2) menuwin.MoveAddChar(2, WIDTH-1, gc.ACS_RTEE) y, _ := stdscr.MaxYX() stdscr.ColorOn(2) stdscr.MovePrint(y-3, 1, "Use up/down arrows or page up/down to navigate. 'q' to exit") stdscr.ColorOff(2) stdscr.Refresh() menu.Post() defer menu.UnPost() menuwin.Refresh() for { gc.Update() if ch := menuwin.GetChar(); ch == 'q' { return } else { menu.Driver(gc.DriverActions[ch]) } } }