Exemplo n.º 1
0
//sets up the initial configuration of curses. Keeps code in main cleaner.
func configCurses(stdscr *gc.Window) {
	if !gc.HasColors() {
		log.Fatal("Example requires a colour capable terminal")
	}
	if err := gc.StartColor(); err != nil {
		log.Fatal("Starting Colors failed:", err)
	}
	gc.Echo(false)

	if err := gc.InitPair(1, gc.C_RED, gc.C_BLACK); err != nil {
		log.Fatal("InitPair failed: ", err)
	}
	gc.InitPair(2, gc.C_BLUE, gc.C_BLACK)
	gc.InitPair(3, gc.C_GREEN, gc.C_BLACK)
	gc.InitPair(4, gc.C_YELLOW, gc.C_BLACK)
	gc.InitPair(5, gc.C_CYAN, gc.C_BLACK)
	gc.InitPair(6, gc.C_MAGENTA, gc.C_WHITE)
	gc.InitPair(7, gc.C_MAGENTA, gc.C_BLACK)

	//set background color to black
	stdscr.SetBackground(gc.Char(' ') | gc.ColorPair(0))

	stdscr.Keypad(true)
	gc.Cursor(1)
	gc.CBreak(true)
	stdscr.Clear()
}
Exemplo n.º 2
0
func (v *CursesView) initCursesColors() (err error) {
	if v.colored = cur.HasColors(); !v.colored {
		return
	}
	if err := cur.StartColor(); err != nil {
		log.Print(err)
	}
	if err := cur.UseDefaultColors(); err != nil {
		log.Print(err)
	}

	colorMap := []int16{
		cur.C_WHITE,
		cur.C_BLUE,
		cur.C_GREEN,
		cur.C_YELLOW,
		cur.C_CYAN,
		cur.C_RED,
	}
	for i, c := range colorMap {

		if e := cur.InitPair(int16(i), c, cur.C_BLACK); e != nil {
			log.Printf("InitPair(%d, %v, %v) failed: %v", i, colorMap[i], cur.C_BLACK, e)
		}
		if e := cur.InitPair(int16(i+len(colorMap)), cur.C_BLACK, colorMap[i]); e != nil {
			log.Printf("InitPair(%d, %v, %v) failed: %v", i, colorMap[i], cur.C_BLACK, e)
		}
	}
	return
}
Exemplo n.º 3
0
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()
}
Exemplo n.º 4
0
func (ui *NcurseUi) initColors() {
	if goncurses.HasColors() {
		err := goncurses.StartColor()
		HandleErr(err)

		goncurses.UseDefaultColors()

		//Main window
		goncurses.InitPair(1, goncurses.C_WHITE, -1)
		goncurses.InitPair(2, goncurses.C_RED, -1)
		goncurses.InitPair(3, goncurses.C_GREEN, -1)
		goncurses.InitPair(4, goncurses.C_CYAN, -1)

		//Title colors
		goncurses.InitPair(10, goncurses.C_BLACK, goncurses.C_BLUE)

		//Menu colors
		goncurses.InitPair(20, goncurses.C_YELLOW, -1)
	}
}