summaryrefslogtreecommitdiff
path: root/colors.go
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2026-01-21 20:22:09 +0100
committerMitja Felicijan <mitja.felicijan@gmail.com>2026-01-21 20:22:09 +0100
commit5a8dbc6347b3541e84fe669b22c17ad3b715e258 (patch)
treeb148c450939688caaaeb4adac6f2faa1eaffe649 /colors.go
downloadqwe-editor-5a8dbc6347b3541e84fe669b22c17ad3b715e258.tar.gz
Engage!
Diffstat (limited to 'colors.go')
-rw-r--r--colors.go62
1 files changed, 62 insertions, 0 deletions
diff --git a/colors.go b/colors.go
new file mode 100644
index 0000000..d88b968
--- /dev/null
+++ b/colors.go
@@ -0,0 +1,62 @@
+package main
+
+// Utility to print all 256 terminal colors. This is useful for debugging themes
+// and ensuring the terminal supports the expected color range.
+
+import (
+ "fmt"
+ "os"
+
+ "github.com/nsf/termbox-go"
+)
+
+// PrintColors initializes termbox and draws a grid of all 256 available colors.
+func PrintColors() {
+ err := termbox.Init()
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "failed to init termbox: %v\n", err)
+ return
+ }
+ defer termbox.Close()
+
+ // Enable 256-color mode for the output.
+ termbox.SetOutputMode(termbox.Output256)
+ termbox.Clear(termbox.ColorDefault, termbox.ColorDefault)
+
+ w, _ := termbox.Size()
+
+ // Adjust grid columns based on terminal width.
+ cols := 16
+ if w < 64 {
+ cols = 8
+ }
+
+ // Loop through all 256 colors and draw them in a grid.
+ for i := 0; i < 256; i++ {
+ row := (i / cols) * 2
+ col := (i % cols) * 5
+
+ bg := termbox.Attribute(i)
+ fg := termbox.ColorWhite
+ // Ensure text is readable against light/dark backgrounds.
+ if i == 7 || i > 240 {
+ fg = termbox.ColorBlack
+ }
+
+ // Draw the color index and a colored block.
+ str := fmt.Sprintf("%5d", i)
+ for j, r := range str {
+ termbox.SetCell(col+j, row, r, fg, bg)
+ termbox.SetCell(col+j, row+1, ' ', fg, bg)
+ }
+ }
+
+ msg := "Press any key to exit..."
+ for i, r := range msg {
+ termbox.SetCell(i, (256/cols)*2, r, termbox.ColorWhite, termbox.ColorDefault)
+ }
+
+ termbox.Flush()
+ // Wait for any key press before closing.
+ termbox.PollEvent()
+}