Skip to content

Commit

Permalink
Changes to work with pragtical luajit
Browse files Browse the repository at this point in the history
  • Loading branch information
jgmdev committed Mar 20, 2024
1 parent d8c4916 commit e912f75
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 76 deletions.
14 changes: 2 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: CI
on: { push: { branches: [master] } }
permissions: write-all
jobs:
version:
runs-on: ubuntu-latest
Expand All @@ -26,9 +27,8 @@ jobs:
build_linux:
needs: [version]
permissions: write-all
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
defaults: { run: { shell: bash } }
container: ghcr.io/lite-xl/lite-xl-build-box:latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
Expand Down Expand Up @@ -100,13 +100,3 @@ jobs:
gh release upload continuous Linux/*.so MacOS/*.so Windows/*.dll
git tag -f continuous
git push -f origin refs/tags/continuous
- name: Discord Webhook
env: { DISCORD_WEBHOOK: "${{ secrets.DISCORD_WEBHOOK }}" }
run: |
if [[ `git tag --points-at HEAD v* | head -c 1` == "v" ]]; then
perl -pe 'last if $_ =~ m/^\s*#/ && $_ !~ m/#\s*${{ needs.version.outputs.version }}/' < CHANGELOG.md | tail -n +2 > NOTES.md
perl -e 'use JSON qw(encode_json from_json); $/ = undef; print encode_json({ content => "## Lite XL Terminal v${{ needs.version.outputs.version }} has been released!\nhttps://github.com/adamharrison/lite-xl-terminal/releases/tag/v${{ needs.version.outputs.version }}\n\n### Changes in ${{ needs.version.outputs.version }}:\n" . <> })' < NOTES.md |
curl -H 'Content-Type:application/json' $DISCORD_WEBHOOK -X POST -d "$(</dev/stdin)"
fi
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.

33 changes: 16 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -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](https://github.com/adamharrison/lite-xl-terminal/assets/1034518/6b8003da-d4c1-4227-8fc9-3d2b1ae89bf2)

## Description

Expand Down Expand Up @@ -51,43 +51,43 @@ 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

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
Expand All @@ -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
```

53 changes: 23 additions & 30 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
{
"addons" : [
{
"description" : "An integrated terminal for lite-xl. *([screenshot](https://github.com/adamharrison/lite-xl-terminal/assets/1034518/eb8a72a0-ff61-4b95-b009-364ac2725f70))*",
"files" : [
{
"arch" : "x86_64-linux",
"checksum" : "2c742b98469642bc683b00c7a1f5185746b86548118d3194f9a0f6129ff4125d",
"url" : "https://github.com/adamharrison/lite-xl-terminal/releases/download/v1.02/libterminal.x86_64-linux.so"
},
{
"arch" : "x86_64-darwin",
"checksum" : "5b5928e721242b6582239442fa46f361688a0319a02371457f0ea562e9730d44",
"url" : "https://github.com/adamharrison/lite-xl-terminal/releases/download/v1.02/libterminal.x86_64-darwin.so"
},
{
"arch" : "aarch64-darwin",
"checksum" : "bcfe13dd078afdc9a454cd29126f5f7051c0dbfa0154104587812400497bc849",
"url" : "https://github.com/adamharrison/lite-xl-terminal/releases/download/v1.02/libterminal.aarch64-darwin.so"
},
{
"arch" : "x86_64-windows",
"checksum" : "e1cc1ad4b7b4bb9fe24f5a1acbf63b5883b77875b28075a12a5886ddb15347aa",
"url" : "https://github.com/adamharrison/lite-xl-terminal/releases/download/v1.02/libterminal.x86_64-windows.dll"
}
],
"id" : "terminal",
"path" : "plugins/terminal",
"version" : "1.02"
}
]
"addons": [{
"id": "terminal",
"description": "An integrated terminal for pragtical.",
"version": "1.02",
"path": "plugins/terminal",
"files": [{
"url": "https://github.com/pragtical/terminal/releases/download/latest/libterminal.x86_64-linux.so",
"arch": "x86_64-linux",
"checksum": "SKIP"
}, {
"url": "https://github.com/pragtical/terminal/releases/download/latest/libterminal.x86_64-darwin.so",
"arch": "x86_64-darwin",
"checksum": "SKIP"
}, {
"url": "https://github.com/pragtical/terminal/releases/download/latest/libterminal.aarch64-darwin.so",
"arch": "aarch64-darwin",
"checksum": "SKIP"
}, {
"url": "https://github.com/pragtical/terminal/releases/download/latest/libterminal.x86_64-windows.dll",
"arch": "x86_64-windows",
"checksum": "SKIP"
}]
}]
}
108 changes: 93 additions & 15 deletions plugins/terminal/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,79 @@ config.plugins.terminal = common.merge({
[245] = { common.color "#8a8a8a" }, [246] = { common.color "#949494" }, [247] = { common.color "#9e9e9e" }, [248] = { common.color "#a8a8a8" }, [249] = { common.color "#b2b2b2" },
[250] = { common.color "#bcbcbc" }, [251] = { common.color "#c6c6c6" }, [252] = { common.color "#d0d0d0" }, [253] = { common.color "#dadada" }, [254] = { common.color "#e4e4e4" },
[255] = { common.color "#eeeeee" }
},
config_spec = {
name = "Terminal",
{
label = "Shell",
description = "Path to the shell binary.",
path = "shell",
type = "file",
exists = true,
default = default_shell
},
{
label = "Drawer Height",
description = "Default height of the console drawer.",
path = "drawer_height",
type = "number",
default = 300,
min = 10
},
{
label = "Scrollback Limit",
description = "Amount of lines you can emit before we start cutting them off.",
path = "scrollback_limit",
type = "number",
default = 10000
},
{
label = "Background Color",
description = "Default background color if not explicitly set by the shell.",
path = "background",
type = "color",
default = { common.color "#000000" },
},
{
label = "Foreground Color",
description = "Default foreground color if not explicitly set by the shell.",
path = "text",
type = "color",
default = { common.color "#FFFFFF" },
},
{
label = "Font",
description = "The font and fallbacks used on the terminal.",
path = "font",
type = "font",
default = {
fonts = {
{
name = "JetBrains Mono Regular",
path = DATADIR .. "/fonts/JetBrainsMono-Regular.ttf"
}
},
options = {
size = 15,
antialiasing = "subpixel",
hinting = "slight"
}
}
},
{
label = "Bold Text in Bright Colors",
description = "Whether to use bright colors for bold text.",
path = "bold_text_in_bright_colors",
type = "toggle",
default = true
},
{
label = "Debug",
description = "Outputs a terminal.log file of all the output of your shell.",
path = "debug",
type = "toggle",
default = false
}
}
}, config.plugins.terminal)
if not config.plugins.terminal.bold_font then config.plugins.terminal.bold_font = config.plugins.terminal.font:copy(style.code_font:get_size(), { smoothing = true }) end
Expand All @@ -122,9 +195,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

Expand Down Expand Up @@ -294,20 +367,25 @@ 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
elseif type == 1 then
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
Expand Down Expand Up @@ -351,17 +429,18 @@ 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
contrast_foreground[line[i]] = ensureContrastRatio(background, foreground, config.plugins.terminal.minimum_contrast_ratio)
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
Expand Down Expand Up @@ -737,6 +816,7 @@ end, {
command.add(nil, {
["terminal:toggle-drawer"] = function()
if not core.terminal_view then
system.chdir(core.root_project().path)
core.terminal_view = TerminalView(config.plugins.terminal)
core.root_view:get_active_node_default():split("down", core.terminal_view, { y = true }, true)
core.set_active_view(core.terminal_view)
Expand Down Expand Up @@ -890,5 +970,3 @@ end
return {
class = TerminalView
}


4 changes: 3 additions & 1 deletion src/libterminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,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) {
Expand Down

0 comments on commit e912f75

Please sign in to comment.