-
Notifications
You must be signed in to change notification settings - Fork 5
/
Output.purs
51 lines (40 loc) · 1.46 KB
/
Output.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
-- | Convenience functions to simplify outputting ANSI escape codes to
-- | terminals.
module Ansi.Output where
import Prelude
import Ansi.Codes (Color, EscapeCode(..), GraphicsParam(..), RenderingMode(..), escapeCodeToString)
-- | Wrap the given text in escape codes corresponding to the given parameters.
-- | For example:
-- |
-- | ```purescript
-- | Console.log $ withGraphics (bold <> underline <> foreground BrightRed) "hello world"
-- | ```
-- |
-- | would print "hello world" to the terminal, bold, underlined, and in bright
-- | red, and then reset (so that further logging to the console uses the
-- | normal color and style).
-- |
-- | This function simply wraps the given text in an escape code and a reset
-- | code, so that it is a little more comfortable to use than the functions
-- | in `Ansi.Codes`.
withGraphics :: Array GraphicsParam -> String -> String
withGraphics params text =
escapeCodeToString (Graphics params) <>
text <>
escapeCodeToString (Graphics [Reset])
bold :: Array GraphicsParam
bold = [PMode Bold]
dim :: Array GraphicsParam
dim = [PMode Dim]
italic :: Array GraphicsParam
italic = [PMode Italic]
underline :: Array GraphicsParam
underline = [PMode Underline]
inverse :: Array GraphicsParam
inverse = [PMode Inverse]
strikethrough :: Array GraphicsParam
strikethrough = [PMode Strikethrough]
foreground :: Color -> Array GraphicsParam
foreground c = [PForeground c]
background :: Color -> Array GraphicsParam
background c = [PBackground c]