Commit graph

149 commits

Author SHA1 Message Date
Leroy Hopson
a849423096
Rewrite terminal.cpp
Rewrites the Terminal class as a GDExtension to be used directly in
Godot without a terminal.gd proxy.

Breaks a lot of things in its current state (e.g. signals and other
functions have not be implemented yet), but does add support for
transparent colors and true color inversion. It also seems to
be about 4x faster (FPS-wise) than the old version with some basic
stress testing.

Old source code has been moved to a different directory to be copied
over and/or rewritten piece by piece.
2024-02-07 00:14:33 +13:00
Leroy Hopson
7d2e22530e
Update libtsm 2024-02-06 23:56:21 +13:00
Leroy Hopson
f694544834
Remove unused code 2024-01-07 11:07:20 +13:00
Leroy Hopson
33ca5b3af7
Change build options
- Removes --disable-pty build option.
- Sets debug_symbols="yes" when build target is debug.
2024-01-07 11:06:26 +13:00
Leroy Hopson
b18726eac9
Pin nixpkgs version 2024-01-06 23:22:39 +13:00
Leroy Hopson
fac6361898
Upgrade min compatible Godot version to 4.2.1 2024-01-06 23:22:34 +13:00
Leroy Hopson
11ed797005
Update godot-cpp to match Godot v4.0-rc1 API
Usage of VARIANT_ENUM_CAST has changed.
2023-02-12 10:53:34 +13:00
Leroy Hopson
f36f1db315
Allow SCONS_CACHE env var in pure nix environment 2023-02-12 10:53:34 +13:00
Leroy Hopson
2ba480b4da
Update build files and GitHub Actions workflow 2023-01-26 08:21:43 +13:00
Leroy Hopson
9f269aec8c
Make update_modue a dropdown in editor inspector
Closes #61.
2023-01-21 11:03:22 +13:00
Leroy Hopson
9c7c5e1c17
Reorder methods 2023-01-21 10:37:26 +13:00
Leroy Hopson
754a20b1c3
Remove unused include 2023-01-21 10:18:26 +13:00
Leroy Hopson
dee6d537c0
Update godot-cpp for Godot v4.0-beta12 2023-01-14 22:38:17 +13:00
Leroy Hopson
8d56b5659a
Re-enable building of godot-cpp dependency 2023-01-14 22:35:30 +13:00
Leroy Hopson
ad7f97e493
Further progress towards Godot 4.0 support
- Primary example scenes (menu, terminal, and asciicast) working but
  still a lot of warning/error messages and some regressions.
- Editor integrated terminal works, but still a lot of warning/error
  messages and some regressions.
- Added support for "blink" display attribute.
- Removed GDScript terminal code. Terminal node is now purely a
  GDExtension. So is LibuvUtils.
- GUT tests not working yet.
- Still a lot of things to fix.
- So far, only built for and manually tested on Linux x86_64.
2023-01-08 22:45:18 +13:00
Leroy Hopson
44f7e3801c
Convert from GDNative to GDExtension
Work in progress.
2022-12-29 22:54:38 +13:00
Leroy Hopson
9435502c8d
Statically link libstdc++
Otherwise binaries build on GitHub Actions fail to load on NixOS as
dynamically linked libstdc++ cannot be found.
2022-08-27 20:45:41 +12:00
Leroy Hopson
10b9764fb3
Use default export templates for HTML5
Changes Emscripten SDK version to match that used to compile the default export
templates used by Godot 3.5 (in this case 3.1.14 as can be seen here:
https://github.com/godotengine/build-containers/blob/3.5/Dockerfile.javascript).

This means we no longer need to compile custom export templates when
exporting HTML5 for Godot 3.5. Exports from other Godot versions may
requiring compiling the GDNative library with a different version of the
Emscripten SDK.

- Changes renderer from GLES3 -> GLES2 and reduces MSAA level to better
  support HTML5 export.
- Updates GitHub Action to export HTML5 and upload as a build artifact.
- Adds Cypress test to smoke test HTML5 export.
2022-08-27 10:32:22 +12:00
Leroy Hopson
9765e94889
Change target Godot version to v3.5-stable
Upgrade setup-godot action from v1 -> v2 which changes default Godot
version from 3.4 -> 3.5.
2022-08-26 16:53:02 +12:00
Leroy Hopson
95b66115c4
Update/deprecate theme item names
Updates theme names to be compatible with Godot 3.5 (no spaces),
consistent with other Godot theme item names (snake_case), and
match the color names listed on the
[ANSI escape code wikipedia page](https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit).

Deprecates the old names and warns users to change them.
2022-08-26 09:28:38 +12:00
Leroy Hopson
d45ea7a3cd
Update libtsm to not erase screen on palette change
Fixes #57.
Fixes #58.
2022-08-22 22:56:50 +12:00
Leroy Hopson
f49410838c
Drop support for Godot 3.3.x 2022-08-22 10:02:50 +12:00
Leroy Hopson
9ed6750b83
Fix unicode errors
Changes `write()` method of native pipe and terminal to accept a
PoolByteArray rather than String. This means that `get_string_from_utf8()`
is no longer called on data coming from PTY and being sent to Terminal.

The terminal state machine already has a UTF8 parser which maintains
its state across calls to `write()`. This means that we can write half
the bytes of a single unicode character in one call and the remaining half
in the next call and the state machine will parse it correctly.

On the other hand, the `get_string_from_utf8()` method of Godot's
PoolByteArray requires that the array contains completely valid UTF8,
otherwise we get errors such as "Unicode error: invalid skip".

The data coming from PTY can be arbitrarily split in the middle of a
unicode character meaning that we will sometimes get errors when calling
`get_string_from_utf8()` on it. This is more likely to occur when there
is a large amount of output (i.e. it's more likely to be split). In other
cases, the data might intentionally contain invalid unicode such as when
printing binary files or random data (e.g. `cat /bin/sh`, `cat /dev/random`).

We avoid these errors by passing the PoolByteArray data directly to the terminal
state machine.

In addition to fixing unicode errors, this commit:
- Prevents repeated calls to pipes `_read_cb()` method that would block Godot
  and result in a crash with the message "ERROR: All memory pool allocations
  are in use" that resulted from writing data to an ever-increasing number of
  PoolByteArrays before any of them could be freed. This could be triggered by
  running the `cat /dev/urandom` command after making the change to `write()`
  mentioned above.
- Prevents memory leaks by freeing libuv buffers after they have been copied
  to PoolByteArrays.

Fixes #55.
2022-08-15 17:09:29 +12:00
Leroy Hopson
8a3adbbe68
Fix GitHub Actions godot-cpp-linux Docker build 2022-08-03 22:41:12 +12:00
Leroy Hopson
0ae1d80abb
Prevent exit callback instance leaks
De-references pty_baton's exit callback after it is called so it can be
automatically released, preventing leaked instances.

Adds basic implementation for Pipe's get_status() method and forces PTY
to wait for child process to exit to ensure exit callback is cleaned up.

Adds a test to check that exit callback is still called as usual.
2022-07-11 09:33:01 +12:00
Leroy Hopson
bea5d1c27d
Check if baton FuncRef is valid before calling call_funcv()
Often when closing a terminal in the terminal panel the error message
'Condition "!obj" is true.' would be printed to console.

This was due to the call_funcv() method being called on an invalid
FuncRef instance (invalid because it had already been deleted or queued
for delection).

Now we check the instance is valid before calling the method.
2022-07-11 09:33:00 +12:00
Leroy Hopson
f0bd70cb3e
Update target Godot version: 3.3.2-stable -> 3.4.4-stable
Also apply automatic updates to .import files after opening project in
3.4.4 editor.
2022-07-11 09:33:00 +12:00
Leroy Hopson
3fdc9ef27e
Add Docker build for Linux
Adds support for building Linux binaries inside a docker container in
order to target an older version of GLIBC.

Updates GitHub Actions workflow to use it.

As a result the minimum version of GLIBC that Linux users need to have
installed on their system is 2.17 which was released in 2012.
2022-07-11 09:33:00 +12:00
Leroy Hopson
1d51acb38d
Register pipe.close() method
Allows kill() method of unix PTY node to be called without error.
2022-07-11 09:33:00 +12:00
Leroy Hopson
57dadf7db2
Support universal (x86_64/arm64) builds for macOS
The macOS binary (libgodot-xterm.osx.64.dylib) is now a universal binary
that runs natively on both x86_64 and arm64.
2022-07-11 09:33:00 +12:00
Leroy Hopson
0ccac28cc6
Update godot-cpp submodule
- We now need to include `<string>` in `terminal.cpp`.
- Clean-up `.gitmodules` while we're at it.
2022-05-31 18:34:51 +07:00
Leroy Hopson
5f399ed46e
Allow theme inheritance
Terminal colors and fonts will be inherited from ancestor nodes if not
defined.
2021-07-23 09:30:25 +07:00
Leroy Hopson
c81da3820b
Kill child process and close pty on exit
- Adds kill() method to LibuvUtils.
- Adds close() method to Pipe.
2021-07-23 08:37:54 +07:00
Leroy Hopson
568a9835c6
Fallback to Regular Terminal font before default font
Will fallback to using Regular Terminal font for Bold, Italic, and Bold
Italic styles if they are not defined. Will only fallback to using the
default theme font if even Regular is not defined.
2021-07-23 08:37:47 +07:00
Leroy Hopson
10983653c6
Fix macOS builds 2021-07-20 11:18:52 +07:00
Leroy Hopson
8bc3a13adb
Fix windows builds
- Fixes build error for windows debug 32bit.
- Allows building windows release with PTY enabled.
- Updates godot-cpp.
2021-07-18 17:00:55 +07:00
Leroy Hopson
84243cd824
Enable compiling Pipe and LibuvUtils on Windows
Currently only works when building with debug target. On GitHub actions
target release results in linking errors. So disable PTY for release
builds.

Part of #25.
2021-07-18 15:09:21 +07:00
Leroy Hopson
88e5320a83
Update build script
- Add flags for target and disable_pty
- Only run docker-compose commands if docker-compose installed
2021-07-18 14:21:47 +07:00
Leroy Hopson
aa83b206a3
Update libuv 2021-07-18 11:05:56 +07:00
Leroy Hopson
97e07093b2
Change terminal menu option 'Select All' -> 'Copy All'
Adds copy_all() function to terminal node which returns all of the
screen's text.
2021-07-13 22:20:29 +07:00
Leroy Hopson
e8c27f2796
Add clear and sb_reset
Clearing the terminal removes all lines in the scrollback buffer except
for the most recent.

With sb_reset, the terminal will return the scrollback buffer to the
bottom when the user starts typing if they have previously scrolled up.
2021-07-13 06:33:44 +07:00
Leroy Hopson
e13bc7e082 Draw wide characters correctly
Draw the full background for wide characters as soon as they are
encountered. Don't draw any foreground or background if width is zero as
this means the previous character was wide.

Fixes #17
2021-07-12 22:46:43 +07:00
Leroy Hopson
5e25ebbab6 Add rudimentary terminal to editor's bottom panel
In order to use the gdnative library as an editor plugin it was
neccessary to set the `reloadable` property of the gdnlib file to false,
in order to prevent crashes when the godot editor window lost focus.

This may have consequences when recompiling the library.
See: https://docs.godotengine.org/en/3.3/classes/class_gdnativelibrary.html#class-gdnativelibrary-property-reloadable

Still crashes quite frequently and doesn't close child processes
properly.

Part of #43.
2021-07-11 23:03:33 +07:00
Leroy Hopson
f48e082b54 Reformat code causing clang-format clashes
VSCode and the clang-format git hook disagreed about how this one should
be formatted, so it kept changing.
2021-07-11 23:03:33 +07:00
Leroy Hopson
0e6334db96 Add copy selection support 2021-07-11 23:03:33 +07:00
Leroy Hopson
57c1c3524d Add basic pointer selection
Part of #4.
2021-07-11 23:03:33 +07:00
Leroy Hopson
fae28006cf Move scroll handling to GDScript
Just expose the underlying libtsm methods from gdnative, but write all
the logic in gdscript. Makes it much easier to customize and update.
2021-07-11 23:03:33 +07:00
Leroy Hopson
c95049c407
Update license information
- Renamed LICENSE -> LICENSE.md as it contains markdown, and added
  contact address.
- Adds THIRDPARTY_NOTICES.txt and THIRDPARTY_NOTICES_nopty.txt which
  bundles licenses of all third-party components for versions of
  GodotXterm compiled with and without PTY node support.
- Adds misc/gen_3rdparty_licenses.sh file to generate the above
  mentioned text files.
- Seperated node_pty and tmux licenses.
- Updated libuv submodule to use version that contains additional license
  information.
- Updated README to reflect these changes.
2021-07-07 21:39:54 +07:00
Leroy Hopson
5838b7fe7e
Add support for mouse scroll
Part of #4.
2021-07-07 21:36:24 +07:00
Leroy Hopson
44ea56aa0f
Add disable_pty compile option
If disable_pty=yes then the PTY node and dependencies (LibuvUtils, Pipe)
will be excluded. On platforms where the PTY node is not supported (e.g.
HTML5), this will always be equivalent to `disable_pty=yes`.
2021-07-07 21:32:26 +07:00
Leroy Hopson
09dc080a2e Add support for the bell "\a" character
Closes #39
2021-07-03 22:47:33 +07:00
Leroy Hopson
964af715d6 Enable Windows 32bit builds
Closes #24
2021-07-03 16:15:18 +07:00
Leroy Hopson
0dd2378387 Add new PTY node (replaces Pseudoterminal node)
Uses fork of node-pty native code for forking pseudoterminals.
Uses libuv pipe handle to communicate with the child process.

- Paves the way for cross-platform (Linux, macOS and Windows) support.
- Renames Pseudoterminal to PTY (which is much easier to type and spell :D).
- Better performance than the old Pseudoterminal node. Especially when
  streaming large amounts of data such as running the `yes` command.
- Allows setting custom file, args, initial window size, cwd, env vars
  (including important ones such as TERM and COLORTERM) and uid/gid
  on Linux and macOS.
- Returns process exit code and terminating signal.
2021-07-03 14:56:27 +07:00
Leroy Hopson
bfa561357e Yield for "frame_pre_draw" signal before writing to terminal
Fixes #41. But creates another issue where sometimes the yield will
resume after the terminal node has already been freed logging an error
to the console.

Also a few changes to where update is called it the gdnative terminal
code.

Also changed gdnative terminal to only accept strings.
2021-07-03 14:56:27 +07:00
Leroy Hopson
4e6715329a Clang-format node-pty files 2021-07-03 14:56:27 +07:00
Leroy Hopson
9c20579bc6 Add original files from the node-pty project
Taken from <https://github.com/microsoft/node-pty>.
See the LICENSE.md file added in this commit for license and copyright
information.
2021-07-03 14:56:27 +07:00
Leroy Hopson
0c43776619
Load default theme if it exists
This also means that we can load default fonts from it. Falling back to
the default Godot font if no theme is set and the default theme does not
exist.

Having an actual theme loaded also allows live font resizing.
2021-06-22 21:45:55 +07:00
Leroy Hopson
4b73c958c0
Ensure libtsm uses correct version of wcwidth
Previously it was using some other linked version, not the one in
thirdparty/libtsm/external/wcwidth.
2021-06-22 21:45:55 +07:00
Leroy Hopson
a337143949 Add libtsm patches for some escape sequences
The sequences are:
  CSI > Pp ; Pv m    (e.g. '\e[>4;m'
  CSI ? Pm $ p       (e.g. '\e[?12$p'

These sequences were being output by vim and causing the underline
attribute to be set and the terminal to be reset.

Fixes #40
2021-06-22 00:07:13 +07:00
Leroy Hopson
d2f073d7ae
Multiple updates
- Use viewport as render target for terminal:
  Terminal now only draws cells which changed since the last _draw() call.
  A viewport is used with clear mode set to NEVER to cache previous draw
  calls. The terminal node and viewport are wrapped by a GDScript Terminal
  node which takes care of resizing the viewport scene, and forcing the
  terminal to redraw all cells when necessary (i.e. on resize or theme
  change).

  Adds update_mode to terminal interface which can be set to one of:
  - DISABLED: terminal will never be drawn
  - AUTO: terminal will only draw the cells that changed, but
    automatically redraw the full screen when necessary (for example,
    when the size or theme changed).
  - ALL: terminal will always draw every cell on every update. This is
    the most reliable but least performant option.
  - ALL_NEXT_FRAME: Will use update_mode ALL for the next _draw() call,
    then change update_mode back to AUTO.

- Upgraded libtsm:
  Includes changes from Fredrik Wikstrom (salass00)'s fork of libtsm.

- Don't require theme to be set.
  Terminal will use default fonts/colors if no theme is set.
2021-06-20 18:33:40 +07:00
Leroy Hopson
03f9b84b71
Be explicit about building for debug target 2021-06-19 19:44:11 +07:00
Leroy Hopson
0743f2a97a
Use gdnative api to get constants only for javascript platform
When trying to load the library in a non-Mono Godot editor v3.3.2
an error is printed about godot_get_global_constants(). Furthermore,
the issue with using the GlobalConstants header to get constants is only
present on the javascript platform, so we can revert all other platforms
to the old way of getting constants.
2021-06-19 19:39:20 +07:00
Leroy Hopson
3fb2580fc6
Build scripts: check if submodule directories are empty
In a freshly cloned repo, submodule directories exist but are not
empty. Check if they are empty and update submodules. Previously,
submodules where only updated if their directories did not exist.
2021-06-15 14:14:48 +07:00
Leroy Hopson
bdda1458c0
Update files for javascript build and export
Adds some files to making building and export for HTML5 more convenient.
2021-06-15 14:02:40 +07:00
Leroy Hopson
c1334896d6
Explicity check not javascript when including pseudoterminal
If compiling for javascript platform on linux '__unix__' will be defined,
so instead check for the abscence of '__EMSCRIPTEN__'.
2021-06-15 14:02:01 +07:00
Leroy Hopson
0437d0f18c
Rename directory 'external' -> 'thirdparty' 2021-06-12 15:10:42 +07:00
Leroy Hopson
caf3bf1910
Use standard OS macros
As per: https://sourceforge.net/p/predef/wiki/OperatingSystems/
2021-06-08 22:59:12 +07:00
Leroy Hopson
bb8d40df58 Add HTML5 support 2021-06-07 18:29:33 +07:00
Leroy Hopson
fbb23661d3 Get KeyList constants from GDNative API
Previously KeyList constants came from the GlobalConstants.hpp header,
but this did not work when compiling for HTML5. Therefore, we now get
the globals constants from the GDNative API.

Throws the error:
`LNK2019: unresolved external symbol godot_get_global_constants referenced in function "private: static void __cdecl godot::Terminal::_populate_key_list(void)" (?_populate_key_list@Terminal@godot@@CAXXZ)`
in GitHub Windows action. So use the old technique on Windows for now.

This is a prerequisite for HTML5 support.
2021-06-06 21:57:06 +07:00
Leroy Hopson
6e455738b8 Format c++ files using clang-format
Add git pre-commit hooks to help with automatic formatting.
2021-06-06 20:05:22 +07:00
Leroy Hopson
99989d19e4 Update godot-cpp 2021-06-06 17:19:24 +07:00
Leroy Hopson
472f0f573b Add transparency support for theme colors
Closes #19.
2020-11-29 15:53:50 +07:00
Leroy Hopson
3e177b781e Set a default theme if theme property is not set
This means that the terminal is no longer blank if no theme has been
set.
2020-11-29 15:53:50 +07:00
Leroy Hopson
8b25be74c0 Don't swap red and blue channels of theme colors
Fixes #18
2020-11-29 13:32:14 +07:00
Leroy Hopson
6a626905d6 Use "Light Cyan" color from theme
Previously this color was ignored.
2020-11-29 13:32:14 +07:00
Leroy Hopson
4cc2115125 Build windows releases with /MT rather than /MD
When making a release export of a project, binaries built with the /MD
flag do not work.
2020-11-23 09:13:32 +07:00
Leroy Hopson
6689ad1c09 Remove cross-compilation dependencies
It makes the github actions workflow take longer and cross-compiled
artifacts are not currently used (nor do they seem to work).
2020-11-21 19:44:43 +07:00
Leroy Hopson
570896b9c0 Provide correct arguments to execvp
Previously no arguments were provided, but by convention argv[0] should
be the name of the program.

Providing this argumens enables Psuedoterminal node to work on macOS.
2020-11-21 13:55:05 +07:00
Leroy Hopson
b2dc46636c Update github actions workflow
- Uses matrix so that build steps don't need to be defined multiple
  times.
- Caches godot-cpp bindings, so they only need to be built when the
  submodule version changes.
- Uploads build artifacts for linux 32/64-bit, windows 64-bit and macOS
  64-bit.
2020-11-21 12:20:13 +07:00
Leroy Hopson
c075ae7418 Enable compiling on macOS 64-bit using llvm
Closes #6
2020-11-20 21:32:43 +07:00
Leroy Hopson
007182b117 Enable compiling 64-bit on Windows using MSVC
Closes #5
2020-11-10 13:44:29 +07:00
Leroy Hopson
399acf00c7 Use alloc_c_string() to convert String to char*
Using get_data() would sometimes result in the wrong data being written.

Fixes #12
2020-11-07 18:13:48 +07:00
Leroy Hopson
43df7d5331 Migrate CI from travis-ci.com to GitHub Actions 2020-11-07 17:11:25 +07:00
Leroy Hopson
630e0104d5 Add support for Windows 64-bit
Tested on NixOS, Ubuntu and Arch Linux. Not yet able to compile for
Windows 32-bit on NixOS or on Windows itself.

Part of #5
2020-11-07 17:11:25 +07:00
Leroy Hopson
8c2c48f5b4 Move and recompile pre-built binary
Move pre-built binary to 'dist' folder so it no longer causes git
conflicts with custom builds. Also make it a release build which
decreases its size by ~70M.


Former-commit-id: ea9954712062f6ab0f6af9a55d72f0324cd51e5f
2020-10-16 14:58:11 +07:00
Leroy Hopson
9e1d0b8ee2 Position background rect at 0,0
This is important when terminal is a child of a Container node and we
set the margin properties, otherwise the background rect is drawn with
an offset.


Former-commit-id: e68d2f55c9
2020-10-16 12:55:41 +07:00
Leroy Hopson
7b42b97610 Update build script
Former-commit-id: fd39635fc5
2020-10-13 16:12:16 +07:00
Leroy Hopson
3d383484e1 Add pre-built binary for x11 platform
Former-commit-id: 293d35f5c5
2020-10-05 17:56:58 +07:00
Leroy Hopson
9bd17ec8dc Multiple changes
Former-commit-id: db8e674358
2020-10-05 17:56:57 +07:00
Leroy Hopson
a55a05d3a4 Make Terminal a tool script
Former-commit-id: f63246d8ea
2020-10-05 17:56:57 +07:00
Leroy Hopson
9bdf69f6f5 Center cell string vertically
This prevents overlapping so we no longer need to draw all background
cells before the foreground.


Former-commit-id: faca53fe28
2020-10-05 17:56:57 +07:00
Leroy Hopson
cc457b8b9a Don't cache true colors
If a true color has been set it will have code -1 regardless of the
actual color. Therefore, it shouldn't be stored in the color cache
dictionary otherwise all true color cells will be colored the most
recently set value.


Former-commit-id: 0d14fd1e47
2020-10-05 17:56:57 +07:00
Leroy Hopson
2a5e07aa48 Change write method to accept both String and PoolByteArray
Will print a warning if neither of these types is used as an argument.


Former-commit-id: 57aed28a0e
2020-10-05 17:56:57 +07:00
Leroy Hopson
11657d50f7 Copy old cells to new cells when resizing
Previously all cells were erased which resulted in the screen becoming
blank in some places until it was redrawn.


Former-commit-id: ada8b1087d
2020-10-05 17:56:57 +07:00
Leroy Hopson
313f6b8b60 Ensure terminal is initialized to the correct size
Moves the call to update_size() from _init() to _ready() to ensure
Terminal is initialized to the correct size.


Former-commit-id: 66b061bf8b
2020-10-05 17:56:57 +07:00
Leroy Hopson
5e33e560f1 Move input handling into the Terminal node
Former-commit-id: d64800229f
2020-10-05 17:56:57 +07:00
Leroy Hopson
9d06d7c313 Update file format
Automatically updated by VSCode upon saving the files.


Former-commit-id: 0dabc56076
2020-10-05 17:56:57 +07:00
Leroy Hopson
e59db03d11 Rename 'modules' directory to 'external'
Former-commit-id: 8d3eec465f
2020-10-05 17:56:57 +07:00
Leroy Hopson
ee6d7cb0fa Refactor file structure
Former-commit-id: 3eecf504cf
2020-10-05 17:56:57 +07:00