Commit graph

58 commits

Author SHA1 Message Date
Leroy Hopson
13cf5ba023
feat(term): implement copy_selection()
Implements the copy_selection() method, which returns the selected text.

Adds a copy_on_selection property. When this property is enabled, the
selected text will automatically be copied to the primary clipboard
(Linux X11/Wayland only).
2024-03-03 21:04:16 +13:00
Leroy Hopson
7f03761fb2
fix(pty): remove non-portable signal enums
Remove signal enum members which do not use portable numbers, and
therefore may be different on different operating systems.
2024-03-03 21:04:16 +13:00
Leroy Hopson
b78bdf3136
feat(pty): rename get_pts() -> get_pts_name() 2024-03-03 21:04:16 +13:00
Leroy Hopson
1a5f0f96da
chore(test): update tests
Adds additional tests for the interface. Creates a new base test class
GodotXtermTest that adds some additional assert methods. Tests
inheriting from this should override the got_described_class() method.
Add instance of the described class named 'subject' will be created and
added to the scene tree before each test.
2024-03-03 15:41:30 +13:00
Leroy Hopson
a0c9777264
feat(pty): add multithread support
Adds the option `use_threads` to PTY (enabled by default) which improves
performance when enabled. For example, running `time cat file.txt` where
file is ~4.5MB will take ~0.250s with threads enabled, versus >20s when
disabled.
2024-03-02 22:49:48 +13:00
Leroy Hopson
8cd11fdae6
fix(term): prevent double keyboard input
Disconnects the "gui_input" signal as the _gui_input() override is
working as expected now. Having this signal connected was causing it to
be called twice for every input.
2024-02-25 22:06:58 +13:00
Leroy Hopson
988788fc68
feat(term): implement data_sent signal 2024-02-25 21:14:03 +13:00
Leroy Hopson
43634affa3
chore(just): update test recipe
Updates the test recipe to use the os_family() function to determine
which test files to include.

Renames 'test_unix.gd' -> 'test_nix.gd'.
2024-02-25 20:51:29 +13:00
Leroy Hopson
05b19c1336
feat(term): implement "key_pressed" signal
Also adds tests for write response as code relating to this was
modified.
2024-02-25 20:25:32 +13:00
Leroy Hopson
c36500615d
feat(pty): further pty development 2024-02-25 17:55:31 +13:00
Leroy Hopson
1514f42b54
feat(pty): add initial pty node 2024-02-25 11:48:47 +13:00
Leroy Hopson
aa6b447c6c
Wait 5 more frames in rendering test
When using opengl3 rendering driver on macos, we need to wait a few more
frames in order for the test to pass.
2024-02-24 16:58:52 +13:00
Leroy Hopson
4771a3c9a7
Fix rendering according to test 2024-02-18 20:31:08 +13:00
Leroy Hopson
685884965e
Fix bell behaviour according to tests 2024-02-18 20:24:27 +13:00
Leroy Hopson
dc97c56b17
Use type Vector2i for get_cursor_pos()
Cursor position is always integer.
2024-02-18 14:06:30 +13:00
Leroy Hopson
db3564f0cc
Setup tests
- Install Gut using gd-plug.
- Add some basic tests.
- Update workflow to run tests.
- Add test and gd-plug install/uninstall recipes to Justfile.
- Re-enable debug builds as these are used by editor when testing.
2024-02-18 14:06:25 +13:00
Leroy Hopson
002e7aacc7
Auto-format files using new pre-commit config 2024-02-13 10:52:22 +13:00
Leroy Hopson
14db14679f
chore: add .import files 2024-02-06 23:56:06 +13:00
Leroy Hopson
cea41d6567
Update GUT to version 9.1.1 2024-01-06 23:33:15 +13:00
Leroy Hopson
893c768f75
Update gdtoolkit to version 4.2.2 2024-01-06 23:11:04 +13:00
Leroy Hopson
98b42733fb
Fix tests
Part of #66. Many tests still failing.
2023-01-21 15:36:03 +13:00
Leroy Hopson
15e5b2b8c7
Remove references to terminal.gd 2023-01-21 15:33:56 +13:00
Leroy Hopson
e563a15ce2
Format files using GDScript Toolkit 2023-01-21 15:33:25 +13:00
Leroy Hopson
4490296d4d
Update .import files 2022-12-28 11:43:36 +13:00
Daniel Inkpen
cdbf3f2adc Godot 4 automatic changes 2022-11-09 20:57:46 +00: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
b2f190d29a
Remove support for deprecated theme item names 2022-08-26 12:30:07 +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
344c04f9d8
Move terminal bell tests from unit -> integration
The bell tests rely on timers and yields, so are too slow to run as part
of the unit test suite.
2022-08-22 10:05:41 +12:00
Leroy Hopson
6cd5facb98
Deprecate the cols and rows properties of Terminal
As cols and rows are read only (i.e. automatically determined by rect
and font size) there is no need for the properties to be exposed.
Instead, users can get the calculated cols and rows using the get_cols()
and get_rows() methods.
2022-08-22 10:05:36 +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
054c7c9ad4
Ensure initial PTY size matches Terminal (if any)
If a PTY has a terminal_path set to a valid Terminal, then ensure that
the initial cols and rows of PTY match the cols and rows of the Terminal
when calling fork() or open(), otherwise PTY will output wrong-sized
data for the Terminal until resized.

Fixes #56.
2022-08-15 17:09:25 +12:00
Leroy Hopson
d558b07fd4 Prevent loss of focus on Tab/Arrow key press
Prevents Terminal losing focus when in a scene with other inputs and
the Tab or Arrow keys are pressed.

Fixes #51.
2022-08-05 10:55:24 +12:00
Leroy Hopson
d99a750d33
Stop testing for Godot version 3.2 2022-07-12 12:51:24 +12:00
Leroy Hopson
df32ee3c18
Refactor PTY
PTY now provides a public interface to an underlying instance of
PTYNative. The PTYNative class can be extended as appropriate for
each platform and the platform-specific implementation will be
selected by PTY at runtime.
2022-07-11 09:33:01 +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
38927e0a3e
Fix winsize test to support unsigned short
The type of winsize.ws_col and winsize.ws_row is unsigned short, so
change python's struct.unpack format from 'hh' (short) to 'HH'.
Otherwise, we can only test sizes up to 32767 when actually sizes up to
65535 are supported.
2022-07-11 09:33:01 +12:00
Leroy Hopson
5fcc9b0595
Increase terminal test yield timeout
Wait a little longer for "bell" signal to be emitted.
2022-07-11 09:33:01 +12:00
Leroy Hopson
deb68e323c
Reformat existing gdscript code 2022-07-11 09:33:00 +12:00
Leroy Hopson
9d15420df3
Move terminal.gd and pty.gd to godot_xterm directory
Makes for pretty paths when extending scripts:
`extends "res://addons/godot_xterm/terminal.gd"`
vs.
`extends "res://addons/godot_xterm/nodes/terminal/terminal.gd"`

Currently "res://addons/godot_xterm/pty.gd" is acutally `pty_unix.gd`.
This is okay for now as the PTY node is only supported on Unix
platforms. However, we will need to sort it out when adding Windows
support as part of #25.

Also remove the GDXterm namespace.
2021-07-26 00:39:48 +07:00
Leroy Hopson
bec14fee14
Enable tests for v3.2
OS.set_environment() not available in v3.2 so create a new gut config
file that skips these tests for v3.2.
2021-07-23 22:07:57 +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
55b0a0577d
Update bell
- Don't add the bell to the archive to keep it small a simplify
  licensing. Also bells seem to be rarely used with terminal emulators.
- Don't play the bell directly from the Terminal node by adding an
  AudioStreamPlayer, but make it easy to tune the "bell" signal behavior
  from the Terminal node so that only an AudioStreamPlayer node's play()
  method needs to be connected to it.
- Keep the bell.wav sound around for testing/demo.
2021-07-23 08:37:49 +07:00
Leroy Hopson
1d86bd6ec6
Add some files for manually testing fonts, colors and UTF8 2021-07-23 07:42:43 +07:00
Leroy Hopson
16d231fc63
Update tests
- Enable tests for osx.universal platform.
- Export HTML5 (but skip upload as .cast files aren't exported
  properly).
- HACK: Use HTML5 export to generate .import directory for tests
  This way we don't get an error message even if using
  `continue-on-error` set to `true`.
2021-07-20 12:02:23 +07:00
Leroy Hopson
3e2162d366
Add basic .xrdb/.Xresources import plugin
Adds basic support for importing .Xresources and .xrdb files as Theme
resources.

Examples of terminal color schemes in .xrdb format can be found here:
https://github.com/mbadolato/iTerm2-Color-Schemes/tree/master/xrdb

Examples of terminal themes in .Xresources format can be found here:
https://github.com/mbadolato/iTerm2-Color-Schemes/tree/master/Xresources

https://terminal.sexy also supports exporting themes is Xresources
format.
2021-07-19 00:10:16 +07:00
Leroy Hopson
b08d218a59
Run tests in CI environment
Currently tests only run on X11.64 platform.
But other platforms can be supported with a bit of effort.
Remove default bell sound as it does not play nicely with CI environment
that does not have sound card.
2021-07-18 23:05:17 +07:00
Leroy Hopson
09dc080a2e Add support for the bell "\a" character
Closes #39
2021-07-03 22:47:33 +07:00
Leroy Hopson
115521f645
Replace Gut with WAT
Gut was freezing on some integration tests. It was also entering an
infinite loop after exiting (even after closing Godot and VSCode) which
caused a `godot.log` file in app_userdata to keep growing until my hard
drive was full.
2021-07-03 21:49:24 +07:00