Commit graph

27 commits

Author SHA1 Message Date
Leroy Hopson
575c3875b6
Implement get_cursor_pos() 2024-02-07 23:14:52 +13:00
Leroy Hopson
8c30bec861
Add support for two different inverse modes
- Inverse mode invert (default) will invert the color in shader.
- Inverse mode swap will simply swap the foreground and background
  colors. This is the default behavior of libtsm and GodotXterm v3.
2024-02-07 23:03:11 +13:00
Leroy Hopson
930f3ef352
Expose blink_on_time and blink_off_time properties 2024-02-07 22:26:45 +13:00
Leroy Hopson
8b320622f9
Use shader include for fore/background shaders
The two shaders use a lot of common logic for co-ordinate and attribute
look up, so it makes sense to use a common include shader for both.

Adds support for the inverse and blink attributes to the foreground shader.
2024-02-07 21:59:01 +13:00
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
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
9c7c5e1c17
Reorder methods 2023-01-21 10:37:26 +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
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
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
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
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
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
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
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
007182b117 Enable compiling 64-bit on Windows using MSVC
Closes #5
2020-11-10 13:44:29 +07:00
Leroy Hopson
9bd17ec8dc Multiple changes
Former-commit-id: db8e674358
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
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
Renamed from addons/godot_xterm/src/terminal.h (Browse further)