Commit graph

96 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
caf3bf1910
Use standard OS macros
As per: https://sourceforge.net/p/predef/wiki/OperatingSystems/
2021-06-08 22:59:12 +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
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
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
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
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
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
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
ee6d7cb0fa Refactor file structure
Former-commit-id: 3eecf504cf
2020-10-05 17:56:57 +07:00