-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtyping.nim
42 lines (35 loc) · 1 KB
/
typing.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 unicode
import csfml
var window = new_RenderWindow(video_mode(800, 600), "Typing")
window.vertical_sync_enabled = true
var str = new_seq[Rune]()
var font = new_Font("resources/sansation.ttf")
var text = new_Text("_", font)
text.color = Black
while window.open:
var event: Event
while window.poll_event(event):
case event.kind
of EventType.KeyPressed:
case event.key.code
of KeyCode.Escape:
window.close()
of KeyCode.Backspace:
if str.len > 0:
discard str.pop()
of KeyCode.Enter:
str.add Rune(10)
else: discard
of EventType.TextEntered:
if ord(event.text.unicode) >= ord(' '):
str.add event.text.unicode
text.str = $str & "_"
of EventType.Closed:
window.close()
else: discard
window.clear White
window.draw text
window.display()
text.destroy()
font.destroy()
window.destroy()