-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
181 lines (148 loc) · 4.57 KB
/
main.lua
File metadata and controls
181 lines (148 loc) · 4.57 KB
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
utf8 = require("utf8")
sd = require("res.savedata")
cs = require("res.cscreen")
cmd = require("res.commands_base")
require("res.commands_load")
require("res.theme")
require("res.misc")
function love.load(args)
_l_font = love.graphics.newFont("res/JetBrainsMono.ttf", 26)
_u_font = love.graphics.newFont("res/JetBrainsMono.ttf", 24)
_i_font = love.graphics.newFont("res/JetBrainsMono.ttf", 16)
love.keyboard.setKeyRepeat(true)
_app = {}
_app.w, _app.h, _app.flags = love.window.getMode()
_app.dir = love.filesystem.getSaveDirectory()
_app.theme = config_theme() or theme_eclipse()
_app.index = false
_app.pages = {{0}, {1}}
for i = 2, 5 do
_app.pages[1][i] = -540 * (i-1)
end
for i = 2, 5 do
_app.pages[2][i] = (18 * (i-1)) + 1
end
_app.page_sel = 1
cs.init(_app.w, _app.h, true)
_todo_table = {}
_mem = {}
_cmd_mem = ""
_action_table = {
{action = "return", func = function() cmd:run() sd.save(_todo_table,".cache") end},
{action = "backspace", func = function() _u_input = _u_input:sub(1, -2) end},
{action = "escape", func = function() love.event.quit() end},
{action = "up", func = function() cmd:back() end},
{action = "down", func = function() _u_input = "" end},
}
_timer = 0
_cursor = "█"
_u_input = ""
_g_input = "type 'help' to get info about commands"
if love.filesystem.getInfo(".cache", "file") == nil then
sd.save(_todo_table, ".cache")
else
_todo_table = sd.load(".cache")
end
end
-- ----------DRAW----------
function love.draw()
cs.apply()
cs.setColor(_app.theme[1])
love.graphics.setBackgroundColor(_app.theme[1])
love.graphics.setColor(_app.theme[2])
if _app.index then
love.graphics.rectangle("fill", 0, 0, 22, _app.h)
end
if _app.index then
for i = _app.pages[2][_app.page_sel], 18*_app.page_sel do
if i > #_todo_table then break end
love.graphics.setColor(_app.theme[4])
love.graphics.print(i, _i_font, 1, _app.pages[1][_app.page_sel]+(-18+(i*30)), 0)
if _todo_table[i][2] > 0 and _todo_table[i][2] <= 3 then
love.graphics.setColor(_app.theme[_todo_table[i][2]+4])
else
love.graphics.setColor(_app.theme[3])
end
love.graphics.print(_todo_table[i][1] or "", _l_font, 23, _app.pages[1][_app.page_sel]+(-25+(i*30)), 0)
end
else
for i = _app.pages[2][_app.page_sel], 18*_app.page_sel do
if i > #_todo_table then break end
if _todo_table[i][2] > 0 and _todo_table[i][2] <= 3 then
love.graphics.setColor(_app.theme[_todo_table[i][2]+4])
else
love.graphics.setColor(_app.theme[3])
end
love.graphics.print(_todo_table[i][1] or "", _l_font, 15, _app.pages[1][_app.page_sel]+(-25+(i*30)), 0)
end
end
love.graphics.setColor(_app.theme[2])
love.graphics.rectangle("fill", 0, _app.h-40, _app.w, _app.h)
love.graphics.rectangle("line", 1, 1, _app.w-1, _app.h-1)
if _u_input == "" and _g_input ~= "" then
love.graphics.setColor(_app.theme[4])
love.graphics.print(">> ".._g_input, _u_font, 5, _app.h-35, 0)
else
love.graphics.setColor(_app.theme[3])
love.graphics.print(">> ".._u_input.._cursor, _u_font, 5, _app.h-35, 0)
end
cs.cease()
end
-- ----------UPDATE----------
function love.update()
_timer = _timer + 1
if _timer >= 20 then
if _cursor == "█" then _cursor = " "
else _cursor = "█" end
_timer = 0
end
end
-- ----------KEYPRESSED----------
function love.keypressed(key)
_key = key
if _g_input ~= "" then _g_input = "" end
for i = 1, #_action_table do
if key == _action_table[i].action then
_action_table[i].func()
break
end
end
if love.keyboard.isDown("lctrl") and key == "v" then
paste()
end
if love.keyboard.isDown("f11") then
local fscr = love.window.getFullscreen()
love.window.setFullscreen(not fscr)
end
print("KEY >> "..key)
end
-- ----------TEXTINPUT----------
function love.textinput(text)
if #_u_input < 52 then
_u_input = _u_input..text
end
end
function love.lowmemory()
collectgarbage()
end
-- ----------FILE DROPPED----------
function love.filedropped(file)
local temp = tostring(os.time())
print(temp)
file:open("r")
local data = file:read()
if data:sub(1, 6) ~= "return" then return end
love.filesystem.write(temp, data)
mem()
local list = sd.load(temp)
love.filesystem.remove(temp)
_todo_table = list
end
-- ----------RESIZE----------
function love.resize(w, h)
cs.update(w, h)
end
-- ----------QUIT----------
function love.quit()
sd.save(_app.theme, "theme.yacf")
end