-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-style-purs.mjs
executable file
·84 lines (81 loc) · 2.57 KB
/
generate-style-purs.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env node
/*
USAGE: ./tools/generate-style-purs.mjs > src/Choku/Style.purs
*/
import { modifierNames, foregroundColorNames, backgroundColorNames } from 'chalk';
const p_ = function(line) { process.stdout.write(line); }
const p = function(line) { process.stdout.write(line + "\n"); }
const allNames = modifierNames.concat(
foregroundColorNames,
backgroundColorNames,
[ "fg", "bg" ]
);
const importStyle = function(name) {
return `foreign import ${name} :: Style`;
};
p("-- | Styles applied to chalks for modifying/colorizing strings.");
p("-- |");
p("-- | These styles are of signature `Choku -> Choku`, appending another");
p("-- | modification to any chalk.");
p("-- |");
p("-- | Check out the full list of styles [here](https://github.com/chalk/chalk#styles)");
p("-- | in the original chalk's README.");
p("-- | An only difference from the original API is that those six methods to apply");
p("-- | styles using RGB/ANSI256 color models, namely `chalk.rgb()`, `chalk.hex()`,");
p("-- | `chalk.ansi256()`, `chalk.bgRgb()`, `chalk.bgHex()`, and `chalk.bgAnsi256()`");
p("-- | are integrated into two functions `fg` and `bg`, thanks to PureScript's GADTs.");
p("-- |");
p("-- | ### See also");
p("-- |");
p("-- | - https://github.com/chalk/chalk#chalkstylestylestring-string");
p("module Choku.Style");
p(" ( Style");
p_(" , ");
p(allNames.join("\n , "));
p(" ) where");
p("");
p("import Data.Function.Uncurried (Fn3, runFn3)")
p("import Choku.Common (Choku)");
p("import Choku.Color (Color(..))");
p("");
p("type Style = Choku -> Choku");
p("");
p("{- Modifiers -}");
p("")
for (const name of modifierNames) {
p(importStyle(name));
}
p("")
p("{- Foreground colors -}");
p("")
for (const name of foregroundColorNames) {
p(importStyle(name));
}
p("")
p("{- Background colors -}");
p("")
for (const name of backgroundColorNames) {
p(importStyle(name));
}
p("")
p("{- 256 and Truecolor support -}");
p("")
p("foreign import _rgb :: Fn3 Int Int Int Style");
p("foreign import _hex :: String -> Style");
p("foreign import _ansi256 :: Int -> Style");
p("foreign import _bgRgb :: Fn3 Int Int Int Style");
p("foreign import _bgHex :: String -> Style");
p("foreign import _bgAnsi256 :: Int -> Style");
p("")
p("-- | Modify foreground color.");
p("fg :: Color -> Style");
p("fg (RGB { r, g, b }) = runFn3 _rgb r g b");
p("fg (Hex hex) = _hex hex");
p("fg (ANSI256 i) = _ansi256 i");
p("")
p("-- | Modify background color.");
p("bg :: Color -> Style");
p("bg (RGB { r, g, b }) = runFn3 _bgRgb r g b");
p("bg (Hex hex) = _bgHex hex");
p("bg (ANSI256 i) = _bgAnsi256 i");
// vim: tw=88 nowrap