diff --git a/.gitattributes b/.gitattributes index bd2cfac4..8cb51a8f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,7 @@ +# Set the default behavior, in case people don't have core.autocrlf set. +# See https://help.github.com/en/articles/dealing-with-line-endings +* text=auto + winlib/* linguist-vendored src/lib/* linguist-vendored -icon.inl linguist-vendored +resources/icons/icon.inl linguist-vendored diff --git a/.gitignore b/.gitignore index 96be3276..42b4ba06 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,7 @@ build* subprojects/lua subprojects/libagg subprojects/reproc -lite +lite-xl error.txt .ccls-cache compile_commands.json diff --git a/build-packages.sh b/build-packages.sh index 76b0ebf5..3701ac53 100755 --- a/build-packages.sh +++ b/build-packages.sh @@ -44,7 +44,7 @@ lite_build_pgo () { meson setup --buildtype=release -Db_pgo=generate "$build" || exit 1 ninja -C "$build" || exit 1 copy_directory_from_repo data "$build/src" - "$build/src/lite" + "$build/src/lite-xl" meson configure -Db_pgo=use "$build" ninja -C "$build" || exit 1 } @@ -74,8 +74,8 @@ lite_build_package_windows () { for module_name in plugins colors; do cp -r "$build/third/data/$module_name" "$datadir" done - cp "$build/src/lite.exe" "$bindir" - strip --strip-all "$bindir/lite.exe" + cp "$build/src/lite-xl.exe" "$bindir" + strip --strip-all "$bindir/lite-xl.exe" pushd ".package-build" local package_name="lite-xl-$os-$arch$portable.zip" zip "$package_name" -r "lite-xl" @@ -84,7 +84,7 @@ lite_build_package_windows () { rm -fr ".package-build" echo "created package $package_name" } - + lite_build_package_macos () { local build="$1" local arch="$2" @@ -100,9 +100,9 @@ lite_build_package_macos () { for module_name in plugins colors; do cp -r "$build/third/data/$module_name" "$datadir" done - cp dev-utils/icon.icns "$appdir/Contents/Resources/icon.icns" - cp dev-utils/Info.plist "$appdir/Contents/Info.plist" - cp "$build/src/lite" "$bindir/lite-xl" + cp resources/icons/icon.icns "$appdir/Contents/Resources/icon.icns" + cp resources/macos/Info.plist "$appdir/Contents/Info.plist" + cp "$build/src/lite-xl" "$bindir/lite-xl" strip "$bindir/lite-xl" pushd ".package-build" local package_name="lite-xl-$os-$arch.zip" @@ -138,12 +138,12 @@ lite_build_package_linux () { for module_name in plugins colors; do cp -r "$build/third/data/$module_name" "$datadir" done - cp "$build/src/lite" "$bindir" - strip "$bindir/lite" + cp "$build/src/lite-xl" "$bindir" + strip "$bindir/lite-xl" if [ -z "$portable" ]; then mkdir -p "$pdir/share/applications" "$pdir/share/icons/hicolor/scalable/apps" - cp "dev-utils/lite-xl.desktop" "$pdir/share/applications" - cp "dev-utils/lite.svg" "$pdir/share/icons/hicolor/scalable/apps/lite-xl.svg" + cp "resources/linux/lite-xl.desktop" "$pdir/share/applications" + cp "resources/icons/lite-xl.svg" "$pdir/share/icons/hicolor/scalable/apps/lite-xl.svg" fi pushd ".package-build" local package_name="lite-xl-$os-$arch$portable.tar.gz" diff --git a/build.sh b/build.sh index eb1d420a..b49dc1bf 100755 --- a/build.sh +++ b/build.sh @@ -12,7 +12,7 @@ if [[ $* == *windows* ]]; then echo "cross compiling for windows is not yet supported" exit 1 else - outfile="lite" + outfile="lite-xl" compiler="gcc" cxxcompiler="g++" fi @@ -20,7 +20,7 @@ fi lib/font_renderer/build.sh || exit 1 libs=libfontrenderer.a -echo "compiling lite..." +echo "compiling lite-xl..." for f in `find src -name "*.c"`; do $compiler -c $cflags $f -o "${f//\//_}.o" if [[ $? -ne 0 ]]; then diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index c3cb0d78..5ddcd507 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -129,6 +129,7 @@ local function split_cursor(direction) end end for i,v in ipairs(new_cursors) do doc():add_selection(v[1], v[2]) end + core.blink_reset() end local commands = { diff --git a/data/core/common.lua b/data/core/common.lua index dc508918..4b16ed1f 100644 --- a/data/core/common.lua +++ b/data/core/common.lua @@ -340,4 +340,51 @@ function common.mkdirp(path) return true end +function common.rm(path, recursively) + local stat = system.get_file_info(path) + if not stat or (stat.type ~= "file" and stat.type ~= "dir") then + return false, "invalid path given", path + end + + if stat.type == "file" then + local removed, error = os.remove(path) + if not removed then + return false, error, path + end + else + local contents = system.list_dir(path) + if #contents > 0 and not recursively then + return false, "directory is not empty", path + end + + for _, item in pairs(contents) do + local item_path = path .. PATHSEP .. item + local item_stat = system.get_file_info(item_path) + + if not item_stat then + return false, "invalid file encountered", item_path + end + + if item_stat.type == "dir" then + local deleted, error, ipath = common.rm(item_path, recursively) + if not deleted then + return false, error, ipath + end + elseif item_stat.type == "file" then + local removed, error = os.remove(item_path) + if not removed then + return false, error, item_path + end + end + end + + local removed, error = system.rmdir(path) + if not removed then + return false, error, path + end + end + + return true +end + return common diff --git a/data/core/keymap-macos.lua b/data/core/keymap-macos.lua index 3db4d4f7..327a1cc5 100644 --- a/data/core/keymap-macos.lua +++ b/data/core/keymap-macos.lua @@ -17,7 +17,7 @@ local function keymap_macos(keymap) ["cmd+ctrl+i"] = "root:switch-to-up", ["cmd+ctrl+k"] = "root:switch-to-down", - ["ctrl+w"] = "root:close", + ["cmd+w"] = "root:close", ["ctrl+tab"] = "root:switch-to-next-tab", ["ctrl+shift+tab"] = "root:switch-to-previous-tab", ["cmd+pageup"] = "root:move-tab-left", diff --git a/data/core/start.lua b/data/core/start.lua index 3ef806cc..6090df4e 100644 --- a/data/core/start.lua +++ b/data/core/start.lua @@ -12,7 +12,8 @@ else local prefix = EXEDIR:match("^(.+)[/\\]bin$") DATADIR = prefix and (prefix .. '/share/lite-xl') or (EXEDIR .. '/data') end -USERDIR = os.getenv("XDG_CONFIG_HOME") or (HOME and (HOME .. '/.config/lite-xl') or (EXEDIR .. '/user')) +USERDIR = (os.getenv("XDG_CONFIG_HOME") and os.getenv("XDG_CONFIG_HOME") .. "/lite-xl") + or (HOME and (HOME .. '/.config/lite-xl') or (EXEDIR .. '/user')) package.path = DATADIR .. '/?.lua;' .. package.path package.path = DATADIR .. '/?/init.lua;' .. package.path diff --git a/data/core/style.lua b/data/core/style.lua index 60df7c73..7cf16eb1 100644 --- a/data/core/style.lua +++ b/data/core/style.lua @@ -22,9 +22,9 @@ style.tab_width = common.round(170 * SCALE) -- On High DPI monitor or non RGB monitor you may consider using antialiasing grayscale instead. -- The antialiasing grayscale with full hinting is interesting for crisp font rendering. style.font = renderer.font.load(DATADIR .. "/fonts/FiraSans-Regular.ttf", 13 * SCALE) -style.big_font = renderer.font.load(DATADIR .. "/fonts/FiraSans-Regular.ttf", 40 * SCALE) +style.big_font = style.font:copy(40 * SCALE) style.icon_font = renderer.font.load(DATADIR .. "/fonts/icons.ttf", 14 * SCALE, {antialiasing="grayscale", hinting="full"}) -style.icon_big_font = renderer.font.load(DATADIR .. "/fonts/icons.ttf", 20 * SCALE, {antialiasing="grayscale", hinting="full"}) +style.icon_big_font = style.icon_font:copy(20 * SCALE) style.code_font = renderer.font.load(DATADIR .. "/fonts/JetBrainsMono-Regular.ttf", 13 * SCALE) style.background = { common.color "#2e2e32" } diff --git a/meson.build b/meson.build index c1108ee7..1f1ff0d2 100644 --- a/meson.build +++ b/meson.build @@ -1,4 +1,4 @@ -project('lite', 'c', 'cpp', default_options : ['c_std=gnu11', 'cpp_std=c++03']) +project('lite-xl', 'c', 'cpp', default_options : ['c_std=gnu11', 'cpp_std=c++03']) if host_machine.system() == 'darwin' add_languages('objc') @@ -55,7 +55,7 @@ endif lite_rc = [] if host_machine.system() == 'windows' windows = import('windows') - lite_rc += windows.compile_resources('res.rc') + lite_rc += windows.compile_resources('resources/icons/icon.rc') endif # On macos we need to use the SDL renderer to support retina displays diff --git a/dev-utils/icon.icns b/resources/icons/icon.icns similarity index 100% rename from dev-utils/icon.icns rename to resources/icons/icon.icns diff --git a/icon.ico b/resources/icons/icon.ico similarity index 100% rename from icon.ico rename to resources/icons/icon.ico diff --git a/icon.inl b/resources/icons/icon.inl similarity index 100% rename from icon.inl rename to resources/icons/icon.inl diff --git a/res.rc b/resources/icons/icon.rc similarity index 100% rename from res.rc rename to resources/icons/icon.rc diff --git a/dev-utils/lite.svg b/resources/icons/lite-xl.svg similarity index 100% rename from dev-utils/lite.svg rename to resources/icons/lite-xl.svg diff --git a/dev-utils/lite-xl.desktop b/resources/linux/lite-xl.desktop similarity index 92% rename from dev-utils/lite-xl.desktop rename to resources/linux/lite-xl.desktop index dbcb779a..f2fa9610 100644 --- a/dev-utils/lite-xl.desktop +++ b/resources/linux/lite-xl.desktop @@ -2,10 +2,9 @@ Type=Application Name=Lite XL Comment=A lightweight text editor written in Lua -Exec=lite %F +Exec=lite-xl %F Icon=lite-xl Terminal=false StartupNotify=false Categories=Utility;TextEditor;Development; MimeType=text/plain; - diff --git a/dev-utils/Info.plist b/resources/macos/Info.plist similarity index 100% rename from dev-utils/Info.plist rename to resources/macos/Info.plist diff --git a/dev-utils/macos-retina-display.md b/resources/macos/macos-retina-display.md similarity index 100% rename from dev-utils/macos-retina-display.md rename to resources/macos/macos-retina-display.md diff --git a/dev-utils/fontello-config.json b/scripts/fontello-config.json similarity index 100% rename from dev-utils/fontello-config.json rename to scripts/fontello-config.json diff --git a/dev-utils/repackage.sh b/scripts/repackage.sh similarity index 100% rename from dev-utils/repackage.sh rename to scripts/repackage.sh diff --git a/dev-utils/run-local b/scripts/run-local similarity index 100% rename from dev-utils/run-local rename to scripts/run-local diff --git a/dev-utils/run-plugin b/scripts/run-plugin similarity index 100% rename from dev-utils/run-plugin rename to scripts/run-plugin diff --git a/src/api/renderer_font.c b/src/api/renderer_font.c index f510da70..7c6587ea 100644 --- a/src/api/renderer_font.c +++ b/src/api/renderer_font.c @@ -55,6 +55,21 @@ static int f_load(lua_State *L) { } +static int f_copy(lua_State *L) { + FontDesc *self = luaL_checkudata(L, 1, API_TYPE_FONT); + float size; + if (lua_gettop(L) >= 2) { + size = luaL_checknumber(L, 2); + } else { + size = self->size; + } + FontDesc *new_font_desc = lua_newuserdata(L, font_desc_alloc_size(self->filename)); + font_desc_init(new_font_desc, self->filename, size, self->options); + luaL_setmetatable(L, API_TYPE_FONT); + return 1; +} + + static int f_set_tab_size(lua_State *L) { FontDesc *self = luaL_checkudata(L, 1, API_TYPE_FONT); int n = luaL_checknumber(L, 2); @@ -123,6 +138,7 @@ static int f_set_size(lua_State *L) { static const luaL_Reg lib[] = { { "__gc", f_gc }, { "load", f_load }, + { "copy", f_copy }, { "set_tab_size", f_set_tab_size }, { "get_width", f_get_width }, { "get_width_subpixel", f_get_width_subpixel }, diff --git a/src/api/system.c b/src/api/system.c index 4b98509f..2f1bf763 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -10,6 +10,7 @@ #ifdef _WIN32 #include #include + #include #endif extern SDL_Window *window; @@ -384,6 +385,52 @@ static int f_show_fatal_error(lua_State *L) { } +// removes an empty directory +static int f_rmdir(lua_State *L) { + const char *path = luaL_checkstring(L, 1); + +#ifdef _WIN32 + int deleted = RemoveDirectoryA(path); + if(deleted > 0) { + lua_pushboolean(L, 1); + } else { + DWORD error_code = GetLastError(); + LPVOID message; + + FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + error_code, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR) &message, + 0, + NULL + ); + + lua_pushboolean(L, 0); + lua_pushlstring(L, (LPCTSTR)message, lstrlen((LPCTSTR)message)); + LocalFree(message); + + return 2; + } +#else + int deleted = remove(path); + if(deleted < 0) { + lua_pushboolean(L, 0); + lua_pushstring(L, strerror(errno)); + + return 2; + } else { + lua_pushboolean(L, 1); + } +#endif + + return 1; +} + + static int f_chdir(lua_State *L) { const char *path = luaL_checkstring(L, 1); int err = chdir(path); @@ -604,6 +651,7 @@ static const luaL_Reg lib[] = { { "set_window_size", f_set_window_size }, { "window_has_focus", f_window_has_focus }, { "show_fatal_error", f_show_fatal_error }, + { "rmdir", f_rmdir }, { "chdir", f_chdir }, { "mkdir", f_mkdir }, { "list_dir", f_list_dir }, diff --git a/src/main.c b/src/main.c index 3aacf828..53e8e364 100644 --- a/src/main.c +++ b/src/main.c @@ -79,7 +79,7 @@ static void get_exe_filename(char *buf, int sz) { static void init_window_icon(void) { #ifndef _WIN32 - #include "../icon.inl" + #include "../resources/icons/icon.inl" (void) icon_rgba_len; /* unused */ SDL_Surface *surf = SDL_CreateRGBSurfaceFrom( icon_rgba, 64, 64, diff --git a/src/meson.build b/src/meson.build index 9516c94d..03cc826f 100644 --- a/src/meson.build +++ b/src/meson.build @@ -17,7 +17,7 @@ if host_machine.system() == 'darwin' lite_sources += 'bundle_open.m' endif -executable('lite', +executable('lite-xl', lite_sources + lite_rc, include_directories: [lite_include, font_renderer_include], dependencies: lite_deps,