Exemplo n.º 1
0
func initPairs(baseTheme *ColorTheme, theme *ColorTheme, black bool) {
	fg := override(baseTheme.Fg, theme.Fg)
	bg := override(baseTheme.Bg, theme.Bg)
	if black {
		bg = C.COLOR_BLACK
	} else if theme.UseDefault {
		fg = colDefault
		bg = colDefault
		C.use_default_colors()
	}
	if theme.UseDefault {
		FG = colDefault
		BG = colDefault
	} else {
		FG = int(fg)
		BG = int(bg)
		C.assume_default_colors(C.int(override(baseTheme.Fg, theme.Fg)), C.int(bg))
	}

	currentFG := override(baseTheme.Current, theme.Current)
	darkBG := override(baseTheme.DarkBg, theme.DarkBg)
	CurrentFG = int(currentFG)
	DarkBG = int(darkBG)
	C.init_pair(ColPrompt, override(baseTheme.Prompt, theme.Prompt), bg)
	C.init_pair(ColMatch, override(baseTheme.Match, theme.Match), bg)
	C.init_pair(ColCurrent, currentFG, darkBG)
	C.init_pair(ColCurrentMatch, override(baseTheme.CurrentMatch, theme.CurrentMatch), darkBG)
	C.init_pair(ColSpinner, override(baseTheme.Spinner, theme.Spinner), bg)
	C.init_pair(ColInfo, override(baseTheme.Info, theme.Info), bg)
	C.init_pair(ColCursor, override(baseTheme.Cursor, theme.Cursor), darkBG)
	C.init_pair(ColSelected, override(baseTheme.Selected, theme.Selected), darkBG)
	C.init_pair(ColHeader, override(baseTheme.Header, theme.Header), bg)
	C.init_pair(ColBorder, override(baseTheme.Border, theme.Border), bg)
}
Exemplo n.º 2
0
func initPairs(theme *ColorTheme, black bool) {
	fg := C.short(theme.Fg)
	bg := C.short(theme.Bg)
	if black {
		bg = C.COLOR_BLACK
	} else if theme.UseDefault {
		fg = -1
		bg = -1
		C.use_default_colors()
	}
	if theme.UseDefault {
		FG = -1
		BG = -1
	} else {
		FG = int(fg)
		BG = int(bg)
		C.assume_default_colors(C.int(theme.Fg), C.int(bg))
	}

	CurrentFG = int(theme.Current)
	DarkBG = int(theme.DarkBg)
	darkBG := C.short(DarkBG)
	C.init_pair(ColPrompt, C.short(theme.Prompt), bg)
	C.init_pair(ColMatch, C.short(theme.Match), bg)
	C.init_pair(ColCurrent, C.short(theme.Current), darkBG)
	C.init_pair(ColCurrentMatch, C.short(theme.CurrentMatch), darkBG)
	C.init_pair(ColSpinner, C.short(theme.Spinner), bg)
	C.init_pair(ColInfo, C.short(theme.Info), bg)
	C.init_pair(ColCursor, C.short(theme.Cursor), darkBG)
	C.init_pair(ColSelected, C.short(theme.Selected), darkBG)
	C.init_pair(ColHeader, C.short(theme.Header), bg)
}
Exemplo n.º 3
0
func Init_pair(pair int, fg int, bg int) os.Error {
	in()
	defer out()
	if C.init_pair(C.short(pair), C.short(fg), C.short(bg)) == 0 {
		return CursesError{"Init_pair failed"}
	}
	return nil
}
Exemplo n.º 4
0
// InitPair sets a colour pair designated by 'pair' to fg and bg colors
func InitPair(pair, fg, bg int16) error {
	if pair <= 0 || C.int(pair) > C.int(C.COLOR_PAIRS-1) {
		return errors.New("Color pair out of range")
	}
	if C.init_pair(C.short(pair), C.short(fg), C.short(bg)) == C.ERR {
		return errors.New("Failed to init color pair")
	}
	return nil
}
Exemplo n.º 5
0
Arquivo: curses.go Projeto: zennro/fzf
func PairFor(fg int, bg int) int {
	key := (fg << 8) + bg
	if found, prs := _colorMap[key]; prs {
		return found
	}

	id := len(_colorMap) + ColUser
	C.init_pair(C.short(id), C.short(fg), C.short(bg))
	_colorMap[key] = id
	return id
}
Exemplo n.º 6
0
func PairFor(fg Color, bg Color) ColorPair {
	// ncurses does not support 24-bit colors
	if fg.is24() || bg.is24() {
		return ColDefault
	}
	key := (int(fg) << 8) + int(bg)
	if found, prs := _colorMap[key]; prs {
		return found
	}

	id := ColorPair(len(_colorMap) + int(ColUser))
	C.init_pair(C.short(id), C.short(fg), C.short(bg))
	_colorMap[key] = id
	return id
}
Exemplo n.º 7
0
func initPairs(theme *ColorTheme) {
	C.assume_default_colors(C.int(theme.Fg), C.int(theme.Bg))
	for _, pair := range []ColorPair{
		ColNormal,
		ColPrompt,
		ColMatch,
		ColCurrent,
		ColCurrentMatch,
		ColSpinner,
		ColInfo,
		ColCursor,
		ColSelected,
		ColHeader,
		ColBorder} {
		C.init_pair(C.short(pair.index()), C.short(pair.Fg()), C.short(pair.Bg()))
	}
}
Exemplo n.º 8
0
func initPairs(theme *ColorTheme) {
	C.assume_default_colors(C.int(theme.Fg), C.int(theme.Bg))
	initPair := func(group ColorPair, fg Color, bg Color) {
		C.init_pair(C.short(group), C.short(fg), C.short(bg))
	}
	initPair(ColNormal, theme.Fg, theme.Bg)
	initPair(ColPrompt, theme.Prompt, theme.Bg)
	initPair(ColMatch, theme.Match, theme.Bg)
	initPair(ColCurrent, theme.Current, theme.DarkBg)
	initPair(ColCurrentMatch, theme.CurrentMatch, theme.DarkBg)
	initPair(ColSpinner, theme.Spinner, theme.Bg)
	initPair(ColInfo, theme.Info, theme.Bg)
	initPair(ColCursor, theme.Cursor, theme.DarkBg)
	initPair(ColSelected, theme.Selected, theme.DarkBg)
	initPair(ColHeader, theme.Header, theme.Bg)
	initPair(ColBorder, theme.Border, theme.Bg)
}
Exemplo n.º 9
0
func (p ColorPair) index() int16 {
	if p.id >= 0 {
		return p.id
	}

	// ncurses does not support 24-bit colors
	if p.is24() {
		return ColDefault.index()
	}

	key := p.key()
	if found, prs := _colorMap[key]; prs {
		return found
	}

	id := int16(len(_colorMap)) + ColUser.id
	C.init_pair(C.short(id), C.short(p.Fg()), C.short(p.Bg()))
	_colorMap[key] = id
	return id
}
Exemplo n.º 10
0
Arquivo: curses.go Projeto: zennro/fzf
func Init(color bool, color256 bool, black bool, mouse bool) {
	{
		in, err := os.OpenFile("/dev/tty", syscall.O_RDONLY, 0)
		if err != nil {
			panic("Failed to open /dev/tty")
		}
		_in = in
		// Break STDIN
		// syscall.Dup2(int(in.Fd()), int(os.Stdin.Fd()))
	}

	C.swapOutput()

	C.setlocale(C.LC_ALL, C.CString(""))
	C.initscr()
	if mouse {
		C.mousemask(C.ALL_MOUSE_EVENTS, nil)
	}
	C.cbreak()
	C.noecho()
	C.raw() // stty dsusp undef

	intChan := make(chan os.Signal, 1)
	signal.Notify(intChan, os.Interrupt, os.Kill)
	go func() {
		<-intChan
		Close()
		os.Exit(1)
	}()

	if color {
		C.start_color()
		var bg C.short
		if black {
			bg = C.COLOR_BLACK
		} else {
			C.use_default_colors()
			bg = -1
		}
		if color256 {
			DarkBG = 236
			C.init_pair(ColPrompt, 110, bg)
			C.init_pair(ColMatch, 108, bg)
			C.init_pair(ColCurrent, 254, DarkBG)
			C.init_pair(ColCurrentMatch, 151, DarkBG)
			C.init_pair(ColSpinner, 148, bg)
			C.init_pair(ColInfo, 144, bg)
			C.init_pair(ColCursor, 161, DarkBG)
			C.init_pair(ColSelected, 168, DarkBG)
		} else {
			DarkBG = C.COLOR_BLACK
			C.init_pair(ColPrompt, C.COLOR_BLUE, bg)
			C.init_pair(ColMatch, C.COLOR_GREEN, bg)
			C.init_pair(ColCurrent, C.COLOR_YELLOW, DarkBG)
			C.init_pair(ColCurrentMatch, C.COLOR_GREEN, DarkBG)
			C.init_pair(ColSpinner, C.COLOR_GREEN, bg)
			C.init_pair(ColInfo, C.COLOR_WHITE, bg)
			C.init_pair(ColCursor, C.COLOR_RED, DarkBG)
			C.init_pair(ColSelected, C.COLOR_MAGENTA, DarkBG)
		}
		_color = attrColored
	} else {
		_color = attrMono
	}
}
Exemplo n.º 11
0
func InitColorPair(pairID int, foreground int, background int) error {
	if C.init_pair(C.short(pairID), C.short(foreground), C.short(background)) == 0 {
		return CursesError{"Init_pair failed"}
	}
	return nil
}
Exemplo n.º 12
0
func Init_pair(pair int, fg int, bg int) error {
	if C.init_pair(C.short(pair), C.short(fg), C.short(bg)) == 0 {
		return CursesError{"Init_pair failed"}
	}
	return nil
}
Exemplo n.º 13
0
func SetColorPair(pair, fg, bg int) error {
	if C.init_pair(C.short(pair), C.short(fg), C.short(bg)) == 0 {
		return ErrorInitPair
	}
	return nil
}
Exemplo n.º 14
0
func InitPair(pair, fg, bg int) {
	C.init_pair(C.short(pair), C.short(fg), C.short(bg))
}
Exemplo n.º 15
0
/* Initializes a color pair, foreground and background. The color pair number to initialize is n, with the foreground and background colors after that. */
func InitPair(n, fore, back int) {
	C.init_pair(C.short(n), C.short(fore), C.short(back))
}