Beispiel #1
0
func (c attrColor) RGBA() (r, g, b, a uint32) {
	switch termbox.Attribute(c) {
	case termbox.ColorBlack:
		return 0, 0, 0, math.MaxUint16
	case termbox.ColorRed:
		return math.MaxUint16, 0, 0, math.MaxUint16
	case termbox.ColorGreen:
		return 0, math.MaxUint16, 0, math.MaxUint16
	case termbox.ColorYellow:
		return math.MaxUint16, math.MaxUint16, 0, math.MaxUint16
	case termbox.ColorBlue:
		return 0, 0, math.MaxUint16, math.MaxUint16
	case termbox.ColorMagenta:
		return math.MaxUint16, 0, math.MaxUint16, math.MaxUint16
	case termbox.ColorCyan:
		return 0, math.MaxUint16, math.MaxUint16, math.MaxUint16
	case termbox.ColorWhite:
		return math.MaxUint16, math.MaxUint16, math.MaxUint16, math.MaxUint16
	}

	switch {
	case c >= 16 && c <= 231:
		c -= 16
		rgba := color.RGBA{R: base[(c/36)%6], G: base[(c/6)%6], B: base[c%6], A: 0xff}
		return rgba.RGBA()
	case c >= 232 && c <= 255:
		x := uint8(0x08 + 0xa*(c-232))
		rgba := color.RGBA{R: x, G: x, B: x, A: 0xff}
		return rgba.RGBA()
	}

	panic("not found")
}
Beispiel #2
0
func draw(img image.Image) {
	w, h := termbox.Size()
	iw, ih := img.Bounds().Max.X, img.Bounds().Max.Y
	sw, sh := fit(w, h, iw*2, ih)
	termbox.Clear(termbox.ColorDefault, termbox.ColorDefault)
	for y := 0; y < h; y++ {
		for x := 0; x < w; x++ {
			if x >= sw || y >= sh {
				termbox.SetCell(x, y, ' ', termbox.ColorDefault, termbox.ColorDefault)
				continue
			}
			xi := x * img.Bounds().Max.X / sw
			yi := y * img.Bounds().Max.Y / sh
			a := palette.Convert(img.At(xi, yi))
			if at, ok := a.(attrColor); ok {
				termbox.SetCell(x, y, ' ', termbox.ColorDefault,
					termbox.Attribute(at))
			}
		}
	}
	termbox.Flush()
}
Beispiel #3
0
func toTmAttr(x Attribute) tm.Attribute {
	return tm.Attribute(x)
}
Beispiel #4
0
func (tb termboxImpl) SetCell(x, y int, c rune, fg, bg uint16) {
	termbox.SetCell(x, y, c, termbox.Attribute(fg), termbox.Attribute(bg))
}