func initializeNcurses() (stdscr *gc.Window, colors *colorsDefined, resetScreen resetScreenFn) {

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

	// Turn off character echo, hide the cursor and disable input buffering
	gc.Echo(false)
	gc.CBreak(true)
	gc.StartColor()

	// initialize colors
	whiteOnBlack := int16(1)
	gc.InitPair(whiteOnBlack, gc.C_WHITE, gc.C_BLACK)
	greenOnBlack := int16(2)
	gc.InitPair(greenOnBlack, gc.C_GREEN, gc.C_BLACK)
	redOnBlack := int16(3)
	gc.InitPair(redOnBlack, gc.C_RED, gc.C_BLACK)

	// Set the cursor visibility.
	// Options are: 0 (invisible/hidden), 1 (normal) and 2 (extra-visible)
	gc.Cursor(0)

	colors = &colorsDefined{whiteOnBlack, greenOnBlack, redOnBlack}

	return
}
Example #2
0
func main() {
	opts := options.Client{}
	opts.Parse()

	if opts.ServerIP == "" {
		zc := zeroconf.NewClient("_goptyscreen._tcp.")
		zc.Dial()
		opts.ServerIP = zc.Host
		opts.Port = zc.Port
	}

	defer goncurses.End()
	_, err := goncurses.Init()
	if err != nil {
		panic(err)
	}

	goncurses.Cursor(0) // no cursor please
	goncurses.StartColor()

	list := pty_client.NewList(opts.ServerIP, opts.Port)
	list.Fetch()
	key_port, screen_port := list.GetSelection()
	goncurses.End()

	pty_client.Connect(opts.ServerIP, key_port, screen_port)
}
Example #3
0
func NewSupervisor() (supervisor *Supervisor) {
	supervisor = new(Supervisor)

	defer goncurses.End()
	_, err := goncurses.Init()
	if err != nil {
		panic(err)
	}

	goncurses.Cursor(2) // high visibilty cursor
	goncurses.StartColor()

	supervisor.list_window = supervisor_views.NewList()
	supervisor.command_window = supervisor_views.NewCommand()

	supervisor.list_window.Refresh()
	supervisor.command_window.Refresh()

	return
}
func main() {
	s, err := gc.Init()
	if err != nil {
		log.Fatal("init:", err)
	}
	defer gc.End()
	// determine color support
	if !gc.HasColors() {
		log.Fatal("no color support")
	}
	// set background color
	gc.StartColor()
	gc.InitPair(1, gc.C_WHITE, gc.C_BLUE)
	s.ColorOn(1)
	s.SetBackground(gc.Char(' ') | gc.ColorPair(1))
	// blinking, different background color
	s.AttrOn(gc.A_BLINK)
	gc.InitPair(2, gc.C_WHITE, gc.C_RED)
	s.ColorOn(2)
	s.Print("   Blinking Red   ")
	s.GetChar()
}
func main() {
	s, err := gc.Init()
	if err != nil {
		log.Fatal("init:", err)
	}
	defer gc.End()
	gc.StartColor()
	const (
		red   = 1
		green = 2
		blue  = 3
	)
	gc.InitPair(red, gc.C_RED, gc.C_BLACK)
	gc.InitPair(green, gc.C_GREEN, gc.C_BLACK)
	gc.InitPair(blue, gc.C_BLUE, gc.C_BLACK)
	s.ColorOn(red)
	s.Println("Red")
	s.ColorOn(green)
	s.Println("Green")
	s.ColorOn(blue)
	s.Println("Blue")
	s.GetChar()
}
Example #6
0
func main() {
	stdscr, _ := gc.Init()
	defer gc.End()

	yMAX, xMAX := stdscr.MaxYX()
	yMAX = yMAX - 5
	xMAX = xMAX - 5

	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{
		" P  - 152.111.192.51",
		" W  - 152.111.192.52",
		" E  - 152.111.192.53",
		" R  - 152.111.192.54",
		" T  - 152.111.192.55",
		"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(yMAX, xMAX, 1, 1)
	menuwin.Keypad(true)

	menu.SetWindow(menuwin)
	//dwin := menuwin.Derived(6, 38, 3, 1)

	//menu.SubWindow(dwin)
	menu.Option(gc.O_SHOWDESC, true)
	menu.Format(5, 2)
	menu.Mark("*")

	// MovePrint 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(4, 1, gc.ACS_HLINE, WIDTH-2)
	//  menuwin.HLine(12, 10, 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()

		ch := menuwin.GetChar()

		if ch == 'p' {

			cmd2 := exec.Command("clear")
			cmd2.Stdout = os.Stdout
			cmd2.Stdin = os.Stdin
			//cmd2.Stderr = os.Stderr
			cmd2.Run()

			cmd := exec.Command("ssh", "[email protected]")
			cmd.Stdout = os.Stdout
			cmd.Stdin = os.Stdin
			cmd.Stderr = os.Stderr

			cmd.Run()
			return

		} else if ch == 'q' {
			return
		} else if ch == 27 {
			return
		} else {
			menu.Driver(gc.DriverActions[ch])
		}
	}
}