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-05 02:49:11 +0100 |
commit | f465b596a16221d04c027aee327ee894dedc3669 (patch) | |
tree | 18fb4c3856e7a9b41fc4f0b5e42839fa481583d9 /xA/xA.go | |
parent | eedbcb64d3b88d939b01f25d3fb753e1b55e4d13 (diff) | |
download | xK-f465b596a16221d04c027aee327ee894dedc3669.tar.gz xK-f465b596a16221d04c027aee327ee894dedc3669.tar.xz xK-f465b596a16221d04c027aee327ee894dedc3669.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 { |