Box drawing character library

Hi all. This is a small library for rendering and combining Unicode box drawing characters with a simple monoidal interface. It is spun out of a text table/box drawing library I began but have not found the time for. It may also be useful for TUI libraries going for a little more fanciness.

It encapsulates the fairly long/tedious job of enumerating what combinations of box drawing characters should look like, using code that I originally wrote with Template Haskell, but then extracted with -ddump-splices to remove the TH dep. The internal representation is as a Word8 bitfield, with 4 bits for up/down/left/right, and 4 bits for style selection.

Tiny demonstration:

>>> mapM_ putStrLn $ map (\x -> let s = show x in s ++ replicate (40 - length s) ' ' ++ " ==> " ++ [render unicode x]) [up,down,left,right,horizontal,vertical,horizontal<>vertical,up<>horizontal,up<>right,right<>down,right<>down<>rounded,right<>down<>double, doubleVert <> horizontal <> up, doubleHoriz <> vertical <> right]
Drawing Light [BUp]                      ==> ╵
Drawing Light [BDown]                    ==> ╷
Drawing Light [BLeft]                    ==> ╴
Drawing Light [BRight]                   ==> ╶
Drawing Light [BLeft,BRight]             ==> ─
Drawing Light [BUp,BDown]                ==> │
Drawing Light [BUp,BDown,BLeft,BRight]   ==> ┼
Drawing Light [BUp,BLeft,BRight]         ==> ┴
Drawing Light [BUp,BRight]               ==> └
Drawing Light [BDown,BRight]             ==> ┌
Drawing Rounded [BDown,BRight]           ==> ╭
Drawing Double [BDown,BRight]            ==> ╔
Drawing DoubleVert [BUp,BLeft,BRight]    ==> ╨
Drawing DoubleHoriz [BUp,BDown,BRight]   ==> ╞
10 Likes