-
Notifications
You must be signed in to change notification settings - Fork 0
/
beKnowledge.ldpl
194 lines (181 loc) · 7.1 KB
/
beKnowledge.ldpl
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
data:
fileContents is text
i is number
speed is number
auxNumber is number
wordLength is number
percent is number
hasPausedOnStart is number
pages is number
nextWord is text
prevWord is text
displayText is text
mode is number
procedure:
if argc is less than 1 then
display "\033[1;31mError\033[0m: no text file specified." crlf
display "Usage: $ beKnowledge <text file name>" crlf
exit
end if
if argc is greater than 1 then
display "\033[1;31mError\033[0m: too many arguments passed." crlf
display "Usage: $ beKnowledge <text file name>" crlf
exit
end if
execute "clear"
display crlf " +-----------------------------------+" crlf
display " | \033[1;31mbeKnowledge\033[0m |" crlf
display " | \033[0;37mgithub.com/lartu/beKnowledge/ |" crlf
display " | by Martín del Río (www.lartu.net)\033[0m |" crlf
display " +-----------------------------------+" crlf crlf
# Load text.txt
display "- (1/4) Loading " argv:0 "..."
load file argv:0 in fileContents
store length of fileContents in wordLength
if errorcode is not equal to 0 then
display crlf
display "\033[1;31mError\033[0m: the file '" argv:0 "' was empty or not found." crlf
exit
else
display " \033[1;32mOK\033[0m" crlf
end if
# Remove line breaks
display "- (2/4) Splitting lines (this may take some time)..."
store "\n" in explode/separator
store fileContents in explode/string
call sub-procedure explode
display " \033[1;32mOK\033[0m" crlf
display "- (3/4) Joining lines..."
store "" in fileContents
store 0 in i
while i is less than or equal to explode/length do
in fileContents join fileContents explode/words:i " "
add 1 and i in i
repeat
display " \033[1;32mOK\033[0m" crlf
# Explode text into words and print them
display "- (4/4) Splitting words (this may take some time)... "
store " " in explode/separator
store fileContents in explode/string
call sub-procedure explode
display " \033[1;32mOK\033[0m" crlf
display crlf "Choose your reading speed (milliseconds per word) (default 100): "
accept speed
display crlf "Choose a reading mode (\033[1;34m0\033[0m: 1 word at a time, \033[1;34m1\033[0m: 3 words at a time): "
accept mode
display crlf "This file has \033[1;35m" explode/length " words\033[0m. From which word would you like to start?" crlf
display "(enter 0 if you'd like to start from the first word): "
accept i
store "" in fileContents
store "" in prevWord
store "" in nextWord
if mode is equal to 0 then
# Single word mode
while i is less than or equal to explode/length do
if explode/words:i is not equal to "" then
execute "clear"
multiply i by 100 in percent
divide percent by explode/length in percent
floor percent
divide i by 280 in pages #Average of 280 words per page in a normal book
floor pages
display "\033[0;36mWord count " i "/" explode/length " (" percent "%) You've read " pages " average book pages.\033[0m"
# Print line breaks
display crlf crlf crlf crlf crlf crlf crlf crlf crlf crlf
# Print spaces so all words appear centered on the same point
store length of explode/words:i in wordLength
divide wordLength by 2 in wordLength
if wordLength is greater than 40 then
store 40 in wordLength
end if
subtract wordLength from 40 in wordLength
while wordLength is greater than 0 do
display " "
subtract 1 from wordLength in wordLength
repeat
# Display word and wait
display explode/words:i crlf
wait speed milliseconds
end if
# Pause speed x 10 every 50 words
modulo i by 50 in auxNumber
if auxNumber is equal to 0 then
store 9 in auxNumber
while auxNumber is greater than 0 do
wait speed milliseconds
subtract 1 from auxNumber in auxNumber
repeat
end if
# Every 1000 words ask for input before continuing.
if hasPausedOnStart is equal to 1 then
modulo i by 1000 in auxNumber
if auxNumber is equal to 0 then
display crlf crlf "\033[1;34mYou've read " i " words. Press ENTER to continue.\033[0m"
accept fileContents
end if
else
display crlf crlf "\033[1;34mPress ENTER to start. You'll be given time to blink every 50 words" crlf
display "and a pause every 1000 words.\033[0m"
accept fileContents
store 1 in hasPausedOnStart
end if
add 1 and i in i
repeat
else
# Three word mode
while i is less than or equal to explode/length do
if explode/words:i is not equal to "" then
execute "clear"
multiply i by 100 in percent
divide percent by explode/length in percent
floor percent
divide i by 280 in pages #Average of 280 words per page in a normal book
floor pages
display "\033[0;36mWord count " i "/" explode/length " (" percent "%) You've read " pages " average book pages.\033[0m"
# Print line breaks
display crlf crlf crlf crlf crlf crlf crlf crlf crlf crlf
add 1 and i in i
store explode/words:i in nextWord
subtract 1 from i in i
# Print spaces so all words appear centered on the same point
in displayText join prevWord " " explode/words:i " " nextWord
store length of displayText in wordLength
divide wordLength by 2 in wordLength
if wordLength is greater than 40 then
store 40 in wordLength
end if
subtract wordLength from 40 in wordLength
while wordLength is greater than 0 do
display " "
subtract 1 from wordLength in wordLength
repeat
# Display word and wait
display displayText crlf
store explode/words:i in prevWord
wait speed milliseconds
end if
# Pause speed x 10 every 50 words
modulo i by 50 in auxNumber
if auxNumber is equal to 0 then
store 9 in auxNumber
while auxNumber is greater than 0 do
wait speed milliseconds
subtract 1 from auxNumber in auxNumber
repeat
end if
# Every 1000 words ask for input before continuing.
if hasPausedOnStart is equal to 1 then
modulo i by 1000 in auxNumber
if auxNumber is equal to 0 then
display crlf crlf "\033[1;34mYou've read " i " words. Press ENTER to continue.\033[0m"
accept fileContents
end if
else
display crlf crlf "\033[1;34mPress ENTER to start. You'll be given time to blink every 50 words" crlf
display "and a pause every 1000 words.\033[0m"
accept fileContents
store 1 in hasPausedOnStart
end if
add 1 and i in i
repeat
end if