Merge branch 'master' of github.com:rxi/lite into more-languages

This commit is contained in:
Alexander Popiak 2020-06-02 11:41:03 +02:00
commit 3582d711eb
18 changed files with 207 additions and 135 deletions

View File

@ -1,13 +1,13 @@
#!/bin/bash
cflags="-Wall -O3 -g -std=gnu11 -Isrc -DLUA_USE_POPEN"
cflags="-Wall -O3 -g -std=gnu11 -Isrc"
lflags="-lSDL2 -lm"
if [[ $* == *windows* ]]; then
platform="windows"
outfile="lite.exe"
compiler="x86_64-w64-mingw32-gcc"
cflags="$cflags -Iwinlib/SDL2-2.0.10/x86_64-w64-mingw32/include"
cflags="$cflags -DLUA_USE_POPEN -Iwinlib/SDL2-2.0.10/x86_64-w64-mingw32/include"
lflags="$lflags -Lwinlib/SDL2-2.0.10/x86_64-w64-mingw32/lib"
lflags="-lmingw32 -lSDL2main $lflags -mwindows -o $outfile res.res"
x86_64-w64-mingw32-windres res.rc -O coff -o res.res
@ -15,6 +15,7 @@ else
platform="unix"
outfile="lite"
compiler="gcc"
cflags="$cflags -DLUA_USE_POSIX"
lflags="$lflags -o $outfile"
fi

View File

@ -35,7 +35,7 @@ command.add(nil, {
end)
end,
["core:command-finder"] = function()
["core:find-command"] = function()
local commands = command.get_all_valid()
core.command_view:enter("Do Command", function(text, item)
if item then
@ -54,15 +54,15 @@ command.add(nil, {
end)
end,
["core:file-finder"] = function()
["core:find-file"] = function()
core.command_view:enter("Open File From Project", function(text, item)
text = core.project_dir .. PATHSEP .. (item and item.text or text)
text = item and item.text or text
core.root_view:open_doc(core.open_doc(text))
end, function(text)
local files = {}
for _, item in pairs(core.project_files) do
if item.type == "file" then
table.insert(files, item.filename:sub(#core.project_dir + 2))
table.insert(files, item.filename)
end
end
return common.fuzzy_match(files, text)
@ -89,7 +89,7 @@ command.add(nil, {
end,
["core:open-project-module"] = function()
local filename = core.project_dir .. "/.lite_project.lua"
local filename = ".lite_project.lua"
if system.get_file_info(filename) then
core.root_view:open_doc(core.open_doc(filename))
else

View File

@ -320,10 +320,10 @@ local commands = {
local translations = {
["previous-char"] = translate.previous_char,
["next-char"] = translate.next_char,
["previous-word-boundary"] = translate.previous_word_boundary,
["next-word-boundary"] = translate.next_word_boundary,
["previous-start-of-block"] = translate.previous_start_of_block,
["next-start-of-block"] = translate.next_start_of_block,
["previous-word-start"] = translate.previous_word_start,
["next-word-end"] = translate.next_word_end,
["previous-block-start"] = translate.previous_block_start,
["next-block-end"] = translate.next_block_end,
["start-of-doc"] = translate.start_of_doc,
["end-of-doc"] = translate.end_of_doc,
["start-of-line"] = translate.start_of_line,

View File

@ -94,7 +94,7 @@ for _, dir in ipairs { "left", "right", "up", "down" } do
end
local node = core.root_view.root_node:get_child_overlapping_point(x, y)
if not node:get_locked_size() then
core.active_view = node.active_view
core.set_active_view(node.active_view)
end
end
end

View File

@ -111,9 +111,8 @@ function CommandView:enter(text, submit, suggest, cancel)
submit = submit or noop,
suggest = suggest or noop,
cancel = cancel or noop,
view = core.active_view
}
core.active_view = self
core.set_active_view(self)
self:update_suggestions()
self.gutter_text_brightness = 100
self.label = text .. ": "
@ -122,7 +121,7 @@ end
function CommandView:exit(submitted, inexplicit)
if core.active_view == self then
core.active_view = self.state.view
core.set_active_view(core.last_active_view)
end
local cancel = self.state.cancel
self.state = default_state

View File

@ -28,33 +28,32 @@ function translate.next_char(doc, line, col)
end
function translate.previous_word_boundary(doc, line, col)
local char = doc:get_char(doc:position_offset(line, col, -1))
local inword = not is_non_word(char)
repeat
local line2, col2 = line, col
line, col = doc:position_offset(line, col, -1)
if line == line2 and col == col2 then
function translate.previous_word_start(doc, line, col)
local prev
while line > 1 or col > 1 do
local l, c = doc:position_offset(line, col, -1)
local char = doc:get_char(l, c)
if prev and prev ~= char or not is_non_word(char) then
break
end
local c = doc:get_char(doc:position_offset(line, col, -1))
until inword and is_non_word(c) or not inword and c ~= char
return line, col
prev, line, col = char, l, c
end
return translate.start_of_word(doc, line, col)
end
function translate.next_word_boundary(doc, line, col)
local char = doc:get_char(line, col)
local inword = not is_non_word(char)
repeat
local line2, col2 = line, col
line, col = doc:position_offset(line, col, 1)
if line == line2 and col == col2 then
function translate.next_word_end(doc, line, col)
local prev
local end_line, end_col = translate.end_of_doc(doc, line, col)
while line < end_line or col < end_col do
local char = doc:get_char(line, col)
if prev and prev ~= char or not is_non_word(char) then
break
end
local c = doc:get_char(line, col)
until inword and is_non_word(c) or not inword and c ~= char
return line, col
line, col = doc:position_offset(line, col, 1)
prev = char
end
return translate.end_of_word(doc, line, col)
end
@ -86,30 +85,30 @@ function translate.end_of_word(doc, line, col)
end
function translate.previous_start_of_block(doc, line, col)
function translate.previous_block_start(doc, line, col)
while true do
line = line - 1
if line <= 1 then
return 1, 1
end
if doc.lines[line-1]:match("^%s*$")
and not doc.lines[line]:match("^%s*$") then
if doc.lines[line-1]:find("^%s*$")
and not doc.lines[line]:find("^%s*$") then
return line, (doc.lines[line]:find("%S"))
end
end
end
function translate.next_start_of_block(doc, line, col)
function translate.next_block_end(doc, line, col)
while true do
line = line + 1
if line >= #doc.lines then
return #doc.lines, 1
end
if doc.lines[line-1]:match("^%s*$")
and not doc.lines[line]:match("^%s*$") then
return line, (doc.lines[line]:find("%S"))
if doc.lines[line+1]:find("^%s*$")
and not doc.lines[line]:find("^%s*$") then
return line+1, #doc.lines[line+1]
end
line = line + 1
end
end

View File

@ -36,7 +36,7 @@ local function project_scan_thread()
for _, file in ipairs(all) do
if not common.match_pattern(file, config.ignore_files) then
local file = path .. PATHSEP .. file
local file = (path ~= "." and path .. PATHSEP or "") .. file
local info = system.get_file_info(file)
if info and info.size < size_limit then
info.filename = file
@ -62,7 +62,7 @@ local function project_scan_thread()
while true do
-- get project files and replace previous table if the new table is
-- different
local t = get_files(core.project_dir)
local t = get_files(".")
if diff_files(core.project_files, t) then
core.project_files = t
core.redraw = true
@ -82,18 +82,26 @@ function core.init()
CommandView = require "core.commandview"
Doc = require "core.doc"
local project_dir = "."
local files = {}
for i = 2, #ARGS do
local info = system.get_file_info(ARGS[i]) or {}
if info.type == "file" then
table.insert(files, system.absolute_path(ARGS[i]))
elseif info.type == "dir" then
project_dir = ARGS[i]
end
end
system.chdir(project_dir)
core.frame_start = 0
core.clip_rect_stack = {{ 0,0,0,0 }}
core.log_items = {}
core.docs = {}
core.threads = setmetatable({}, { __mode = "k" })
core.project_files = {}
core.project_dir = "."
local info = ARGS[2] and system.get_file_info(ARGS[2])
if info and info.type == "dir" then
core.project_dir = ARGS[2]:gsub("[\\/]$", "")
end
core.redraw = true
core.root_view = RootView()
core.command_view = CommandView()
@ -101,7 +109,6 @@ function core.init()
core.root_view.root_node:split("down", core.command_view, true)
core.root_view.root_node.b:split("down", core.status_view, true)
core.active_view = core.root_view.root_node.a.active_view
core.add_thread(project_scan_thread)
command.add_defaults()
@ -109,12 +116,8 @@ function core.init()
local got_user_error = not core.try(require, "user")
local got_project_error = not core.load_project_module()
for i = 2, #ARGS do
local filename = ARGS[i]
local info = system.get_file_info(filename)
if info and info.type == "file" then
core.root_view:open_doc(core.open_doc(filename))
end
for _, filename in ipairs(files) do
core.root_view:open_doc(core.open_doc(filename))
end
if got_plugin_error or got_user_error or got_project_error then
@ -123,8 +126,28 @@ function core.init()
end
local temp_uid = (system.get_time() * 1000) % 0xffffffff
local temp_file_prefix = string.format(".lite_temp_%08x", temp_uid)
local temp_file_counter = 0
local function delete_temp_files()
for _, filename in ipairs(system.list_dir(EXEDIR)) do
if filename:find(temp_file_prefix, 1, true) == 1 then
os.remove(EXEDIR .. PATHSEP .. filename)
end
end
end
function core.temp_filename(ext)
temp_file_counter = temp_file_counter + 1
return EXEDIR .. PATHSEP .. temp_file_prefix
.. string.format("%06x", temp_file_counter) .. (ext or "")
end
function core.quit(force)
if force then
delete_temp_files()
os.exit()
end
local dirty_count = 0
@ -166,7 +189,7 @@ end
function core.load_project_module()
local filename = core.project_dir .. "/.lite_project.lua"
local filename = ".lite_project.lua"
if system.get_file_info(filename) then
return core.try(function()
local fn, err = loadfile(filename)
@ -190,6 +213,15 @@ function core.reload_module(name)
end
function core.set_active_view(view)
assert(view, "Tried to set active view to nil")
if view ~= core.active_view then
core.last_active_view = core.active_view
core.active_view = view
end
end
function core.add_thread(f, weak_ref)
local key = weak_ref or #core.threads + 1
local fn = function() return core.try(f) end
@ -307,11 +339,17 @@ function core.on_event(type, ...)
elseif type == "mousewheel" then
core.root_view:on_mouse_wheel(...)
elseif type == "filedropped" then
local mx, my = core.root_view.mouse.x, core.root_view.mouse.y
local ok, doc = core.try(core.open_doc, select(1, ...))
if ok then
core.root_view:on_mouse_pressed("left", mx, my, 1)
core.root_view:open_doc(doc)
local filename, mx, my = ...
local info = system.get_file_info(filename)
if info and info.type == "dir" then
system.exec(string.format("%q %q", EXEFILE, filename))
else
local ok, doc = core.try(core.open_doc, filename)
if ok then
local node = core.root_view.root_node:get_child_overlapping_point(mx, my)
node:set_active_view(node.active_view)
core.root_view:open_doc(doc)
end
end
elseif type == "quit" then
core.quit()
@ -348,10 +386,7 @@ function core.step()
-- update
core.root_view.size.x, core.root_view.size.y = width, height
core.root_view:update()
if not core.redraw then
if not system.window_has_focus() then system.wait_event(0.5) end
return
end
if not core.redraw then return false end
core.redraw = false
-- close unreferenced docs
@ -365,10 +400,10 @@ function core.step()
-- update window title
local name = core.active_view:get_name()
if name ~= "---" then
system.set_window_title(name .. " - lite")
else
system.set_window_title("lite")
local title = (name ~= "---") and (name .. " - lite") or "lite"
if title ~= core.window_title then
system.set_window_title(title)
core.window_title = title
end
-- draw
@ -377,6 +412,7 @@ function core.step()
renderer.set_clip_rect(table.unpack(core.clip_rect_stack[1]))
core.root_view:draw()
renderer.end_frame()
return true
end
@ -415,8 +451,11 @@ end)
function core.run()
while true do
core.frame_start = system.get_time()
core.step()
local did_redraw = core.step()
run_threads()
if not did_redraw and not system.window_has_focus() then
system.wait_event(0.25)
end
local elapsed = system.get_time() - core.frame_start
system.sleep(math.max(0, 1 / config.fps - elapsed))
end

View File

@ -84,8 +84,8 @@ end
keymap.add {
["ctrl+shift+p"] = "core:command-finder",
["ctrl+p"] = "core:file-finder",
["ctrl+shift+p"] = "core:find-command",
["ctrl+p"] = "core:find-file",
["ctrl+o"] = "core:open-file",
["ctrl+n"] = "core:new-doc",
["alt+return"] = "core:toggle-fullscreen",
@ -132,12 +132,12 @@ keymap.add {
["shift+tab"] = "doc:unindent",
["backspace"] = "doc:backspace",
["shift+backspace"] = "doc:backspace",
["ctrl+backspace"] = "doc:delete-to-previous-word-boundary",
["ctrl+shift+backspace"] = "doc:delete-to-previous-word-boundary",
["ctrl+backspace"] = "doc:delete-to-previous-word-start",
["ctrl+shift+backspace"] = "doc:delete-to-previous-word-start",
["delete"] = "doc:delete",
["shift+delete"] = "doc:delete",
["ctrl+delete"] = "doc:delete-to-next-word-boundary",
["ctrl+shift+delete"] = "doc:delete-to-next-word-boundary",
["ctrl+delete"] = "doc:delete-to-next-word-end",
["ctrl+shift+delete"] = "doc:delete-to-next-word-end",
["return"] = { "command:submit", "doc:newline" },
["ctrl+return"] = "doc:newline-below",
["ctrl+shift+return"] = "doc:newline-above",
@ -155,10 +155,10 @@ keymap.add {
["right"] = "doc:move-to-next-char",
["up"] = { "command:select-previous", "doc:move-to-previous-line" },
["down"] = { "command:select-next", "doc:move-to-next-line" },
["ctrl+left"] = "doc:move-to-previous-word-boundary",
["ctrl+right"] = "doc:move-to-next-word-boundary",
["ctrl+["] = "doc:move-to-previous-start-of-block",
["ctrl+]"] = "doc:move-to-next-start-of-block",
["ctrl+left"] = "doc:move-to-previous-word-start",
["ctrl+right"] = "doc:move-to-next-word-end",
["ctrl+["] = "doc:move-to-previous-block-start",
["ctrl+]"] = "doc:move-to-next-block-end",
["home"] = "doc:move-to-start-of-line",
["end"] = "doc:move-to-end-of-line",
["ctrl+home"] = "doc:move-to-start-of-doc",
@ -170,10 +170,10 @@ keymap.add {
["shift+right"] = "doc:select-to-next-char",
["shift+up"] = "doc:select-to-previous-line",
["shift+down"] = "doc:select-to-next-line",
["ctrl+shift+left"] = "doc:select-to-previous-word-boundary",
["ctrl+shift+right"] = "doc:select-to-next-word-boundary",
["ctrl+shift+["] = "doc:select-to-previous-start-of-block",
["ctrl+shift+]"] = "doc:select-to-next-start-of-block",
["ctrl+shift+left"] = "doc:select-to-previous-word-start",
["ctrl+shift+right"] = "doc:select-to-next-word-end",
["ctrl+shift+["] = "doc:select-to-previous-block-start",
["ctrl+shift+]"] = "doc:select-to-next-block-end",
["shift+home"] = "doc:select-to-start-of-line",
["shift+end"] = "doc:select-to-end-of-line",
["ctrl+shift+home"] = "doc:select-to-start-of-doc",

View File

@ -9,22 +9,33 @@ local DocView = require "core.docview"
local EmptyView = View:extend()
function EmptyView:draw()
self:draw_background(style.background)
local pos = self.position
local x, y, w, h = pos.x, pos.y, self.size.x, self.size.y
local _, y = common.draw_text(style.big_font, style.dim, "empty", "center", x, y, w, h)
local function draw_text(x, y, color)
local th = style.big_font:get_height()
local dh = th + style.padding.y * 2
x = renderer.draw_text(style.big_font, "lite", x, y + (dh - th) / 2, color)
x = x + style.padding.x
renderer.draw_rect(x, y, math.ceil(1 * SCALE), dh, color)
local lines = {
{ fmt = "%s to run a command", cmd = "core:command-finder" },
{ fmt = "%s to open a file from the project", cmd = "core:file-finder" },
{ fmt = "%s to run a command", cmd = "core:find-command" },
{ fmt = "%s to open a file from the project", cmd = "core:find-file" },
}
local th = style.font:get_height()
th = style.font:get_height()
y = y + (dh - th * 2 - style.padding.y) / 2
local w = 0
for _, line in ipairs(lines) do
local text = string.format(line.fmt, keymap.get_binding(line.cmd))
y = y + style.padding.y
common.draw_text(style.font, style.dim, text, "center", x, y, w, th)
y = y + th
w = math.max(w, renderer.draw_text(style.font, text, x + style.padding.x, y, color))
y = y + th + style.padding.y
end
return w, dh
end
function EmptyView:draw()
self:draw_background(style.background)
local w, h = draw_text(0, 0, { 0, 0, 0, 0 })
local x = self.position.x + math.max(style.padding.x, (self.size.x - w) / 2)
local y = self.position.y + (self.size.y - h) / 2
draw_text(x, y, style.dim)
end
@ -77,17 +88,18 @@ end
local type_map = { up="vsplit", down="vsplit", left="hsplit", right="hsplit" }
function Node:split(dir, view, locked)
assert(self.type == "leaf", "tried to split non-leaf node")
local type = assert(type_map[dir], "invalid direction")
assert(self.type == "leaf", "Tried to split non-leaf node")
local type = assert(type_map[dir], "Invalid direction")
local last_active = core.active_view
local child = Node()
child:consume(self)
self:consume(Node(type))
self.a = child
self.b = Node()
self.b.locked = locked
if view then self.b:add_view(view) end
if not self.b.active_view.focusable then
self.a:set_active_view(self.a.active_view)
if locked then
self.b.locked = locked
core.set_active_view(last_active)
end
if dir == "up" or dir == "left" then
self.a, self.b = self.b, self.a
@ -118,13 +130,15 @@ function Node:close_active_view(root)
p:set_active_view(p.active_view)
end
end
core.last_active_view = nil
end
self.active_view:try_close(do_close)
end
function Node:add_view(view)
assert(self.type == "leaf", "tried to add view to non-leaf node")
assert(self.type == "leaf", "Tried to add view to non-leaf node")
assert(not self.locked, "Tried to add view to locked node")
if self.views[1] and self.views[1]:is(EmptyView) then
table.remove(self.views)
end
@ -134,9 +148,9 @@ end
function Node:set_active_view(view)
assert(self.type == "leaf", "tried to set active view on non-leaf node")
assert(self.type == "leaf", "Tried to set active view on non-leaf node")
self.active_view = view
core.active_view = view
core.set_active_view(view)
end
@ -377,13 +391,16 @@ end
function RootView:get_active_node()
local node = self.root_node:get_node_for_view(core.active_view)
return node or self.root_node.a
return self.root_node:get_node_for_view(core.active_view)
end
function RootView:open_doc(doc)
local node = self:get_active_node()
if node.locked and core.last_active_view then
core.set_active_view(core.last_active_view)
node = self:get_active_node()
end
assert(not node.locked, "Cannot open doc on locked node")
for i, view in ipairs(node.views) do
if view.doc == doc then
@ -413,9 +430,7 @@ function RootView:on_mouse_pressed(button, x, y, clicks)
node:close_active_view(self.root_node)
end
else
if node.active_view.focusable then
core.active_view = node.active_view
end
core.set_active_view(node.active_view)
node.active_view:on_mouse_pressed(button, x, y, clicks)
end
end
@ -431,13 +446,13 @@ end
function RootView:on_mouse_moved(x, y, dx, dy)
if self.dragged_divider then
local div = self.dragged_divider
if div.type == "hsplit" then
div.divider = div.divider + dx / div.size.x
local node = self.dragged_divider
if node.type == "hsplit" then
node.divider = node.divider + dx / node.size.x
else
div.divider = div.divider + dy / div.size.y
node.divider = node.divider + dy / node.size.y
end
div.divider = common.clamp(div.divider, 0.01, 0.99)
node.divider = common.clamp(node.divider, 0.01, 0.99)
return
end

View File

@ -16,13 +16,13 @@ StatusView.separator2 = " | "
function StatusView:new()
StatusView.super.new(self)
self.focusable = false
self.message_timeout = 0
self.message = {}
end
function StatusView:on_mouse_pressed()
core.set_active_view(core.last_active_view)
if system.get_time() < self.message_timeout
and not core.active_view:is(LogView) then
command.perform "core:open-log"

View File

@ -14,7 +14,6 @@ function View:new()
self.scroll = { x = 0, y = 0, to = { x = 0, y = 0 } }
self.cursor = "arrow"
self.scrollable = false
self.focusable = true
end

View File

@ -18,7 +18,7 @@ local function reload_doc(doc)
local sel = { doc:get_selection() }
doc:remove(1, 1, math.huge, math.huge)
doc:insert(1, 1, text:gsub("\n$", ""))
doc:insert(1, 1, text:gsub("\r", ""):gsub("\n$", ""))
doc:set_selection(table.unpack(sel))
update_time(doc)

View File

@ -22,7 +22,6 @@ local TreeView = View:extend()
function TreeView:new()
TreeView.super.new(self)
self.scrollable = true
self.focusable = false
self.visible = true
self.init_size = true
self.cache = {}
@ -35,7 +34,7 @@ function TreeView:get_cached(item)
t = {}
t.filename = item.filename
t.abs_filename = system.absolute_path(item.filename)
t.path, t.name = t.filename:match("^(.*)[\\/](.+)$")
t.name = t.filename:match("[^\\/]+$")
t.depth = get_depth(t.filename)
t.type = item.type
self.cache[t.filename] = t
@ -143,7 +142,6 @@ function TreeView:draw()
local icon_width = style.icon_font:get_width("D")
local spacing = style.font:get_width(" ") * 2
local root_depth = get_depth(core.project_dir) + 1
local doc = core.active_view.doc
local active_filename = doc and system.absolute_path(doc.filename or "")
@ -163,7 +161,7 @@ function TreeView:draw()
end
-- icons
x = x + (item.depth - root_depth) * style.padding.x + style.padding.x
x = x + item.depth * style.padding.x + style.padding.x
if item.type == "dir" then
local icon1 = item.expanded and "-" or "+"
local icon2 = item.expanded and "D" or "d"

View File

@ -5,7 +5,7 @@ style.background = { common.color "#fbfbfb" }
style.background2 = { common.color "#f2f2f2" }
style.background3 = { common.color "#f2f2f2" }
style.text = { common.color "#404040" }
style.caret = { common.color "#181818" }
style.caret = { common.color "#fc1785" }
style.accent = { common.color "#fc1785" }
style.dim = { common.color "#b0b0b0" }
style.divider = { common.color "#e8e8e8" }

View File

@ -2,9 +2,11 @@
#include <stdbool.h>
#include <ctype.h>
#include <dirent.h>
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include "api.h"
#include "rencache.h"
#ifdef _WIN32
#include <windows.h>
#endif
@ -35,6 +37,7 @@ static char* key_name(char *dst, int sym) {
static int f_poll_event(lua_State *L) {
char buf[16];
int mx, my, wx, wy;
SDL_Event e;
top:
@ -54,7 +57,9 @@ top:
lua_pushnumber(L, e.window.data2);
return 3;
} else if (e.window.event == SDL_WINDOWEVENT_EXPOSED) {
SDL_UpdateWindowSurface(window);
rencache_invalidate();
lua_pushstring(L, "exposed");
return 1;
}
/* on some systems, when alt-tabbing to the window SDL will queue up
** several KEYDOWN events for the `tab` key; we flush all keydown
@ -65,10 +70,14 @@ top:
goto top;
case SDL_DROPFILE:
SDL_GetGlobalMouseState(&mx, &my);
SDL_GetWindowPosition(window, &wx, &wy);
lua_pushstring(L, "filedropped");
lua_pushstring(L, e.drop.file);
lua_pushnumber(L, mx - wx);
lua_pushnumber(L, my - wy);
SDL_free(e.drop.file);
return 2;
return 4;
case SDL_KEYDOWN:
lua_pushstring(L, "keypressed");
@ -216,6 +225,14 @@ static int f_show_confirm_dialog(lua_State *L) {
}
static int f_chdir(lua_State *L) {
const char *path = luaL_checkstring(L, 1);
int err = chdir(path);
if (err) { luaL_error(L, "chdir() failed"); }
return 0;
}
static int f_list_dir(lua_State *L) {
const char *path = luaL_checkstring(L, 1);
@ -321,10 +338,10 @@ static int f_sleep(lua_State *L) {
static int f_exec(lua_State *L) {
size_t len;
const char *cmd = luaL_checklstring(L, 1, &len);
char *buf = malloc(len + 16);
char *buf = malloc(len + 32);
if (!buf) { luaL_error(L, "buffer allocation failed"); }
#if _WIN32
sprintf(buf, "cmd /c %s", cmd);
sprintf(buf, "cmd /c \"%s\"", cmd);
WinExec(buf, SW_HIDE);
#else
sprintf(buf, "%s &", cmd);
@ -346,11 +363,11 @@ static int f_fuzzy_match(lua_State *L) {
while (*str == ' ') { str++; }
while (*ptn == ' ') { ptn++; }
if (tolower(*str) == tolower(*ptn)) {
score += run;
score += run * 10 - (*str != *ptn);
run++;
ptn++;
} else {
score--;
score -= 10;
run = 0;
}
str++;
@ -370,6 +387,7 @@ static const luaL_Reg lib[] = {
{ "set_window_mode", f_set_window_mode },
{ "window_has_focus", f_window_has_focus },
{ "show_confirm_dialog", f_show_confirm_dialog },
{ "chdir", f_chdir },
{ "list_dir", f_list_dir },
{ "absolute_path", f_absolute_path },
{ "get_file_info", f_get_file_info },

View File

@ -20,8 +20,6 @@ static double get_scale(void) {
SDL_GetDisplayDPI(0, NULL, &dpi, NULL);
#if _WIN32
return dpi / 96.0;
#elif __APPLE__
return 1.0; /* dpi / 72.0; */
#else
return 1.0;
#endif
@ -100,7 +98,7 @@ int main(int argc, char **argv) {
}
lua_setglobal(L, "ARGS");
lua_pushstring(L, "1.04");
lua_pushstring(L, "1.06");
lua_setglobal(L, "VERSION");
lua_pushstring(L, SDL_GetPlatform());
@ -120,7 +118,7 @@ int main(int argc, char **argv) {
"xpcall(function()\n"
" SCALE = tonumber(os.getenv(\"LITE_SCALE\")) or SCALE\n"
" PATHSEP = package.config:sub(1, 1)\n"
" EXEDIR = EXEFILE:match(\"^(.-)[^/\\\\]*$\")"
" EXEDIR = EXEFILE:match(\"^(.+)[/\\\\].*$\")\n"
" package.path = EXEDIR .. '/data/?.lua;' .. package.path\n"
" package.path = EXEDIR .. '/data/?/init.lua;' .. package.path\n"
" core = require('core')\n"

View File

@ -150,6 +150,11 @@ int rencache_draw_text(RenFont *font, const char *text, int x, int y, RenColor c
}
void rencache_invalidate(void) {
memset(cells_prev, 0xff, sizeof(cells_buf1));
}
void rencache_begin_frame(void) {
/* reset all cells if the screen width/height has changed */
int w, h;
@ -157,7 +162,7 @@ void rencache_begin_frame(void) {
if (screen_rect.width != w || h != screen_rect.height) {
screen_rect.width = w;
screen_rect.height = h;
memset(cells_prev, 0xff, sizeof(cells_buf1));
rencache_invalidate();
}
}

View File

@ -9,6 +9,7 @@ void rencache_free_font(RenFont *font);
void rencache_set_clip_rect(RenRect rect);
void rencache_draw_rect(RenRect rect, RenColor color);
int rencache_draw_text(RenFont *font, const char *text, int x, int y, RenColor color);
void rencache_invalidate(void);
void rencache_begin_frame(void);
void rencache_end_frame(void);