From f465b596a16221d04c027aee327ee894dedc3669 Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch
Date: Tue, 5 Nov 2024 02:49:11 +0100 Subject: WIP: xA: IRC colors --- xA/xA.go | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 7 deletions(-) (limited to 'xA/xA.go') diff --git a/xA/xA.go b/xA/xA.go index 20d8351..7c2231f 100644 --- a/xA/xA.go +++ b/xA/xA.go @@ -34,12 +34,60 @@ var ( type customTheme struct{} +func convertColor(c int) color.Color { + base16 := []uint16{ + 0x000, 0x800, 0x080, 0x880, 0x008, 0x808, 0x088, 0xccc, + 0x888, 0xf00, 0x0f0, 0xff0, 0x00f, 0xf0f, 0x0ff, 0xfff, + } + if c < 16 { + r := 0xf & uint8(base16[c]>>8) + g := 0xf & uint8(base16[c]>>4) + b := 0xf & uint8(base16[c]) + return color.RGBA{r * 0x11, g * 0x11, b * 0x11, 0xff} + } + if c >= 216 { + return color.Gray{8 + uint8(c-216)*10} + } + + var ( + i = uint8(c - 16) + r = i / 36 >> 0 + g = (i / 6 >> 0) % 6 + b = i % 6 + ) + if r != 0 { + r = 55 + 40*r + } + if g != 0 { + g = 55 + 40*g + } + if b != 0 { + b = 55 + 40*b + } + return color.RGBA{r, g, b, 0xff} +} + +var ircColors = make(map[fyne.ThemeColorName]color.Color) + +func init() { + for color := 0; color < 256; color++ { + ircColors[fyne.ThemeColorName( + fmt.Sprintf("irc%02x", color))] = convertColor(color) + } +} + func (t *customTheme) Color( name fyne.ThemeColorName, variant fyne.ThemeVariant) color.Color { + // Fuck this low contrast shit, text must be black. if name == theme.ColorNameForeground && variant == theme.VariantLight { return color.Black } + + // TODO(p): Consider constants for stuff like timestamps. + if c, ok := ircColors[name]; ok { + return c + } return theme.DefaultTheme().Color(name, variant) } @@ -64,13 +112,11 @@ type server struct { } type bufferLineItem struct { - // TODO(p): Figure out how to store formatting. - // → fyne.TextStyle, however this doesn't store bg or fg colour, - // which is only a widget.{Custom,}TextGridStyle thing. - // - I'll likely have to create 257^2 name combinations, - // plus perhaps add names for "internal" stuff like timestamps. - // - theme.ColorForWidget - text string + format fyne.TextStyle + // For RichTextStyle.ColorName. + // XXX: Fyne's RichText doesn't support background colours. + color string + text string } type bufferLine struct { -- cgit v1.2.3-70-g09d2