diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2024-11-05 02:49:11 +0100 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2024-11-09 17:20:18 +0100 |
commit | 2f32bda5697a6ed8163019f5d6a1f6be76007bb8 (patch) | |
tree | e188dec1f97f2e49421e149e2e3ee7237f0195d2 /xA/xA.go | |
parent | 498dfdfca47085c00ad7d60b03c510050c39d512 (diff) | |
download | xK-2f32bda5697a6ed8163019f5d6a1f6be76007bb8.tar.gz xK-2f32bda5697a6ed8163019f5d6a1f6be76007bb8.tar.xz xK-2f32bda5697a6ed8163019f5d6a1f6be76007bb8.zip |
WIP: xA: IRC colors
Diffstat (limited to 'xA/xA.go')
-rw-r--r-- | xA/xA.go | 60 |
1 files changed, 53 insertions, 7 deletions
@@ -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 { |