-
Notifications
You must be signed in to change notification settings - Fork 0
/
Style.purs
146 lines (134 loc) · 3.56 KB
/
Style.purs
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
-- | Styles applied to chalks for modifying/colorizing strings.
-- |
-- | These styles are of signature `Choku -> Choku`, appending another
-- | modification to any chalk.
-- |
-- | Check out the full list of styles [here](https://github.com/chalk/chalk#styles)
-- | in the original chalk's README.
-- | An only difference from the original API is that those six methods to apply
-- | styles using RGB/ANSI256 color models, namely `chalk.rgb()`, `chalk.hex()`,
-- | `chalk.ansi256()`, `chalk.bgRgb()`, `chalk.bgHex()`, and `chalk.bgAnsi256()`
-- | are integrated into two functions `fg` and `bg`, thanks to PureScript's GADTs.
-- |
-- | ### See also
-- |
-- | - https://github.com/chalk/chalk#chalkstylestylestring-string
module Choku.Style
( Style
, reset
, bold
, dim
, italic
, underline
, overline
, inverse
, hidden
, strikethrough
, black
, red
, green
, yellow
, blue
, magenta
, cyan
, white
, blackBright
, gray
, grey
, redBright
, greenBright
, yellowBright
, blueBright
, magentaBright
, cyanBright
, whiteBright
, bgBlack
, bgRed
, bgGreen
, bgYellow
, bgBlue
, bgMagenta
, bgCyan
, bgWhite
, bgBlackBright
, bgGray
, bgGrey
, bgRedBright
, bgGreenBright
, bgYellowBright
, bgBlueBright
, bgMagentaBright
, bgCyanBright
, bgWhiteBright
, fg
, bg
) where
import Data.Function.Uncurried (Fn3, runFn3)
import Choku.Common (Choku)
import Choku.Color (Color(..))
type Style = Choku -> Choku
{- Modifiers -}
foreign import reset :: Style
foreign import bold :: Style
foreign import dim :: Style
foreign import italic :: Style
foreign import underline :: Style
foreign import overline :: Style
foreign import inverse :: Style
foreign import hidden :: Style
foreign import strikethrough :: Style
{- Foreground colors -}
foreign import black :: Style
foreign import red :: Style
foreign import green :: Style
foreign import yellow :: Style
foreign import blue :: Style
foreign import magenta :: Style
foreign import cyan :: Style
foreign import white :: Style
foreign import blackBright :: Style
foreign import gray :: Style
foreign import grey :: Style
foreign import redBright :: Style
foreign import greenBright :: Style
foreign import yellowBright :: Style
foreign import blueBright :: Style
foreign import magentaBright :: Style
foreign import cyanBright :: Style
foreign import whiteBright :: Style
{- Background colors -}
foreign import bgBlack :: Style
foreign import bgRed :: Style
foreign import bgGreen :: Style
foreign import bgYellow :: Style
foreign import bgBlue :: Style
foreign import bgMagenta :: Style
foreign import bgCyan :: Style
foreign import bgWhite :: Style
foreign import bgBlackBright :: Style
foreign import bgGray :: Style
foreign import bgGrey :: Style
foreign import bgRedBright :: Style
foreign import bgGreenBright :: Style
foreign import bgYellowBright :: Style
foreign import bgBlueBright :: Style
foreign import bgMagentaBright :: Style
foreign import bgCyanBright :: Style
foreign import bgWhiteBright :: Style
{- 256 and Truecolor support -}
foreign import _rgb :: Fn3 Int Int Int Style
foreign import _hex :: String -> Style
foreign import _ansi256 :: Int -> Style
foreign import _bgRgb :: Fn3 Int Int Int Style
foreign import _bgHex :: String -> Style
foreign import _bgAnsi256 :: Int -> Style
-- | Modify foreground color.
fg :: Color -> Style
fg (RGB { r, g, b }) = runFn3 _rgb r g b
fg (Hex hex) = _hex hex
fg (ANSI256 i) = _ansi256 i
-- | Modify background color.
bg :: Color -> Style
bg (RGB { r, g, b }) = runFn3 _bgRgb r g b
bg (Hex hex) = _bgHex hex
bg (ANSI256 i) = _bgAnsi256 i