Ejemplo n.º 1
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
			}
		}
	}
}
func createWindow(height int, width int, y int, x int) (win *gc.Window) {
	win, err := gc.NewWindow(height, width, y, x)
	if err != nil {
		log.Fatal(err)
	}
	return
}
Ejemplo n.º 3
0
func NewCommand() (command *Command) {
	command = new(Command)
	win_height, win_width := goncurses.StdScr().Maxyx()
	window, err := goncurses.NewWindow(3, win_width, win_height-3, 0)
	if err != nil {
		panic(err)
	}

	command.init_colors()

	command.Window = &window
	command.clear()
	return
}
Ejemplo n.º 4
0
func NewList() (list *List) {
	list = new(List)
	win_height, win_width := goncurses.StdScr().Maxyx()
	window, err := goncurses.NewWindow(win_height-3, win_width, 0, 0)
	if err != nil {
		panic(err)
	}

	list.Window = &window
	list.items = make(map[string]*pty_servers.PtyShare)
	list.init_colors()
	list.draw_initial()
	return
}
Ejemplo n.º 5
0
func NewList() (list *List) {
	list = new(List)
	win_height, win_width := goncurses.StdScr().Maxyx()
	window, err := goncurses.NewWindow(win_height, win_width, 0, 0)
	if err != nil {
		panic(err)
	}

	list.Window = &window
	list.init_colors()
	list.draw_initial()

	return
}
Ejemplo n.º 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])
		}
	}
}