-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathboxdrawing.nim
109 lines (81 loc) · 2.97 KB
/
boxdrawing.nim
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
# Example demonstrating the various box drawing methods.
import illwill
import os
proc exitProc() {.noconv.} =
illwillDeinit()
showCursor()
quit(0)
proc main() =
illwillInit(fullscreen=true)
setControlCHook(exitProc)
hideCursor()
while true:
var tb = newTerminalBuffer(terminalWidth(), terminalHeight())
var key = getKey()
case key
of Key.Escape, Key.Q: exitProc()
else: discard
tb.write(0, 0, "Press Q, Esc or Ctrl-C to quit")
# (1) TerminalBuffer.drawRect doesn't connect overlapping lines
tb.setForegroundColor(fgGreen)
tb.drawRect(2, 3, 14, 5, doubleStyle=true)
tb.drawRect(6, 2, 10, 6)
tb.write(7, 7, fgWhite, "(1)")
# (2) BoxBuffer.drawRect, however, does by default
var bb = newBoxBuffer(tb.width, tb.height)
bb.drawRect(20, 3, 32, 5, doubleStyle=true)
bb.drawRect(24, 2, 28, 6)
tb.setForegroundColor(fgBlue)
tb.write(bb)
tb.write(25, 7, fgWhite, "(2)")
# (3) BoxBuffer.drawRect with connect=false
bb = newBoxBuffer(tb.width, tb.height)
bb.drawRect(38, 3, 50, 5, doubleStyle=true, connect=false)
bb.drawRect(42, 2, 46, 6, connect=false)
tb.setForegroundColor(fgRed)
tb.write(bb)
tb.write(43, 7, fgWhite, "(3)")
# (4) Smallest possible rectangle to draw
tb.setForegroundColor(fgWhite)
tb.drawRect(7, 9, 8, 10)
tb.write(7, 11, fgWhite, "(4)")
# (5) Rectangle too small, draw nothing
tb.setForegroundColor(fgMagenta)
tb.drawRect(25, 9, 25, 9)
tb.write(25, 11, fgWhite, "(5)")
# (6) TerminalBuffer.drawHorizLine/drawVertLine doesn't connect
# overlapping lines
tb.setForegroundColor(fgYellow)
tb.drawHorizLine(2, 14, 14, doubleStyle=true)
tb.drawVertLine(4, 13, 15, doubleStyle=true)
tb.drawVertLine(6, 13, 15)
tb.drawVertLine(10, 13, 16)
tb.drawHorizLine(4, 12, 15, doubleStyle=true)
tb.write(7, 17, fgWhite, "(6)")
# (7) TerminalBuffer.drawHorizLine/drawVertLine does connect
# overlapping lines by default
bb = newBoxBuffer(tb.width, tb.height)
bb.drawHorizLine(20, 32, 14, doubleStyle=true)
bb.drawVertLine(22, 13, 15, doubleStyle=true)
bb.drawVertLine(24, 13, 15)
bb.drawVertLine(28, 13, 16)
bb.drawHorizLine(22, 30, 15, doubleStyle=true)
tb.setForegroundColor(fgCyan)
tb.write(bb)
tb.write(25, 17, fgWhite, "(7)")
# (8) TerminalBuffer.drawHorizLine/drawVertLine does connect
# overlapping lines by default
bb = newBoxBuffer(tb.width, tb.height)
bb.drawHorizLine(38, 50, 14, doubleStyle=true, connect=false)
bb.drawVertLine(40, 13, 15, doubleStyle=true, connect=false)
bb.drawVertLine(42, 13, 15, connect=false)
bb.drawVertLine(46, 13, 16, connect=false)
bb.drawHorizLine(40, 48, 15, doubleStyle=true, connect=false)
tb.setForegroundColor(fgMagenta)
tb.write(bb)
tb.write(43, 17, fgWhite, "(8)")
tb.write(0, 20,
"Check the source code for the description of the test cases ")
tb.display()
sleep(20)
main()