Probably some progress

This commit is contained in:
Daniel Inkpen 2022-11-09 22:29:11 +00:00
parent b1ec881c8c
commit 5c39a8071f
7 changed files with 47 additions and 61 deletions

View file

@ -6,7 +6,7 @@ extends Object
# GDNative does not currently support registering static functions so we fake it. # GDNative does not currently support registering static functions so we fake it.
# Only the static functions of this class should be called. # Only the static functions of this class should be called.
const LibuvUtils := preload("./libuv_utils.gdns") const LibuvUtils = preload("./libuv_utils.gdns")
static func get_os_environ() -> Dictionary: static func get_os_environ() -> Dictionary:

View file

@ -1,32 +1,22 @@
[gd_scene load_steps=3 format=2] [gd_scene load_steps=2 format=3 uid="uid://c62updkby54f3"]
[ext_resource path="res://addons/godot_xterm/nodes/terminal/terminal.gdns" type="Script" id=1] [sub_resource type="GDScript" id="1"]
script/source = "@tool
[sub_resource type="GDScript" id=1]
script/source = "tool
extends SubViewport extends SubViewport
" "
[node name="SubViewport" type="SubViewport"] [node name="SubViewport" type="SubViewport"]
size = Vector2( 2, 2 )
own_world = true
transparent_bg = true transparent_bg = true
handle_input_locally = false handle_input_locally = false
hdr = false
usage = 0
render_target_v_flip = true
render_target_clear_mode = 1
gui_snap_controls_to_pixels = false gui_snap_controls_to_pixels = false
script = SubResource( 1 ) size = Vector2i(2, 2)
render_target_clear_mode = 1
script = SubResource("1")
[node name="Terminal" type="Control" parent="."] [node name="Terminal" type="Control" parent="."]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
offset_right = -2.0 offset_right = -2.0
offset_bottom = -2.0 offset_bottom = -2.0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
rows = 2
cols = 1

View file

@ -23,11 +23,12 @@ const Signal = _PTYUnix.Signal
signal data_received(data) signal data_received(data)
signal exited(exit_code, signum) signal exited(exit_code, signum)
@export var terminal_path: NodePath := NodePath() : @export var terminal_path: NodePath = NodePath() :
get: get:
return terminal_path # TODOConverter40 Non existent get function return terminal_path
set(mod_value): set(value):
mod_value # TODOConverter40 Copy here content of set_terminal_path terminal_path = value
_set_terminal(get_node_or_null(terminal_path))
var _terminal: _Terminal = null : var _terminal: _Terminal = null :
get: get:
@ -36,26 +37,26 @@ var _terminal: _Terminal = null :
mod_value # TODOConverter40 Copy here content of _set_terminal mod_value # TODOConverter40 Copy here content of _set_terminal
# The column size in characters. # The column size in characters.
@export var cols: int: int = DEFAULT_COLS : @export var cols: int = DEFAULT_COLS :
get: get:
return cols # TODOConverter40 Copy here content of get_cols return cols # TODOConverter40 Copy here content of get_cols
set(mod_value): set(mod_value):
mod_value # TODOConverter40 Copy here content of set_cols mod_value # TODOConverter40 Copy here content of set_cols
# The row size in characters. # The row size in characters.
@export var rows: int: int = DEFAULT_ROWS : @export var rows: int = DEFAULT_ROWS :
get: get:
return rows # TODOConverter40 Copy here content of get_rows return rows # TODOConverter40 Copy here content of get_rows
set(mod_value): set(mod_value):
mod_value # TODOConverter40 Copy here content of set_rows mod_value # TODOConverter40 Copy here content of set_rows
# Environment to be set for the child program. # Environment to be set for the child program.
@export var env: Dictionary := DEFAULT_ENV @export var env: Dictionary = DEFAULT_ENV
# If true the environment variables in the env Dictionary will be merged with # If true the environment variables in the env Dictionary will be merged with
# the environment variables of the operating system (e.g. printenv), with the # the environment variables of the operating system (e.g. printenv), with the
# former taking precedence in the case of conflicts. # former taking precedence in the case of conflicts.
@export var use_os_env: bool := true @export var use_os_env: bool = true
var _cols := DEFAULT_COLS var _cols := DEFAULT_COLS
var _rows := DEFAULT_ROWS var _rows := DEFAULT_ROWS
@ -95,12 +96,7 @@ func set_rows(value: int):
func get_rows() -> int: func get_rows() -> int:
return _rows return _rows
func set_terminal_path(value := NodePath()):
terminal_path = value
_set_terminal(get_node_or_null(terminal_path))
func _set_terminal(value: _Terminal): func _set_terminal(value: _Terminal):
if _terminal == value: if _terminal == value:

View file

@ -76,17 +76,15 @@ func get_rows() -> int:
func write(data) -> void: func write(data) -> void:
assert( # "Invalid type for argument 'data'. Should be of type PackedByteArray or String."
data is PackedByteArray or data is String, assert(data is PackedByteArray or data is String)
"Invalid type for argument 'data'. Should be of type PackedByteArray or String."
)
# Will be cleared when _flush() is called after RenderingServer emits the "frame_pre_draw" signal. # Will be cleared when _flush() is called after RenderingServer emits the "frame_pre_draw" signal.
_buffer.push_back(data) _buffer.push_back(data)
# Ensure redraw is requested if terminal is visible. # Ensure redraw is requested if terminal is visible.
if visible: if visible:
update() queue_redraw()
func _flush(): func _flush():
@ -122,7 +120,7 @@ func _ready():
_viewport.size = size _viewport.size = size
_viewport.render_target_update_mode = SubViewport.UPDATE_ALWAYS _viewport.render_target_update_mode = SubViewport.UPDATE_ALWAYS
_screen.set_anchors_preset(PRESET_WIDE) _screen.set_anchors_preset(PRESET_VCENTER_WIDE)
_screen.texture = _viewport.get_texture() _screen.texture = _viewport.get_texture()
_native_terminal.connect("bell",Callable(self,"_on_bell")) _native_terminal.connect("bell",Callable(self,"_on_bell"))
@ -151,16 +149,16 @@ func _update_theme():
for color in _default_theme.get_color_list("Terminal"): for color in _default_theme.get_color_list("Terminal"):
var c: Color var c: Color
if has_theme_color(color, "Terminal"): if has_theme_color(color, "Terminal"):
c = get_color(color, "Terminal") c = get_theme_color(color, "Terminal")
else: else:
c = _default_theme.get_color(color, "Terminal") c = _default_theme.get_color(color, "Terminal")
_native_terminal.add_theme_color_override(color, c) _native_terminal.add_theme_color_override(color, c)
for font in _default_theme.get_font_list("Terminal"): for font in _default_theme.get_font_list("Terminal"):
var f: Font var f: Font
if has_theme_font(font, "Terminal"): if has_theme_font(font, "Terminal"):
f = get_font(font, "Terminal") f = get_theme_font(font, "Terminal")
elif has_theme_font("regular", "Terminal"): elif has_theme_font("regular", "Terminal"):
f = get_font("regular", "Terminal") f = get_theme_font("regular", "Terminal")
else: else:
if _default_theme.has_theme_font(font, "Terminal"): if _default_theme.has_theme_font(font, "Terminal"):
f = _default_theme.get_font(font, "Terminal") f = _default_theme.get_font(font, "Terminal")
@ -184,7 +182,7 @@ func _gui_input(event):
# Return to bottom of scrollback buffer if we scrolled up. Ignore modifier # Return to bottom of scrollback buffer if we scrolled up. Ignore modifier
# keys pressed in isolation or if Ctrl+Shift modifier keys are pressed. # keys pressed in isolation or if Ctrl+Shift modifier keys are pressed.
if ( if (
not event.scancode in [KEY_ALT, KEY_SHIFT, KEY_CTRL, KEY_META, KEY_MASK_CMD] not event.scancode in [KEY_ALT, KEY_SHIFT, KEY_CTRL, KEY_META, KEY_MASK_CMD_OR_CTRL]
and not (event.control and event.shift) and not (event.control and event.shift)
): ):
_native_terminal.sb_reset() _native_terminal.sb_reset()
@ -247,7 +245,8 @@ func _on_selection_held() -> void:
if not Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT) or _selecting_mode == SelectionMode.NONE: if not Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT) or _selecting_mode == SelectionMode.NONE:
if copy_on_selection: if copy_on_selection:
var selection = _native_terminal.copy_selection() var selection = _native_terminal.copy_selection()
OS.set_clipboard(selection) # TODO:godot4
# OS.set_clipboard(selection)
_selection_timer.stop() _selection_timer.stop()
return return

View file

@ -37,11 +37,9 @@ class ANSIColor:
const bright_white = {fg = 97, panel = 107} const bright_white = {fg = 97, panel = 107}
func _init(): func _init():
assert( # "ANSIColor is an abstract class. You should only use the color constants (e.g. ANSIColor.black)."
false, assert(false)
"ANSIColor is an abstract class. You should only use the color constants (e.g. ANSIColor.black)."
)
var terminal var terminal

View file

@ -1,21 +1,22 @@
[gd_scene load_steps=3 format=2] [gd_scene load_steps=3 format=3 uid="uid://brjrtf5fpptw8"]
[ext_resource path="res://addons/godot_xterm/terminal.gd" type="Script" id=1] [ext_resource type="Script" path="res://addons/godot_xterm/terminal.gd" id="1"]
[ext_resource path="res://examples/menu/menu.gd" type="Script" id=2] [ext_resource type="Script" path="res://examples/menu/menu.gd" id="2"]
[node name="Menu" type="Control"] [node name="Menu" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
script = ExtResource( 2 ) script = ExtResource("2")
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[node name="Terminal" type="Control" parent="."] [node name="Terminal" type="Control" parent="."]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
focus_mode = 1 focus_mode = 1
script = ExtResource( 1 ) script = ExtResource("1")
__meta__ = {
"_edit_use_anchors_": false
}

View file

@ -60,10 +60,12 @@ func _on_Terminal_key_pressed(_data, event: InputEventKey):
_tput.sgr0() _tput.sgr0()
prompt("\r\n>> ") prompt("\r\n>> ")
else: else:
var json = JavaScript.eval("JSON.stringify(%s)" % line, true) # TODO: godot4
_tput.setaf(TPut.ANSIColor.magenta) pass
terminal.write(str(json)) # var json = JavaScript.eval("JSON.stringify(%s)" % line, true)
_tput.sgr0() # _tput.setaf(TPut.ANSIColor.magenta)
# terminal.write(str(json))
# _tput.sgr0()
line = "" line = ""
#_tput.srg0() #_tput.srg0()