main.go (11595B)
1 package main 2 3 import ( 4 "bufio" 5 "bytes" 6 "flag" 7 "fmt" 8 "io" 9 "io/ioutil" 10 "log" 11 "os" 12 "strconv" 13 "strings" 14 15 cl "github.com/go-pa/colorlab" 16 ) 17 18 // Options are command line flags . 19 type Options struct { 20 NoElispUpdate bool 21 } 22 23 func (o *Options) Register() { 24 flag.BoolVar(&o.NoElispUpdate, "no-update", false, "don't update ../solarized-palettes.el") 25 26 } 27 28 func main() { 29 var opts Options 30 31 opts.Register() 32 flag.Parse() 33 34 for _, pal := range palettes { 35 fmt.Println(pal.Name) 36 nc := pal.Generate() 37 PrintAlist(os.Stdout, nc, 0) 38 // nc.FilterPrefix("base").PrintAlist(os.Stdout, 0) 39 // Merge(nc.FilterSuffix("-d"), oldDarkAccents.NamedColors().WithSuffix("-do")).PrintAlist(os.Stdout, 0) 40 // Merge(nc.FilterSuffix("-l"), oldLightAccents.NamedColors().WithSuffix("-lo")).PrintAlist(os.Stdout, 0) 41 if !opts.NoElispUpdate { 42 RewritePalette(nc, pal.Name) 43 } 44 } 45 fmt.Println("\n-----\n") 46 } 47 48 var ( 49 default1BgFg = cl.AccentPairGenerator{ 50 BlendBackgroundAmout: 0.85, 51 BlendForegroundAmout: 0.3, 52 Gamma: 0.01, 53 MinimumLightnessDifference: 0.35, 54 ForegroundBlendFinder: cl.ExtremeColorFgFinder, 55 BackgroundBlendFinder: cl.ExtremeColorBgFinder, 56 } 57 default2BgFg = cl.AccentPairGenerator{ 58 BlendBackgroundAmout: 0.6, 59 BlendForegroundAmout: 0.45, 60 Gamma: 0.04, 61 MinimumLightnessDifference: 0.35, 62 ForegroundBlendFinder: cl.ExtremeColorFgFinder, 63 BackgroundBlendFinder: cl.ExtremeColorBgFinder, 64 } 65 66 palettes = []cl.Palette{ 67 { 68 Name: "solarized-dark", 69 Solarized: solarized, 70 Accent1Pair: cl.AccentPairGenerator{ 71 BlendBackgroundAmout: default1BgFg.BlendBackgroundAmout, 72 BlendForegroundAmout: default1BgFg.BlendForegroundAmout, 73 Gamma: default1BgFg.Gamma, 74 ForegroundBlendFinder: cl.NamedColorFinder("base1"), 75 BackgroundBlendFinder: default1BgFg.BackgroundBlendFinder, 76 MinimumLightnessDifference: 0.4, 77 }, 78 Accent2Pair: cl.AccentPairGenerator{ 79 BlendBackgroundAmout: default2BgFg.BlendBackgroundAmout, 80 BlendForegroundAmout: default2BgFg.BlendForegroundAmout, 81 Gamma: default2BgFg.Gamma, 82 ForegroundBlendFinder: cl.NamedColorFinder("base1"), 83 BackgroundBlendFinder: default2BgFg.BackgroundBlendFinder, 84 MinimumLightnessDifference: 0.4, 85 }, 86 }, 87 { 88 Name: "solarized-light", 89 Solarized: solarized, 90 Inverse: true, 91 Accent1Pair: default1BgFg, 92 Accent2Pair: default2BgFg, 93 }, 94 { 95 Name: "solarized-dark-high-contrast", 96 Solarized: solarizedDarkHighContrast, 97 Accent1Pair: cl.AccentPairGenerator{ 98 BlendBackgroundAmout: default1BgFg.BlendBackgroundAmout, 99 BlendForegroundAmout: default1BgFg.BlendForegroundAmout, 100 Gamma: default1BgFg.Gamma, 101 ForegroundBlendFinder: cl.NamedColorFinder("base1"), 102 BackgroundBlendFinder: default1BgFg.BackgroundBlendFinder, 103 MinimumLightnessDifference: 0.4, 104 }, 105 Accent2Pair: cl.AccentPairGenerator{ 106 BlendBackgroundAmout: default2BgFg.BlendBackgroundAmout, 107 BlendForegroundAmout: default2BgFg.BlendForegroundAmout, 108 Gamma: default2BgFg.Gamma, 109 ForegroundBlendFinder: cl.NamedColorFinder("base1"), 110 BackgroundBlendFinder: default2BgFg.BackgroundBlendFinder, 111 MinimumLightnessDifference: 0.4, 112 }, 113 }, 114 { 115 Name: "solarized-light-high-contrast", 116 Solarized: solarizedLightHighContrast, 117 Inverse: true, 118 Accent1Pair: default1BgFg, 119 Accent2Pair: default2BgFg, 120 }, 121 { 122 Name: "gruvbox-dark", 123 Solarized: gruvboxDark, 124 Accent1Pair: default1BgFg, 125 Accent2Pair: default2BgFg, 126 }, 127 { 128 Name: "gruvbox-light", 129 Solarized: gruvboxLight, 130 Inverse: true, 131 Accent1Pair: default1BgFg, 132 Accent2Pair: default2BgFg, 133 }, 134 { 135 Name: "zenburn", 136 Solarized: zenburn, 137 Accent1Pair: default1BgFg, 138 Accent2Pair: default2BgFg, 139 }, 140 { 141 Name: "monokai", 142 Solarized: monokai, 143 Accent1Pair: default1BgFg, 144 Accent2Pair: default2BgFg, 145 }, 146 { 147 Name: "selenized-dark", 148 Solarized: selenizedDark, 149 Accent1Pair: default1BgFg, 150 Accent2Pair: default2BgFg, 151 }, 152 { 153 Name: "selenized-black", 154 Solarized: selenizedBlack, 155 Accent1Pair: default1BgFg, 156 Accent2Pair: default2BgFg, 157 }, 158 { 159 Name: "selenized-light", 160 Solarized: selenizedLight, 161 Accent1Pair: default1BgFg, 162 Accent2Pair: default2BgFg, 163 }, 164 { 165 Name: "selenized-white", 166 Solarized: selenizedWhite, 167 Accent1Pair: default1BgFg, 168 Accent2Pair: default2BgFg, 169 }, 170 } 171 172 // The original solarized color palette 173 solarized = cl.Solarized{ 174 Base: cl.Base{ 175 Base03: cl.SolarizedBase03, 176 Base02: cl.SolarizedBase02, 177 Base01: cl.SolarizedBase01, 178 Base00: cl.SolarizedBase00, 179 Base0: cl.SolarizedBase0, 180 Base1: cl.SolarizedBase1, 181 Base2: cl.SolarizedBase2, 182 Base3: cl.SolarizedBase3, 183 }, 184 Accents: cl.Accents{ 185 Blue: cl.SolarizedBlue, 186 Cyan: cl.SolarizedCyan, 187 Green: cl.SolarizedGreen, 188 Magenta: cl.SolarizedMagenta, 189 Orange: cl.SolarizedOrange, 190 Red: cl.SolarizedRed, 191 Violet: cl.SolarizedViolet, 192 Yellow: cl.SolarizedYellow, 193 }, 194 } 195 solarizedDarkHighContrast = cl.Solarized{ 196 Base: solarized.Base.Clone().ChangeLightness(0.04, -0.02), 197 Accents: solarized.Accents.Clone().ChangeLightness(0.05), 198 } 199 solarizedLightHighContrast = cl.Solarized{ 200 Base: solarized.Base.Clone().ChangeLightness(0.02, -0.05), 201 Accents: solarized.Accents.Clone().ChangeLightness(-0.05), 202 } 203 204 // the current -d colors in the emacs theme 205 oldDarkAccents = cl.Accents{ 206 Blue: "#00629D", 207 Cyan: "#00736F", 208 Green: "#546E00", 209 Magenta: "#93115C", 210 Orange: "#8B2C02", 211 Red: "#990A1B", 212 Violet: "#3F4D91", 213 Yellow: "#7B6000", 214 } 215 // the current -l colors in the emacs theme 216 oldLightAccents = cl.Accents{ 217 Blue: "#69B7F0", 218 Cyan: "#69CABF", 219 Green: "#B4C342", 220 Magenta: "#F771AC", 221 Orange: "#F2804F", 222 Red: "#FF6E64", 223 Violet: "#9EA0E5", 224 Yellow: "#DEB542", 225 } 226 gruvboxDark = cl.Solarized{ 227 Base: cl.Base{ 228 Base03: cl.GruvboxDark0, 229 Base02: cl.GruvboxDark0Soft, 230 Base01: cl.GruvboxDark4, 231 Base00: cl.GruvboxDark0, 232 Base0: cl.GruvboxLight4, 233 Base1: cl.GruvboxLight3, 234 Base2: cl.GruvboxLight4, 235 Base3: cl.GruvboxLight0, 236 }, 237 Accents: cl.Accents{ 238 Blue: cl.GruvboxBlue, 239 Cyan: cl.GruvboxAqua, 240 Green: cl.GruvboxGreen, 241 Magenta: cl.GruvboxBrightPurple, 242 Orange: cl.GruvboxOrange, 243 Red: cl.GruvboxBrightRed, 244 Violet: cl.GruvboxPurple, 245 Yellow: cl.GruvboxYellow, 246 }, 247 } 248 // note: not inversed here 249 gruvboxLight = cl.Solarized{ 250 Base: cl.Base{ 251 Base03: cl.GruvboxDark0, 252 Base02: cl.GruvboxDark0Soft, 253 Base01: cl.GruvboxDark3, 254 Base00: cl.GruvboxDark4, 255 Base0: cl.GruvboxDark1, 256 Base1: cl.GruvboxLight4, 257 Base2: cl.GruvboxLight1, 258 Base3: cl.GruvboxLight0, 259 }, 260 Accents: cl.Accents{ 261 Blue: cl.GruvboxDarkBlue, 262 Cyan: cl.GruvboxAqua, 263 Green: cl.GruvboxGreen, 264 Magenta: cl.GruvboxBrightPurple, 265 Orange: cl.GruvboxDarkOrange, 266 Red: cl.GruvboxDarkRed, 267 Violet: cl.GruvboxDarkPurple, 268 Yellow: cl.GruvboxDarkYellow, 269 }, 270 } 271 zenburn = cl.Solarized{ 272 Base: cl.Base{ 273 Base03: cl.ZenburnBg, 274 Base02: cl.ZenburnBgP1, 275 Base01: cl.HexColor(cl.ZenburnFgM1).Blend(cl.ZenburnFg, 0.3), 276 Base00: cl.ZenburnBgP3, 277 Base0: cl.ZenburnFg, 278 Base1: cl.ZenburnFgP1, 279 Base2: cl.HexColor(cl.ZenburnFgP1).Blend(cl.ZenburnFgP2, 0.5), 280 Base3: cl.ZenburnFgP2, 281 }, 282 Accents: cl.Accents{ 283 Blue: cl.ZenburnBlue, 284 Cyan: cl.ZenburnCyan, 285 Green: cl.ZenburnGreen, 286 Magenta: cl.ZenburnMagenta, 287 Orange: cl.ZenburnOrange, 288 Red: cl.ZenburnRed, 289 Violet: cl.HexColor(cl.ZenburnBlue).Blend(cl.ZenburnMagenta, 0.5), 290 Yellow: cl.ZenburnYellow, 291 }, 292 } 293 294 monokai = cl.Solarized{ 295 Base: cl.Base{ 296 Base03: cl.Monokai03, 297 Base02: cl.Monokai02, 298 Base01: cl.Monokai01, 299 Base00: cl.Monokai00, 300 Base0: cl.Monokai0, 301 Base1: cl.Monokai0, 302 Base2: cl.Monokai0, 303 Base3: cl.Monokai0, 304 }, 305 Accents: cl.Accents{ 306 Blue: cl.MonokaiBlue, 307 Cyan: cl.MonokaiCyan, 308 Green: cl.MonokaiGreen, 309 Magenta: cl.MonokaiMagenta, 310 Orange: cl.MonokaiOrange, 311 Red: cl.MonokaiRed, 312 Violet: cl.MonokaiViolet, 313 Yellow: cl.MonokaiYellow, 314 }, 315 } 316 selenizedDark = cl.Solarized{ 317 Base: cl.Base{ 318 Base03: "#103c48", 319 Base02: "#184956", 320 Base01: "#72898f", 321 Base00: "#103c48", 322 Base0: "#adbcbc", 323 Base1: "#cad8d9", 324 Base2: "#ece3cc", 325 Base3: "#fbf3db", 326 }, 327 Accents: cl.Accents{ 328 Blue: "#4695f7", 329 Cyan: "#41c7b9", 330 Green: "#75b938", 331 Magenta: "#f275be", 332 Orange: "#ed8649", 333 Red: "#fa5750", 334 Violet: "#af88eb", 335 Yellow: "#dbb32d", 336 }, 337 } 338 selenizedBlack = cl.Solarized{ 339 Base: cl.Base{ 340 Base03: "#181818", 341 Base02: "#252525", 342 Base01: "#777777", 343 Base00: "#181818", 344 Base0: "#b9b9b9", 345 Base1: "#dedede", 346 Base2: "#53676d", 347 Base3: "#3a4d53", 348 }, 349 Accents: cl.Accents{ 350 Blue: "#368aeb", 351 Cyan: "#3fc5b7", 352 Green: "#70b433", 353 Magenta: "#eb6eb7", 354 Orange: "#e67f43", 355 Red: "#ed4a46", 356 Violet: "#a580e2", 357 Yellow: "#dbb32d", 358 }, 359 } 360 selenizedLight = cl.Solarized{ 361 Base: cl.Base{ 362 Base03: "#fbf3db", 363 Base02: "#ece3cc", 364 Base01: "#909995", 365 Base00: "#fbf3db", 366 Base0: "#53676d", 367 Base1: "#3a4d53", 368 Base2: "#adbcbc", 369 Base3: "#cad8d9", 370 }, 371 Accents: cl.Accents{ 372 Blue: "#0072d4", 373 Cyan: "#009c8f", 374 Green: "#489100", 375 Magenta: "#ca4898", 376 Orange: "#c25d1e", 377 Red: "#d2212d", 378 Violet: "#8762c6", 379 Yellow: "#ad8900", 380 }, 381 } 382 selenizedWhite = cl.Solarized{ 383 Base: cl.Base{ 384 Base03: "#ffffff", 385 Base02: "#ebebeb", 386 Base01: "#878787", 387 Base00: "#ffffff", 388 Base0: "#474747", 389 Base1: "#282828", 390 Base2: "#b9b9b9", 391 Base3: "#dedede", 392 }, 393 Accents: cl.Accents{ 394 Blue: "#0064e4", 395 Cyan: "#00ad9c", 396 Green: "#1d9700", 397 Magenta: "#dd0f9d", 398 Orange: "#d04a00", 399 Red: "#d6000c", 400 Violet: "#7f51d6", 401 Yellow: "#c49700", 402 }, 403 } 404 ) 405 406 // PrintAlist prints the named colors list in a way that is compatible with solarized-palettes.el. 407 func PrintAlist(w io.Writer, n cl.NamedColors, indent int) (int, error) { 408 keys := cl.OrderedKeys(n) 409 var longestKey int 410 for _, n := range keys { 411 l := len(n) 412 if l > longestKey { 413 longestKey = l 414 } 415 } 416 prefix := "" 417 for i := 0; i < indent; i++ { 418 prefix += " " 419 420 } 421 var nt int 422 423 for _, name := range keys { 424 n, err := fmt.Fprintf(w, "%s(%-"+strconv.Itoa(longestKey)+"s . \"%s\")\n", prefix, name, n[name]) 425 n = n + nt 426 if err != nil { 427 return nt, err 428 } 429 430 } 431 return nt, nil 432 } 433 434 func RewritePalette(nc cl.NamedColors, paletteName string) { 435 436 var dst bytes.Buffer 437 438 file, err := os.Open("../solarized-palettes.el") 439 if err != nil { 440 log.Fatal(err) 441 } 442 defer file.Close() 443 444 scanner := bufio.NewScanner(file) 445 var insideReplacement bool 446 for scanner.Scan() { 447 txt := scanner.Text() 448 if insideReplacement && strings.HasSuffix(txt, ";; palette end") { 449 insideReplacement = false 450 } 451 if !insideReplacement { 452 dst.WriteString(txt) 453 dst.WriteString("\n") 454 455 } 456 if strings.HasSuffix(txt, fmt.Sprintf(";; %s palette", paletteName)) { 457 insideReplacement = true 458 PrintAlist(&dst, nc, 4) 459 } 460 } 461 462 if err := scanner.Err(); err != nil { 463 log.Fatal(err) 464 } 465 466 file.Close() 467 ioutil.WriteFile("../solarized-palettes.el", dst.Bytes(), 0x776) 468 469 }