-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathmouse.nim
42 lines (37 loc) · 1.03 KB
/
mouse.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
import os, illwill
proc exitProc() {.noconv.} =
illwillDeinit()
showCursor()
quit(0)
illwillInit(fullscreen=true, mouse=true)
setControlCHook(exitProc)
hideCursor()
var tb = newTerminalBuffer(terminalWidth(), terminalHeight())
while true:
tb.write(0, 0, fgWhite, styleBright, "Draw with left/right/middle click; hold Ctrl for brigher colours")
tb.write(0, 1, "Press Q or Ctrl-C to quit")
var key = getKey()
case key
of Key.None: discard
of Key.Escape, Key.Q: exitProc()
of Key.Mouse:
let mi = getMouse()
if mi.action == MouseButtonAction.mbaPressed:
let style: Style =
if mi.ctrl: styleBright
else: styleDim
case mi.button
of mbLeft:
tb.write mi.x, mi.y, fgRed, style, "♥"
of mbMiddle:
tb.write mi.x, mi.y, fgBlue, style, "◉"
of mbRight:
tb.write mi.x, mi.y, fgCyan, style, "#"
else: discard
elif mi.action == MouseButtonAction.mbaReleased:
tb.write mi.x, mi.y, "^"
else:
echo key
discard
tb.display()
sleep(10)