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
}
Beispiel #2
0
func (view *View) RunForever() string {
	window, err := goncurses.Init()
	view.Window = window
	if err != nil {
		panic(err)
	}
	defer goncurses.End()

	goncurses.CBreak(true)
	goncurses.Echo(false)
	window.Clear()
	var ch goncurses.Key

	view.InitPaint()

	for {
		ch = window.GetChar()
		if ch == 'q' {
			break
		}

		if handler, ok := HandlerMap[ch]; ok {
			handler(view.World)
		}
		view.World.RunMonsterActions()
		if view.World.Player.Hitpoints <= 0 {
			return "You have been slain!"
		}
		if len(view.World.AliveMonsters()) == 0 {
			return "You have vanquished all the monsters!"
		}
		view.Paint()
	}
	return ""
}
func main() {
	s, err := gc.Init()
	if err != nil {
		log.Fatal("init:", err)
	}
	defer gc.End()
	gc.Cursor(0)
	s.Move(20, 0)
	s.Print("Key check in ")
	for i := 3; i >= 1; i-- {
		s.MovePrint(20, 13, i)
		s.Refresh()
		time.Sleep(500 * time.Millisecond)
	}
	s.Println()
	gc.Echo(false)

	// task requirement next two lines
	s.Timeout(0)
	k := s.GetChar()

	if k == 0 {
		s.Println("No key pressed")
	} else {
		s.Println("You pressed", gc.KeyString(k))
	}
	s.Refresh()
	s.Timeout(-1)
	gc.FlushInput()
	gc.Cursor(1)
	s.GetChar()
}
Beispiel #4
0
func main() {
	scr, _ := gc.Init()
	defer gc.End()

	rows, cols := scr.Maxyx()

	gc.InitPair(ChatAreaColor, gc.C_WHITE, gc.C_BLACK)
	gc.InitPair(InputAreaColor, gc.C_BLACK, gc.C_WHITE)

	chatArea := scr.Derived(rows-1, cols, 0, 0)
	chatArea.SetBackground(gc.Character(' ' | gc.ColorPair(ChatAreaColor)))

	inputArea := scr.Derived(1, cols, rows-1, 0)
	chatArea.SetBackground(gc.Character(' ' | gc.ColorPair(InputAreaColor)))

	chat := make(chan string)
	go func() {
		for msg := range chat {
			msg = fmt.Sprintf("%v| %v", time.Now().Format("15:04:05"), msg)
			chatArea.Scroll(1)
			chatArea.MovePrint(rows-2, 0, msg)
			chatArea.Refresh()
		}
	}()
	defer close(chat)

	userInputChan := make(chan string)
	go func() {
		for msg := range userInputChan {
			if len(msg) > 0 && msg[0] == '/' {
				chat <- fmt.Sprintf("Command: %s", msg[1:])
			} else {
				chat <- msg
			}
		}
	}()
	defer close(userInputChan)

	gc.Echo(false)
	gc.CBreak(true)
	gc.Raw(true)
	chatArea.ScrollOk(true)
	scr.Keypad(true)

	chat <- "Welcome to snails shitty chat thing."
	chat <- "Press esc to quit, it may or may not break stuff. "
	chat <- "If it does, do a 'reset' to fix it."
	buffer := ""
	for {
		chatArea.Refresh()
		key := inputArea.GetChar()
		switch key {
		case gc.Key(27):
			return
		case gc.KEY_RETURN:
			userInputChan <- buffer
			buffer = ""
			chatArea.Refresh()
		case gc.Key(127): //backspace
			l := len(buffer)
			if l > 0 {
				buffer = buffer[:l-1]
			}
		default:
			buffer = fmt.Sprintf("%s%c", buffer, key)
		}
		inputArea.Clear()
		inputArea.MovePrint(0, 0, buffer)
	}

}
Beispiel #5
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])
		}
	}
}