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
}
Esempio n. 2
0
func (command *Command) init_colors() {
	command.prompt_color = 10
	err := goncurses.InitPair(command.prompt_color, goncurses.C_MAGENTA, goncurses.C_BLACK)
	if err != nil {
		panic(err)
	}

	command.error_color = 11
	err = goncurses.InitPair(command.error_color, goncurses.C_RED, goncurses.C_BLACK)
	if err != nil {
		panic(err)
	}
}
Esempio n. 3
0
func (list *List) init_colors() {
	list.header_color = 20
	err := goncurses.InitPair(list.header_color, goncurses.C_MAGENTA, goncurses.C_BLACK)
	if err != nil {
		panic(err)
	}
}
Esempio n. 4
0
func (list *List) init_colors() {
	list.header_color = 20
	err := goncurses.InitPair(list.header_color, goncurses.C_MAGENTA, goncurses.C_BLACK)
	if err != nil {
		panic(err)
	}

	list.error_color = 21
	err = goncurses.InitPair(list.error_color, goncurses.C_RED, goncurses.C_BLACK)
	if err != nil {
		panic(err)
	}

	list.selection_color = 22
	err = goncurses.InitPair(list.selection_color, goncurses.C_BLACK, goncurses.C_WHITE)
	if err != nil {
		panic(err)
	}
}
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()
}
Esempio n. 7
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)
	}

}