summaryrefslogtreecommitdiff
path: root/src/System/IO/Terminal/Characters.hs
blob: 85f8b5f558e06295843d5a9762acc5d2d9f6e018 (plain)
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
{-|
Module      : System.IO.Terminal.Characters
Copyright   : (c) UU, 2019
License     : MIT
Maintainer  : Tom Smeding
Stability   : experimental
Portability : POSIX, macOS, Windows

Access to a small database of box-drawing characters.
-}
module System.IO.Terminal.Characters
    (boxChar, BoxChar, BoxWeight(..))
    where

import qualified Data.Map.Strict as Map


-- | Description of a box-drawing character: (up, right, down, left)
type BoxChar = (BoxWeight, BoxWeight, BoxWeight, BoxWeight)

-- | Description of one arm of a box-drawing character.
data BoxWeight = BoxNone | BoxSingle | BoxHeavy | BoxDouble
  deriving (Eq, Ord, Show)

-- | Look up a box drawing character in the unicode table. Note that not
-- all combinations are valid; currently, the function throws an error if
-- the character doesn't exist.
boxChar :: BoxChar -> Char
boxChar tup = mapping Map.! tup
  where
    mapping = Map.fromList
        [((BoxNone, BoxNone, BoxNone, BoxSingle), '╴')
        ,((BoxNone, BoxNone, BoxNone, BoxHeavy), '╸')
        ,((BoxSingle, BoxNone, BoxNone, BoxNone), '╵')
        ,((BoxHeavy, BoxNone, BoxNone, BoxNone), '╹')
        ,((BoxNone, BoxSingle, BoxNone, BoxNone), '╶')
        ,((BoxNone, BoxHeavy, BoxNone, BoxNone), '╺')
        ,((BoxNone, BoxNone, BoxSingle, BoxNone), '╷')
        ,((BoxNone, BoxNone, BoxHeavy, BoxNone), '╻')
        ,((BoxNone, BoxSingle, BoxNone, BoxSingle), '─')
        ,((BoxNone, BoxHeavy, BoxNone, BoxHeavy), '━')
        ,((BoxNone, BoxHeavy, BoxNone, BoxSingle), '╼')
        ,((BoxNone, BoxSingle, BoxNone, BoxHeavy), '╾')
        ,((BoxSingle, BoxNone, BoxSingle, BoxNone), '│')
        ,((BoxHeavy, BoxNone, BoxHeavy, BoxNone), '┃')
        ,((BoxSingle, BoxNone, BoxHeavy, BoxNone), '╽')
        ,((BoxHeavy, BoxNone, BoxSingle, BoxNone), '╿')
        ,((BoxNone, BoxSingle, BoxSingle, BoxNone), '┌')
        ,((BoxNone, BoxHeavy, BoxSingle, BoxNone), '┍')
        ,((BoxNone, BoxSingle, BoxHeavy, BoxNone), '┎')
        ,((BoxNone, BoxHeavy, BoxHeavy, BoxNone), '┏')
        ,((BoxNone, BoxNone, BoxSingle, BoxSingle), '┐')
        ,((BoxNone, BoxNone, BoxSingle, BoxHeavy), '┑')
        ,((BoxNone, BoxNone, BoxHeavy, BoxSingle), '┒')
        ,((BoxNone, BoxNone, BoxHeavy, BoxHeavy), '┓')
        ,((BoxSingle, BoxSingle, BoxNone, BoxNone), '└')
        ,((BoxSingle, BoxHeavy, BoxNone, BoxNone), '┕')
        ,((BoxHeavy, BoxSingle, BoxNone, BoxNone), '┖')
        ,((BoxHeavy, BoxHeavy, BoxNone, BoxNone), '┗')
        ,((BoxSingle, BoxNone, BoxNone, BoxSingle), '┘')
        ,((BoxSingle, BoxNone, BoxNone, BoxHeavy), '┙')
        ,((BoxHeavy, BoxNone, BoxNone, BoxSingle), '┚')
        ,((BoxHeavy, BoxNone, BoxNone, BoxHeavy), '┛')
        ,((BoxSingle, BoxSingle, BoxSingle, BoxNone), '├')
        ,((BoxSingle, BoxHeavy, BoxSingle, BoxNone), '┝')
        ,((BoxHeavy, BoxSingle, BoxSingle, BoxNone), '┞')
        ,((BoxSingle, BoxSingle, BoxHeavy, BoxNone), '┟')
        ,((BoxHeavy, BoxSingle, BoxHeavy, BoxNone), '┠')
        ,((BoxHeavy, BoxHeavy, BoxSingle, BoxNone), '┡')
        ,((BoxSingle, BoxHeavy, BoxHeavy, BoxNone), '┢')
        ,((BoxHeavy, BoxHeavy, BoxHeavy, BoxNone), '┣')
        ,((BoxSingle, BoxNone, BoxSingle, BoxSingle), '┤')
        ,((BoxSingle, BoxNone, BoxSingle, BoxHeavy), '┥')
        ,((BoxHeavy, BoxNone, BoxSingle, BoxSingle), '┦')
        ,((BoxSingle, BoxNone, BoxHeavy, BoxSingle), '┧')
        ,((BoxHeavy, BoxNone, BoxHeavy, BoxSingle), '┨')
        ,((BoxHeavy, BoxNone, BoxSingle, BoxHeavy), '┩')
        ,((BoxSingle, BoxNone, BoxHeavy, BoxHeavy), '┪')
        ,((BoxHeavy, BoxNone, BoxHeavy, BoxHeavy), '┫')
        ,((BoxNone, BoxSingle, BoxSingle, BoxSingle), '┬')
        ,((BoxNone, BoxSingle, BoxSingle, BoxHeavy), '┭')
        ,((BoxNone, BoxHeavy, BoxSingle, BoxSingle), '┮')
        ,((BoxNone, BoxHeavy, BoxSingle, BoxHeavy), '┯')
        ,((BoxNone, BoxSingle, BoxHeavy, BoxSingle), '┰')
        ,((BoxNone, BoxSingle, BoxHeavy, BoxHeavy), '┱')
        ,((BoxNone, BoxHeavy, BoxHeavy, BoxSingle), '┲')
        ,((BoxNone, BoxHeavy, BoxHeavy, BoxHeavy), '┳')
        ,((BoxSingle, BoxSingle, BoxNone, BoxSingle), '┴')
        ,((BoxSingle, BoxSingle, BoxNone, BoxHeavy), '┵')
        ,((BoxSingle, BoxHeavy, BoxNone, BoxSingle), '┶')
        ,((BoxSingle, BoxHeavy, BoxNone, BoxHeavy), '┷')
        ,((BoxHeavy, BoxSingle, BoxNone, BoxSingle), '┸')
        ,((BoxHeavy, BoxSingle, BoxNone, BoxHeavy), '┹')
        ,((BoxHeavy, BoxHeavy, BoxNone, BoxSingle), '┺')
        ,((BoxHeavy, BoxHeavy, BoxNone, BoxHeavy), '┻')
        ,((BoxSingle, BoxSingle, BoxSingle, BoxSingle), '┼')
        ,((BoxSingle, BoxSingle, BoxSingle, BoxHeavy), '┽')
        ,((BoxSingle, BoxHeavy, BoxSingle, BoxSingle), '┾')
        ,((BoxSingle, BoxHeavy, BoxSingle, BoxHeavy), '┿')
        ,((BoxHeavy, BoxSingle, BoxSingle, BoxSingle), '╀')
        ,((BoxSingle, BoxSingle, BoxHeavy, BoxSingle), '╁')
        ,((BoxHeavy, BoxSingle, BoxHeavy, BoxSingle), '╂')
        ,((BoxHeavy, BoxSingle, BoxSingle, BoxHeavy), '╃')
        ,((BoxHeavy, BoxHeavy, BoxSingle, BoxSingle), '╄')
        ,((BoxSingle, BoxSingle, BoxHeavy, BoxHeavy), '╅')
        ,((BoxSingle, BoxHeavy, BoxHeavy, BoxSingle), '╆')
        ,((BoxHeavy, BoxHeavy, BoxSingle, BoxHeavy), '╇')
        ,((BoxSingle, BoxHeavy, BoxHeavy, BoxHeavy), '╈')
        ,((BoxHeavy, BoxSingle, BoxHeavy, BoxHeavy), '╉')
        ,((BoxHeavy, BoxHeavy, BoxHeavy, BoxSingle), '╊')
        ,((BoxHeavy, BoxHeavy, BoxHeavy, BoxHeavy), '╋')
        ,((BoxNone, BoxDouble, BoxNone, BoxDouble), '═')
        ,((BoxDouble, BoxNone, BoxDouble, BoxNone), '║')
        ,((BoxNone, BoxDouble, BoxSingle, BoxNone), '╒')
        ,((BoxNone, BoxSingle, BoxDouble, BoxNone), '╓')
        ,((BoxNone, BoxDouble, BoxDouble, BoxNone), '╔')
        ,((BoxNone, BoxNone, BoxSingle, BoxDouble), '╕')
        ,((BoxNone, BoxNone, BoxDouble, BoxSingle), '╖')
        ,((BoxNone, BoxNone, BoxDouble, BoxDouble), '╗')
        ,((BoxSingle, BoxDouble, BoxNone, BoxNone), '╘')
        ,((BoxDouble, BoxSingle, BoxNone, BoxNone), '╙')
        ,((BoxDouble, BoxDouble, BoxNone, BoxNone), '╚')
        ,((BoxSingle, BoxNone, BoxNone, BoxDouble), '╛')
        ,((BoxDouble, BoxNone, BoxNone, BoxSingle), '╜')
        ,((BoxDouble, BoxNone, BoxNone, BoxDouble), '╝')
        ,((BoxSingle, BoxDouble, BoxSingle, BoxNone), '╞')
        ,((BoxDouble, BoxSingle, BoxDouble, BoxNone), '╟')
        ,((BoxDouble, BoxDouble, BoxDouble, BoxNone), '╠')
        ,((BoxSingle, BoxNone, BoxSingle, BoxDouble), '╡')
        ,((BoxDouble, BoxNone, BoxDouble, BoxSingle), '╢')
        ,((BoxDouble, BoxNone, BoxDouble, BoxDouble), '╣')
        ,((BoxNone, BoxDouble, BoxSingle, BoxDouble), '╤')
        ,((BoxNone, BoxSingle, BoxDouble, BoxSingle), '╥')
        ,((BoxNone, BoxDouble, BoxDouble, BoxDouble), '╦')
        ,((BoxSingle, BoxDouble, BoxNone, BoxDouble), '╧')
        ,((BoxDouble, BoxSingle, BoxNone, BoxSingle), '╨')
        ,((BoxDouble, BoxDouble, BoxNone, BoxDouble), '╩')
        ,((BoxSingle, BoxDouble, BoxSingle, BoxDouble), '╪')
        ,((BoxDouble, BoxSingle, BoxDouble, BoxSingle), '╫')
        ,((BoxDouble, BoxDouble, BoxDouble, BoxDouble), '╬')]