v0.1.2 moved xterm color functionality to color package, adapters added for compatibility
This commit is contained in:
+38
-77
@@ -1,93 +1,54 @@
|
||||
package terminal
|
||||
|
||||
// Generic xterm 256-color palette indices without game semantics
|
||||
// Game systems reference these via aliases in their own parameter files
|
||||
//
|
||||
// Color cube: index = 16 + 36*r + 6*g + b where r,g,b ∈ [0,5]
|
||||
// Grayscale ramp: indices 232-255, level = 8 + 10*(index-232)
|
||||
//
|
||||
// Ordered dark-to-light within each hue group
|
||||
import "github.com/lixenwraith/color"
|
||||
|
||||
// Generic xterm 256-color constants proxied to the central color package
|
||||
// to maintain backwards compatibility for the terminal package.
|
||||
|
||||
const (
|
||||
// --- Blue ---
|
||||
P256DeepNavy uint8 = 17 // (0,0,1)
|
||||
P256DarkBlue uint8 = 18 // (0,0,2)
|
||||
P256SteelBlue uint8 = 75 // (1,3,5)
|
||||
P256LightBlue uint8 = 81 // (1,4,5)
|
||||
|
||||
// --- Teal / Cyan ---
|
||||
P256DeepTeal uint8 = 23 // (0,1,1)
|
||||
P256Teal uint8 = 44 // (0,4,4)
|
||||
P256Green uint8 = 46 // (0,5,0)
|
||||
P256Cyan uint8 = 51 // (0,5,5)
|
||||
P256LightCyan uint8 = 87 // (1,5,5)
|
||||
|
||||
// --- Blue / Purple ---
|
||||
P256CobaltBlue uint8 = 33 // (0,2,5)
|
||||
P256DarkPurpleBlue uint8 = 54 // (1,0,2)
|
||||
P256Indigo uint8 = 63 // (1,1,5)
|
||||
P256Purple uint8 = 129 // (3,0,5)
|
||||
P256Violet uint8 = 134 // (3,1,4)
|
||||
P256MediumPurple uint8 = 135 // (3,1,5)
|
||||
P256Orchid uint8 = 176 // (4,2,4)
|
||||
|
||||
// --- Green / Yellow-Green ---
|
||||
P256YellowGreen uint8 = 154 // (3,5,0)
|
||||
|
||||
// --- Red ---
|
||||
P256Maroon uint8 = 52 // (1,0,0)
|
||||
P256DarkCrimson uint8 = 88 // (2,0,0)
|
||||
P256Crimson uint8 = 160 // (4,0,0)
|
||||
|
||||
// --- Red / Orange / Yellow ---
|
||||
P256Red uint8 = 196 // (5,0,0)
|
||||
P256Rose uint8 = 198 // (5,0,2)
|
||||
P256RedOrange uint8 = 202 // (5,1,0)
|
||||
P256Orange uint8 = 208 // (5,2,0)
|
||||
P256Amber uint8 = 214 // (5,3,0)
|
||||
P256Gold uint8 = 220 // (5,4,0)
|
||||
P256Yellow uint8 = 226 // (5,5,0)
|
||||
|
||||
// --- Orange / Brown ---
|
||||
P256DarkAmber uint8 = 94 // (2,1,0)
|
||||
|
||||
// --- Grayscale ---
|
||||
P256Gray uint8 = 240 // Grayscale step 8, level ~88
|
||||
P256DeepNavy = color.P256DeepNavy
|
||||
P256DarkBlue = color.P256DarkBlue
|
||||
P256SteelBlue = color.P256SteelBlue
|
||||
P256LightBlue = color.P256LightBlue
|
||||
P256DeepTeal = color.P256DeepTeal
|
||||
P256Teal = color.P256Teal
|
||||
P256Green = color.P256Green
|
||||
P256Cyan = color.P256Cyan
|
||||
P256LightCyan = color.P256LightCyan
|
||||
P256CobaltBlue = color.P256CobaltBlue
|
||||
P256DarkPurpleBlue = color.P256DarkPurpleBlue
|
||||
P256Indigo = color.P256Indigo
|
||||
P256Purple = color.P256Purple
|
||||
P256Violet = color.P256Violet
|
||||
P256MediumPurple = color.P256MediumPurple
|
||||
P256Orchid = color.P256Orchid
|
||||
P256YellowGreen = color.P256YellowGreen
|
||||
P256Maroon = color.P256Maroon
|
||||
P256DarkCrimson = color.P256DarkCrimson
|
||||
P256Crimson = color.P256Crimson
|
||||
P256Red = color.P256Red
|
||||
P256Rose = color.P256Rose
|
||||
P256RedOrange = color.P256RedOrange
|
||||
P256Orange = color.P256Orange
|
||||
P256Amber = color.P256Amber
|
||||
P256Gold = color.P256Gold
|
||||
P256Yellow = color.P256Yellow
|
||||
P256DarkAmber = color.P256DarkAmber
|
||||
P256Gray = color.P256Gray
|
||||
)
|
||||
|
||||
// Cube256 returns the xterm 256-palette index for an RGB cube coordinate.
|
||||
// r, g, b must be in [0,5]. Values outside that range are clamped.
|
||||
func Cube256(r, g, b uint8) uint8 {
|
||||
if r > 5 {
|
||||
r = 5
|
||||
}
|
||||
if g > 5 {
|
||||
g = 5
|
||||
}
|
||||
if b > 5 {
|
||||
b = 5
|
||||
}
|
||||
return 16 + 36*r + 6*g + b
|
||||
return color.Cube256(r, g, b)
|
||||
}
|
||||
|
||||
// CubeRGB256 returns the (r, g, b) cube coordinates for a 256-palette color cube index.
|
||||
// Index must be in [16,231]. Returns (0,0,0) for out-of-range indices.
|
||||
func CubeRGB256(index uint8) (r, g, b uint8) {
|
||||
if index < 16 || index > 231 {
|
||||
return 0, 0, 0
|
||||
}
|
||||
n := index - 16
|
||||
r = n / 36
|
||||
g = (n % 36) / 6
|
||||
b = n % 6
|
||||
return r, g, b
|
||||
return color.CubeRGB256(index)
|
||||
}
|
||||
|
||||
// Gray256 returns the xterm 256-palette index for a grayscale step.
|
||||
// step must be in [0,23] (maps to indices 232-255, levels 8-238).
|
||||
func Gray256(step uint8) uint8 {
|
||||
if step > 23 {
|
||||
step = 23
|
||||
}
|
||||
return 232 + step
|
||||
}
|
||||
return color.Gray256(step)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user