-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
430 lines (385 loc) · 15.6 KB
/
Copy pathinit.lua
File metadata and controls
430 lines (385 loc) · 15.6 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
-- ~/.config/lite-xl/init.lua
-- VS Code Everforest Light layout for Lite-XL
-- Load order is critical — do NOT reorder these blocks.
local core = require "core"
local config = require "core.config"
local style = require "core.style"
local keymap = require "core.keymap"
local command = require "core.command"
local common = require "core.common"
-- Global Process Spawn Protection
-- Wraps process.start to prevent fatal Lua crashes when executables (like bash, gh, powershell) are missing.
local process = require "process"
local orig_process_start = process.start
function process.start(...)
local ok, a, b, c = pcall(orig_process_start, ...)
if ok then return a, b, c else return nil, a end
end
-- ── 1. Color scheme (must load before any rendering) ──────────────────────────
-- NOTE: Lua module names cannot contain hyphens. File is everforest_lite_xl.lua
require "colors.everforest_lite_xl"
-- ── 2. Font — Auto-Native OS Fonts ──────────────────────────────────────────────
-- First tries custom user fonts (Fira Code), then elegantly falls back to
-- native high-quality OS monospace fonts if they aren't installed.
local function try_load_font(path, size, opts)
local ok, f = pcall(renderer.font.load, path, size, opts or {})
return ok and f or nil
end
local os_fonts = {
USERDIR .. "/fonts/FiraCode-iScript.ttf",
USERDIR .. "/fonts/FiraCodeNerdFont-Regular.ttf",
}
if PLATFORM == "Windows" then
local windir = os.getenv("WINDIR") or "C:\\Windows"
table.insert(os_fonts, windir .. "\\Fonts\\consola.ttf") -- Consolas
table.insert(os_fonts, windir .. "\\Fonts\\lucon.ttf") -- Lucida Console
elseif PLATFORM == "Mac OS X" then
table.insert(os_fonts, "/System/Library/Fonts/Menlo.ttc")
table.insert(os_fonts, "/System/Library/Fonts/Monaco.ttf")
else
table.insert(os_fonts, "/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf")
table.insert(os_fonts, "/usr/share/fonts/truetype/liberation/LiberationMono-Regular.ttf")
table.insert(os_fonts, "/usr/share/fonts/dejavu/DejaVuSansMono.ttf")
end
local base_font = nil
local font_path_used = nil
for _, path in ipairs(os_fonts) do
base_font = try_load_font(path, 15 * SCALE)
if base_font then
font_path_used = path
break
end
end
if base_font then
style.font = base_font
style.big_font = try_load_font(font_path_used, 20 * SCALE) or base_font
style.code_font = base_font
-- Try to load icons, but fallback to base if missing
local NERD_PATH = USERDIR .. "/fonts/FiraCodeNerdFont-Regular.ttf"
style.icon_font = try_load_font(NERD_PATH, 14 * SCALE) or base_font
style.icon_big_font = try_load_font(NERD_PATH, 28 * SCALE) or base_font
end
-- ── 3. Editor behaviour (VS Code defaults) ────────────────────────────────────
config.tab_type = "soft"
config.indent_size = 4
config.max_project_files = 50000
config.line_limit = 120
config.highlight_current_line = true
config.mouse_wheel_scroll = 50 * SCALE
config.blink_period = 0.5
config.draw_whitespace = false
config.max_undos = 10000
config.file_size_limit = 10
config.ignore_files = {
"^%.git$", "^node_modules$", "^__pycache__$", "^%.DS_Store$",
"^venv$", "^%.venv$", "^build$", "^dist$", "^%.next$", "^vendor$",
"^%.gemini$", "^AppData$", "^%.config$", "^%.cache$", "^%.vscode$",
"^%.npm$", "^%.rustup$", "^%.cargo$", "^%.antigravity$", "^tempfiles$",
"^NTUSER%.DAT", "^ntuser%.dat", "%.tmp$", "%.log$", "%.cache$"
}
-- ── 4. Built-in plugin config ─────────────────────────────────────────────────
config.plugins.treeview = true
config.plugins.autocomplete = true
config.plugins.bracketmatch = true
config.plugins.autosave = false
config.plugins.minimap = true
config.plugins.drawwhitespace = false
config.plugins.lineguide = false
config.plugins.wordcount = false
-- ── 5. Hybrid Theme Universal Patches ──────────────────────────────────────────
local Node = require "core.node"
local old_node_draw_tabs = Node.draw_tabs
function Node:draw_tabs(...)
local old_text = style.text
local old_dim = style.dim
local old_bg2 = style.background2
if style.mossy then
style.background2 = style.tab_bar_background or style.mossy.activity_bg or style.background2
style.text = style.syntax.normal or style.text
style.dim = style.mossy.sidebar_text or style.dim
end
old_node_draw_tabs(self, ...)
style.text = old_text
style.dim = old_dim
style.background2 = old_bg2
end
local TreeView_ok, TreeView = pcall(require, "plugins.treeview")
if TreeView_ok then
local old_tv_draw = TreeView.draw
function TreeView:draw(...)
local old_bg2 = style.background2
local old_bg3 = style.background3
local old_text = style.text
local old_dim = style.dim
if style.mossy then
style.background2 = style.mossy.sidebar_bg or style.background2
style.background3 = style.mossy.activity_bg or style.background3
style.text = style.mossy.sidebar_text or style.text
style.dim = style.mossy.sidebar_muted or style.dim
end
old_tv_draw(self, ...)
style.background2 = old_bg2
style.background3 = old_bg3
style.text = old_text
style.dim = old_dim
end
end
local TitleView_ok, TitleView = pcall(require, "core.titleview")
if TitleView_ok then
local old_title_draw = TitleView.draw
function TitleView:draw(...)
local old_bg2 = style.background2
local old_bg3 = style.background3
local old_text = style.text
local old_dim = style.dim
if style.mossy then
style.background2 = style.titlebar_background or style.mossy.activity_bg or style.background2
style.background3 = style.titlebar_background or style.mossy.activity_bg or style.background3
style.text = style.titlebar_text or style.mossy.sidebar_text or style.text
style.dim = style.titlebar_text or style.mossy.sidebar_muted or style.dim
end
old_title_draw(self, ...)
style.background2 = old_bg2
style.background3 = old_bg3
style.text = old_text
style.dim = old_dim
end
end
local ToolbarView_ok, ToolbarView = pcall(require, "plugins.toolbarview")
if ToolbarView_ok then
local old_toolbar_draw = ToolbarView.draw
function ToolbarView:draw(...)
local old_bg2 = style.background2
local old_bg3 = style.background3
local old_text = style.text
local old_dim = style.dim
if style.mossy then
style.background2 = style.mossy.activity_bg or style.background2
style.background3 = style.mossy.activity_bg or style.background3
style.text = style.mossy.activity_icon_hl or style.text
style.dim = style.mossy.sidebar_muted or style.dim
end
old_toolbar_draw(self, ...)
style.background2 = old_bg2
style.background3 = old_bg3
style.text = old_text
style.dim = old_dim
end
end
-- ── 6. Custom plugins ─────────────────────────────────────────────────────────
-- mossy_icons must load before mossy_treeview (dependency order)
local function safe_require(mod)
local ok, err = pcall(require, mod)
if not ok then
core.warn("Failed to load %s: %s", mod, tostring(err))
local f = io.open(USERDIR .. "/error_log.txt", "a")
if f then
f:write("Failed to load " .. mod .. ": " .. tostring(err) .. "\n")
f:close()
end
end
end
safe_require "plugins.mossy_icons"
safe_require "plugins.mossy_treeview"
safe_require "plugins.toggle_terminal"
safe_require "plugins.git_timeline"
safe_require "plugins.github_actions"
safe_require "plugins.antigravity_sidebar"
safe_require "plugins.auto_healer"
safe_require "plugins.mossy_statusbar"
safe_require "plugins.loader_games"
safe_require "plugins.virtual_codespace_fs"
safe_require "plugins.github_codespaces"
safe_require "plugins.font_picker"
-- ── 6. Keybindings (VS Code parity) ──────────────────────────────────────────
keymap.add {
["ctrl+`"] = "terminal:toggle",
["ctrl+shift+a"] = "antigravity:toggle",
["ctrl+b"] = "treeview:toggle",
["ctrl+p"] = "core:open-file",
["ctrl+shift+p"] = "core:find-command",
["ctrl+shift+e"] = "treeview:focus",
["ctrl+/"] = "doc:toggle-line-comments",
["ctrl+d"] = "find-replace:select-next",
["ctrl+z"] = "doc:undo",
["ctrl+y"] = "doc:redo",
["ctrl+s"] = "doc:save",
["ctrl+w"] = "root:close-active",
["ctrl+shift+k"] = "doc:delete-lines",
["alt+up"] = "doc:move-lines-up",
["alt+down"] = "doc:move-lines-down",
["ctrl+shift+r"] = "core:restart",
["ctrl+shift+g"] = "git-timeline:toggle",
["alt+p"] = "pdf:open-file",
["ctrl+alt+p"] = "pdf:open-file",
["shift+alt+f"] = "lsp:format-document",
["alt+shift+f"] = "lsp:format-document",
["ctrl+alt+l"] = "lsp:toggle-servers",
["alt+l"] = "lsp:toggle-servers",
}
-- ── 7. Open CWD when launched without arguments from a project folder ─────────
local function is_generic_dir(path)
local p = path:lower():gsub("\\", "/")
local userprofile = (os.getenv("USERPROFILE") or ""):lower():gsub("\\", "/")
local exedir = EXEDIR:lower():gsub("\\", "/")
if p == userprofile then return true end
if p == userprofile .. "/desktop" then return true end
if p == userprofile .. "/documents" then return true end
if p == userprofile .. "/downloads" then return true end
if p == userprofile .. "/onedrive" then return true end
if p == userprofile .. "/onedrive/desktop" then return true end
if p == userprofile .. "/onedrive/documents" then return true end
if p == exedir then return true end
if p == "c:/windows/system32" then return true end
if p == "c:/windows" then return true end
return false
end
local STARTUP_CWD = system.absolute_path(".")
local original_add_project_directory = core.add_project_directory
function core.add_project_directory(path)
if #ARGS <= 1 and not core._cwd_handled then
core._cwd_handled = true
if STARTUP_CWD and STARTUP_CWD ~= path and not is_generic_dir(STARTUP_CWD) then
path = STARTUP_CWD
core.set_project_dir(STARTUP_CWD)
local recents = core.recent_projects
local dirname = common.normalize_volume(STARTUP_CWD)
if recents and dirname then
for i, v in ipairs(recents) do
if v == dirname then
table.remove(recents, i)
break
end
end
table.insert(recents, 1, dirname)
end
end
end
return original_add_project_directory(path)
end
-- ── 8. Responsive Filesystem Indexing ──────────────────────────────────────────
-- Keep UI silky smooth (60 FPS) while project files are indexed progressively
config.max_project_files = 10000
config.borderless = true
safe_require "plugins.resource_monitor"
-- Patch to prevent statusview crash when project_files is nil
local StatusView = require "core.statusview"
local orig_statusview_update = StatusView.update
function StatusView:update(...)
if core.project_files == nil then
core.project_files = {}
end
if orig_statusview_update then
return orig_statusview_update(self, ...)
end
end
-- ── 13. Fix Theme Inconsistency ──────────────────────────────────────────────
-- When switching themes, Lua doesn't delete unknown keys from the style table.
-- We hook module reloading to explicitly wipe style.mossy when a new theme loads,
-- so the mossy colors don't permanently bleed into standard themes.
local old_reload = core.reload_module
function core.reload_module(name)
if type(name) == "string" and name:match("^colors%.") then
style.mossy = nil
end
return old_reload(name)
end
-- ── 14. Hide Tab Overflow Arrows Visually ────────────────────────────────────
local Node = require "core.node"
local old_draw = Node.draw_tabs
local renderer = require "renderer"
function Node:draw_tabs(...)
local old_draw_text = renderer.draw_text
-- Intercept text rendering just for the tab bar
renderer.draw_text = function(font, text, x, y, color)
-- If it tries to draw the specific scroll/dropdown icons, skip them!
if text == "\u{f104}" or text == "\u{f105}" or text == "\u{f107}" then
return x
end
return old_draw_text(font, text, x, y, color)
end
local res = old_draw(self, ...)
-- Restore the normal text renderer immediately after
renderer.draw_text = old_draw_text
return res
end
-- ── Auto-Close Editor Splits on Startup ───────────────────────────────────────
core.add_thread(function()
coroutine.yield() -- Wait one frame for workspace to load
local max_iters = 20 -- Safety limit to prevent infinite loop
for iter = 1, max_iters do
local editor_nodes = {}
local function collect(node)
if node.type == "leaf" then
if not node.locked then table.insert(editor_nodes, node) end
elseif node.type ~= "leaf" then
collect(node.a)
collect(node.b)
end
end
collect(core.root_view.root_node)
if #editor_nodes <= 1 then break end
local source = editor_nodes[2]
local view = source.views[1]
if view then
source:remove_view(core.root_view.root_node, view)
-- Re-collect to find the surviving editor node, safely avoiding detached tables
local surviving_nodes = {}
local function collect_survivors(node)
if node.type == "leaf" then
if not node.locked then table.insert(surviving_nodes, node) end
elseif node.type ~= "leaf" then
collect_survivors(node.a)
collect_survivors(node.b)
end
end
collect_survivors(core.root_view.root_node)
if #surviving_nodes > 0 then
surviving_nodes[1]:add_view(view)
end
else
break -- no view to move, stop
end
end
end)
-- Window Opacity Setting
local settings_module = require "plugins.settings"
if settings_module then
settings_module.add("Appearance", {
{
label = "Window Opacity",
description = "Adjust the global transparency of the editor window (glass effect).",
path = "window_opacity",
type = settings_module.type.NUMBER,
default = 1.0,
min = 0.1,
max = 1.0,
step = 0.05,
on_apply = function(value)
if system.set_window_opacity then
system.set_window_opacity(value)
end
end
}
})
end
core.add_thread(function()
coroutine.yield()
if config.window_opacity and config.window_opacity < 1.0 then
if system.set_window_opacity then
system.set_window_opacity(config.window_opacity)
end
end
end)
-- 14. Native OS Font on startup (applied by font_picker plugin)
core.add_thread(function()
coroutine.yield(0.5) -- wait for plugins to load
if config.native_code_font and config.native_code_font ~= "" then
local ok, f = pcall(renderer.font.load, config.native_code_font, 15 * SCALE)
if ok and f then
style.code_font = f
style.font = f
core.redraw = true
end
end
end)