diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index feddb0c..6c17082 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,7 +1,7 @@ name: CI on: { push: { branches: [master] } } -env: - LPM_PLUGINS: https://raw.githubusercontent.com/adamharrison/lite-xl-maintenance/latest/lpm-plugins/gh.lua +permissions: write-all + jobs: version: runs-on: ubuntu-latest @@ -9,28 +9,44 @@ jobs: version: ${{ steps.setup_release.outputs.version }} steps: - name: Checkout Code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: { fetch-depth: 0 } - name: Setup Release id: setup_release env: { GITHUB_TOKEN: "${{ github.token }}" } run: | - wget https://github.com/lite-xl/lite-xl-plugin-manager/releases/download/latest/lpm.x86_64-linux -O lpm-latest && chmod +x lpm-latest - echo "version=`./lpm-latest gh version`" >> $GITHUB_OUTPUT + export VERSION=`git describe --tags --match "v*" | tail -c +2` + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "Building terminal version $VERSION." + perl -pe 'last if $_ =~ m/^\s*#/ && $_ !~ m/#\s*$ENV{VERSION}/' < CHANGELOG.md | tail -n +2 > NOTES.md + if [[ `git tag --points-at HEAD | head -c 1` == "v" ]]; then + gh release delete -y v$VERSION || true; gh release create -t v$VERSION v$VERSION + gh release delete -y latest || true; gh release create -t latest latest + fi + gh release delete -y continuous || true; gh release create -p -t 'Continuous Release' continuous -F NOTES.md + build_linux: needs: [version] permissions: write-all - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 defaults: { run: { shell: bash } } steps: - name: Checkout Code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: { fetch-depth: 0, submodules: true } + - name: Install Cross Compiler + run: | + sudo apt-get install -y gcc-aarch64-linux-gnu - name: Build Linux - run: docker run -v .:/terminal ubuntu:14.04 bash -c 'cd /terminal && apt-get update && apt-get install -y gcc-4.8 gcc-4.8-aarch64-linux-gnu && BIN=libterminal.aarch64-linux.so CC=aarch64-linux-gnu-gcc-4.8 ./build.sh -O3 -std=c99 -D_BSD_SOURCE -D_POSIX_SOURCE -DLIBTERMINAL_VERSION=\"${{ needs.version.outputs.version }}-aarch64-linux\" && CC=gcc-4.8 BIN=libterminal.x86_64-linux.so ./build.sh -std=c99 -D_BSD_SOURCE -D_POSIX_SOURCE -O3 -DLIBTERMINAL_VERSION=\"${{ needs.version.outputs.version }}-x86_64-linux\" ' - - name: Upload Artifacts - uses: actions/upload-artifact@v3 - with: { name: "Linux", path: "*.so" } + run: | + BIN=libterminal.x86_64-linux.so ./build.sh -O3 -DLIBTERMINAL_VERSION='"'${{ needs.version.outputs.version }}-x86_64-linux'"' + BIN=libterminal.aarch64-linux.so CC=aarch64-linux-gnu-gcc ./build.sh -O3 -DLIBTERMINAL_VERSION='"'${{ needs.version.outputs.version }}-aarch64-linux'"' + - name: Upload x86_64 Artifacts + uses: actions/upload-artifact@v4 + with: { name: "Linux_x86_64", path: "libterminal.x86_64-linux.so" } + - name: Upload aarch64 Artifacts + uses: actions/upload-artifact@v4 + with: { name: "Linux_aarch64", path: "libterminal.aarch64-linux.so" } build_windows: needs: [version] @@ -39,33 +55,36 @@ jobs: defaults: { run: { shell: bash } } steps: - name: Checkout Code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: { fetch-depth: 0, submodules: true } - name: Build Windows env: { GITHUB_TOKEN: "${{ github.token }}" } run: sudo apt-get install mingw-w64 && BIN=libterminal.x86_64-windows.dll CC=x86_64-w64-mingw32-gcc ./build.sh -O3 -DLIBTERMINAL_VERSION='"'${{ needs.version.outputs.version }}-x86_64-windows'"' - name: Upload Artifacts - uses: actions/upload-artifact@v3 - with: { name: "Windows", path: "*.dll" } + uses: actions/upload-artifact@v4 + with: { name: "Windows", path: "libterminal.x86_64-windows.dll" } build_macos: needs: [version] - runs-on: macos-latest + runs-on: macos-13 env: CC: clang steps: - name: Checkout Code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: { fetch-depth: 0, submodules: true } - name: Build MacOS env: { GITHUB_TOKEN: "${{ github.token }}" } run: | ./build.sh clean - BIN=libterminal.x86_64-darwin.so ./build.sh -O3 -DLIBTERMINAL_VERSION='"'${{ needs.version.outputs.version }}-x86_64-darwin'"' - BIN=libterminal.aarch64-darwin.so CC=clang CFLAGS="-arch arm64" ./build.sh -O3 -DLIBTERMINAL_VERSION='"'${{ needs.version.outputs.version }}-x86_64-darwin'"' - - name: Upload Artifacts - uses: actions/upload-artifact@v3 - with: { name: "MacOS", path: "*.so" } + BIN=libterminal.x86_64-darwin.so MACOSX_DEPLOYMENT_TARGET=10.11 ./build.sh -O3 -DLIBTERMINAL_VERSION='"'${{ needs.version.outputs.version }}-x86_64-darwin'"' + BIN=libterminal.aarch64-darwin.so MACOSX_DEPLOYMENT_TARGET=11.0 CC=clang CFLAGS="-arch arm64" ./build.sh -O3 -DLIBTERMINAL_VERSION='"'${{ needs.version.outputs.version }}-x86_64-darwin'"' + - name: Upload x86_64 Artifacts + uses: actions/upload-artifact@v4 + with: { name: "MacOS_x86_64", path: "libterminal.x86_64-darwin.so" } + - name: Upload aarch64 Artifacts + uses: actions/upload-artifact@v4 + with: { name: "MacOS_aarch64", path: "libterminal.aarch64-darwin.so" } finalize: @@ -74,16 +93,23 @@ jobs: environment: Release steps: - name: Checkout Code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: { fetch-depth: 0 } - name: Download Artifacts - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: { path: "." } - name: Perform Release env: GITHUB_TOKEN: "${{ github.token }}" - LPM_DISCORD_WEBHOOK: "${{ secrets.DISCORD_WEBHOOK }}" run: | - wget https://github.com/lite-xl/lite-xl-plugin-manager/releases/download/latest/lpm.x86_64-linux -O lpm-latest && chmod +x lpm-latest - ./lpm-latest gh release Linux/*.so MacOS/*.so Windows/*.dll - + if [[ `git tag --points-at HEAD | head -c 1` == "v" ]]; then + gh release upload v${{ needs.version.outputs.version }} Linux_x86_64/*.so Linux_aarch64/*.so MacOS_x86_64/*.so MacOS_aarch64/*.so Windows/*.dll + gh release upload latest Linux_x86_64/*.so Linux_aarch64/*.so MacOS_x86_64/*.so MacOS_aarch64/*.so Windows/*.dll + git branch -f latest HEAD + git tag -f latest + git push -f origin refs/heads/latest + git push -f origin refs/tags/latest + fi + gh release upload continuous Linux_x86_64/*.so Linux_aarch64/*.so MacOS_x86_64/*.so MacOS_aarch64/*.so Windows/*.dll + git tag -f continuous + git push -f origin refs/tags/continuous diff --git a/LICENSE b/LICENSE index 162c6f1..d3b24e2 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,5 @@ Copyright (c) 2023 lite-xl Team +Copyright (c) 2023 Pragtical Team Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in @@ -17,4 +18,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - diff --git a/README.md b/README.md index 1bb5f9b..0a86a5c 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ -# lite-xl-terminal +# pragtical-terminal -`lite-xl-terminal` is a (mostly) fully-featured terminal emulator designed to -slot into lite-xl as a plugin for windows (Windows 10+ only), mac and linux. +`pragtical-terminal` is a (mostly) fully-featured terminal emulator designed to +slot into pragtical as a plugin for windows (Windows 10+ only), mac and linux. -![image](https://github.com/adamharrison/lite-xl-terminal/assets/1034518/eb8a72a0-ff61-4b95-b009-364ac2725f70) +![image](screenshots/preview.png) ## Description @@ -51,35 +51,35 @@ More shells should work, but are not tested outright. ## Installation -The easiest way to install `lite-xl-terminal` is to use -[`lpm`](https://github.com/lite-xl/lite-xl-plugin-manager), and then run the +The easiest way to install `pragtical-terminal` is to use +[`ppm`](https://github.com/pragtical/plugin-manager), and then run the following command: ``` -lpm install terminal +ppm install terminal ``` -If you want to simply try it out, you can use `lpm`'s `run` command: +If you want to simply try it out, you can use `ppm`'s `run` command: ``` -lpm run terminal +ppm run terminal ``` If you want to grab it directly, and build it from the repo, on Linux, Mac or MSYS on Windows you can do: ``` -git clone --depth=1 https://github.com/adamharrison/lite-xl-terminal.git \ - --recurse-submodules --shallow-submodules && cd lite-xl-terminal && \ - ./build.sh && cp -R plugins/terminal ~/.config/lite-xl/plugins && \ - cp libterminal.so ~/.config/lite-xl/plugins/terminal +git clone --depth=1 https://github.com/pragtical/terminal.git \ + --recurse-submodules --shallow-submodules && cd terminal && \ + ./build.sh && cp -R plugins/terminal ~/.config/pragtical/plugins && \ + cp libterminal.so ~/.config/pragtical/plugins/terminal ``` If you want to install on Windows, but don't have MSYS, you can download -the files directly from our [release](https://github.com/adamharrison/lite-xl-terminal/releases/tag/latest) +the files directly from our [release](https://github.com/pragtical/terminal/releases/tag/latest) page, download `libterminal.x86_64-windows.dll`, as well as the Source Code, and place both the dll, and the `plugins/terminal/init.lua` from the source -code archive into your lite-xl plugins directory as `plugins/terminal/init.lua` +code archive into your pragtical plugins directory as `plugins/terminal/init.lua` and `plugins/terminal/libterminal.x86_64-windows.dll`. ### Stanalone @@ -87,7 +87,7 @@ and `plugins/terminal/libterminal.x86_64-windows.dll`. If you want to use terminal as a standalone terminal, here's a handy script you can use: ``` -LITE_SCALE=1 lpm run terminal --config 'config.plugins.treeview=false config.plugins.workspace=false config.always_show_tabs=false local _,_,x,y = system.get_window_size() system.set_window_size(800, 500, x, y) local TerminalView = require "plugins.terminal".class local old_close = TerminalView.close function TerminalView:close() old_close(self) os.exit(0) end core.add_thread(function() command.perform("terminal:open-tab") local node = core.root_view.root_node:get_node_for_view(core.status_view) node:close_view(core.root_view.root_node, core.status_view) end)' +PRAGTICAL_SCALE=1 ppm run terminal --config 'config.plugins.treeview=false config.plugins.workspace=false config.always_show_tabs=false local _,_,x,y = system.get_window_size() system.set_window_size(800, 500, x, y) local TerminalView = require "plugins.terminal".class local old_close = TerminalView.close function TerminalView:close() old_close(self) os.exit(0) end core.add_thread(function() command.perform("terminal:open-tab") local node = core.root_view.root_node:get_node_for_view(core.status_view) node:close_view(core.root_view.root_node, core.status_view) end)' ``` ## Status @@ -111,4 +111,3 @@ dependencies other than the native OS libraries for each OS. ``` CC=x86_64-w64-mingw32-gcc BIN=libterminal.dll ./build.sh -g ``` - diff --git a/manifest.json b/manifest.json index e6876e3..73fbc42 100644 --- a/manifest.json +++ b/manifest.json @@ -1,37 +1,37 @@ { - "addons": [ + "addons" : [ { - "description": "An integrated terminal for lite-xl. *([screenshot](https://github.com/adamharrison/lite-xl-terminal/assets/1034518/eb8a72a0-ff61-4b95-b009-364ac2725f70))*", - "files": [ + "id" : "terminal", + "description" : "An integrated terminal for pragtical.", + "version" : "1.06", + "path" : "plugins/terminal", + "files" : [ { - "arch": "x86_64-linux", - "checksum": "2d5a28f64299d930c5d77afeb92a44f8923e0ae1091e35ffa1b8c5338261a32f", - "url": "https://github.com/adamharrison/lite-xl-terminal/releases/download/v1.06/libterminal.x86_64-linux.so" + "url" : "https://github.com/pragtical/terminal/releases/download/latest/libterminal.x86_64-linux.so", + "arch" : "x86_64-linux", + "checksum" : "SKIP" }, { - "arch": "aarch64-linux", - "checksum": "27e9af46c4f675327d3f2782beeade26bce2dccdf156416cd430ea9884683847", - "url": "https://github.com/adamharrison/lite-xl-terminal/releases/download/v1.06/libterminal.aarch64-linux.so" + "arch" : "aarch64-linux", + "url" : "https://github.com/pragtical/terminal/releases/download/latest/libterminal.aarch64-linux.so", + "checksum" : "SKIP" }, { - "arch": "x86_64-darwin", - "checksum": "408e24b2d5d66e64f093cff329840b05616e3f118d6fe4bc3f6a492ba5cd4715", - "url": "https://github.com/adamharrison/lite-xl-terminal/releases/download/v1.06/libterminal.x86_64-darwin.so" + "url" : "https://github.com/pragtical/terminal/releases/download/latest/libterminal.x86_64-darwin.so", + "arch" : "x86_64-darwin", + "checksum" : "SKIP" }, { - "arch": "aarch64-darwin", - "checksum": "fc2b9addf5d39feb94c7d981e84eb5c5a871c46aa961b47fd6c52d7afa5078d3", - "url": "https://github.com/adamharrison/lite-xl-terminal/releases/download/v1.06/libterminal.aarch64-darwin.so" + "url" : "https://github.com/pragtical/terminal/releases/download/latest/libterminal.aarch64-darwin.so", + "arch" : "aarch64-darwin", + "checksum" : "SKIP" }, { - "arch": "x86_64-windows", - "checksum": "cbcc0687199f3bed113d6d416545b6cbe9b2a8f4541e81b7f6d0c11bd56b20cb", - "url": "https://github.com/adamharrison/lite-xl-terminal/releases/download/v1.06/libterminal.x86_64-windows.dll" + "url" : "https://github.com/pragtical/terminal/releases/download/latest/libterminal.x86_64-windows.dll", + "arch" : "x86_64-windows", + "checksum" : "SKIP" } - ], - "id": "terminal", - "path": "plugins/terminal", - "version": "1.06" + ] } ] } diff --git a/plugins/terminal/init.lua b/plugins/terminal/init.lua index 0eaf0cc..32589fc 100644 --- a/plugins/terminal/init.lua +++ b/plugins/terminal/init.lua @@ -117,52 +117,80 @@ default_config.config_spec = set_config_default_values { { label = "Font", description = "The font to use for the terminal.", - path = "font", type = "FONT" + path = "font", type = "FONT", + default = { + fonts = { + { + name = "JetBrains Mono Regular", + path = DATADIR .. "/fonts/JetBrainsMono-Regular.ttf" + } + }, + options = { + size = 15, + antialiasing = "subpixel", + hinting = "slight" + } + }, + on_apply = function() + if not config.plugins.terminal.bold_font then + config.plugins.terminal.bold_font = config.plugins.terminal.font:copy( + config.plugins.terminal.font:get_size(), { smoothing = true } + ) + end + end }, { label = "Background Color", description = "The color of the terminal background (when not overridden by the shell).", - path = "background", type = "COLOR" + path = "background", type = "COLOR", + default = style.background or { common.color "#000000" } }, { label = "Text Color", description = "The color of the text (when not overridden by the shell).", - path = "text", type = "COLOR" + path = "text", type = "COLOR", + default = style.syntax and style.syntax.normal or { common.color "#FFFFFF" } }, { label = "Show Bold Text In Bright Colors", description = "Display emboldened text with brighter colors.", - path = "bold_text_in_bright_colors", type = "TOGGLE" + path = "bold_text_in_bright_colors", type = "TOGGLE", + default = true }, { label = "Minimum Contrast Ratio", description = "Minimum contrast between the text and background color (set to 0 to disable auto color adjustment).", - path = "minimum_contrast_ratio", type = "NUMBER" + path = "minimum_contrast_ratio", type = "NUMBER", + default = 3 }, { label = "Terminal Drawer Height", description = "Height of the terminal drawer (in pixels).", - path = "drawer_height", type = "NUMBER" + path = "drawer_height", type = "NUMBER", + default = 300 }, { label = "Inversion Key", - description = "The key to press in combination with CTRL to send the shortcut to Lite XL instead of the terminal.", + description = "The key to press in combination with CTRL to send the shortcut to Pragtical instead of the terminal.", path = "inversion_key", type = "STRING", + default = "shift" }, { label = "Omit Shortcuts", - description = "A Lua pattern of shortcuts to pass to Lite XL instead of the terminal.", + description = "A Lua pattern of shortcuts to pass to Pragtical instead of the terminal.", path = "omit_escapes", type = "STRING" }, { label = "Scrolling speed", description = "The amount of time to scroll a line when selecting text offscreen.", - path = "scrolling_speed", type = "NUMBER" + path = "scrolling_speed", type = "NUMBER", + default = 0.01 }, { label = "Shell", description = "Absolute path to the shell for the terminal.", - path = "shell", type = "STRING" + path = "shell", type = "FILE", exists=true, + default = default_shell }, { label = "Shell Arguments", @@ -172,17 +200,19 @@ default_config.config_spec = set_config_default_values { { label = "Terminal Type", description = "The type to terminal to appear as (sets the $TERM environment variable).", - path = "term", type = "STRING" + path = "term", type = "STRING", + default = "xterm-256color" }, { label = "Scrollback Buffer Size", description = "Number of lines to store for scrolling in the terminal.", - path = "scrollback_limit", type = "NUMBER" + path = "scrollback_limit", type = "NUMBER", + default = 10000 }, { label = "Change Other Options", description = "For other options such as the color palette, you can change them in the user module.", - icon = "PLATFORM", type = "BUTTON", on_click = "core:open-user-module", path = "", + icon = "P", type = "BUTTON", on_click = "core:open-user-module", path = "" } } config.plugins.terminal = common.merge(default_config, config.plugins.terminal) @@ -198,9 +228,9 @@ local function relativeLuminance(color) local rs = color[1] / 255 local gs = color[2] / 255 local bs = color[3] / 255 - local rr = rs <= 0.03928 and rs / 12.92 or (((rs + 0.055) / 1.055) ^ 2.4) - local rg = gs <= 0.03928 and gs / 12.92 or (((gs + 0.055) / 1.055) ^ 2.4) - local rb = bs <= 0.03928 and bs / 12.92 or (((bs + 0.055) / 1.055) ^ 2.4) + local rr = rs <= 0.03928 and rs / 12.92 or math.pow((rs + 0.055) / 1.055, 2.4) + local rg = gs <= 0.03928 and gs / 12.92 or math.pow((gs + 0.055) / 1.055, 2.4) + local rb = bs <= 0.03928 and bs / 12.92 or math.pow((bs + 0.055) / 1.055, 2.4) return rr * 0.2126 + rg * 0.7152 + rb * 0.0722 end @@ -279,6 +309,7 @@ function TerminalView:new(options) self.modified_since_last_focus = false end + function TerminalView:shift_selection_update() local shifts = self.terminal:update() if shifts and not self.focused then self.modified_since_last_focus = true end @@ -379,8 +410,8 @@ function TerminalView:set_target_size(axis, value) end function TerminalView:convert_color(int, target, should_bright) - local attributes = int >> 24 - local type = (attributes & 0x7) + local attributes = bit.rshift(int, 24) + local type = bit.band(attributes, 0x7) if type == 0 then if target == "foreground" then return self.options.text, attributes end return self.options.background, attributes @@ -388,11 +419,16 @@ function TerminalView:convert_color(int, target, should_bright) if target == "foreground" then return self.options.background, attributes end return self.options.text, attributes elseif type == 2 then - local index = (int >> 16) & 0xFF - if index < 8 and should_bright and (((attributes >> 3) & 0x1) ~= 0) then index = index + 8 end - return self.options.colors[index], attributes + local index = bit.band(bit.rshift(int, 16), 0xFF) + if index < 8 and should_bright and (bit.band(bit.rshift(attributes, 3), 0x1) ~= 0) then index = index + 8 end + return self.options.colors[tonumber(index)], attributes elseif type == 3 then - return { ((int >> 16) & 0xFF), ((int >> 8) & 0xFF), ((int >> 0) & 0xFF), 255 }, attributes + return { + tonumber(bit.band(bit.rshift(int, 16), 0xFF)), + tonumber(bit.band(bit.rshift(int, 8), 0xFF)), + tonumber(bit.band(bit.rshift(int, 0), 0xFF)), + 255 + }, attributes end return nil end @@ -436,8 +472,9 @@ function TerminalView:draw() local offset = 0 local foreground, background, text_style for i = 1, #line, 2 do - background = self:convert_color(line[i] & 0xFFFFFFFF, "background") - foreground, text_style = self:convert_color(line[i] >> 32, "foreground", self.options.bold_text_in_bright_colors) + line[i] = math.tointeger(line[i]) + background = self:convert_color(bit.band(line[i], 0xFFFFFFFF), "background") + foreground, text_style = self:convert_color(bit.rshift(line[i], 32), "foreground", self.options.bold_text_in_bright_colors) if config.plugins.terminal.minimum_contrast_ratio > 0 then if not contrast_foreground[line[i]] then @@ -445,8 +482,8 @@ function TerminalView:draw() end foreground = contrast_foreground[line[i]] end - - local font = (((text_style >> 3) & 0x1) ~= 0) and self.options.bold_font or self.options.font + + local font = (bit.band(bit.rshift(text_style, 3), 0x1) ~= 0) and self.options.bold_font or self.options.font local text = line[i+1] local length = text:ulen() local valid_utf8 = length ~= nil @@ -858,7 +895,7 @@ command.add(nil, { local open_drawer = function(text) if not core.terminal_view then command.perform("terminal:toggle-drawer") end local target_view = core.active_view:is(TerminalView) and core.active_view or core.terminal_view - target_view:input(text .. target_view.options.newline) + target_view:input(text .. target_view.options.newline) end if not text then core.command_view:enter("Execute Command", { submit = open_drawer }) @@ -1005,5 +1042,3 @@ end return { class = TerminalView } - - diff --git a/screenshots/preview.png b/screenshots/preview.png new file mode 100644 index 0000000..771e9da Binary files /dev/null and b/screenshots/preview.png differ diff --git a/src/libterminal.c b/src/libterminal.c index c7df628..03b9fb1 100644 --- a/src/libterminal.c +++ b/src/libterminal.c @@ -1257,7 +1257,9 @@ static void output_line(lua_State* L, buffer_char_t* start, buffer_char_t* end, ((uint64_t)style.background.g << 8) | ((uint64_t)style.background.b << 0) ); - lua_pushinteger(L, packed); + char hex_string[24]; + sprintf(hex_string, "%lu", packed); + lua_pushstring(L, hex_string); lua_rawseti(L, -2, ++group); lua_pushlstring(L, text_buffer, last_nonzero_codepoint); if (!overflows && start >= end) {