mirror of
https://github.com/lihop/godot-xterm.git
synced 2024-11-25 02:30:27 +01:00
Probably some progress
This commit is contained in:
parent
b1ec881c8c
commit
5c39a8071f
7 changed files with 47 additions and 61 deletions
|
@ -6,7 +6,7 @@ extends Object
|
|||
# GDNative does not currently support registering static functions so we fake it.
|
||||
# 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:
|
||||
|
|
|
@ -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
|
||||
"
|
||||
|
||||
[node name="SubViewport" type="SubViewport"]
|
||||
size = Vector2( 2, 2 )
|
||||
own_world = true
|
||||
transparent_bg = true
|
||||
handle_input_locally = false
|
||||
hdr = false
|
||||
usage = 0
|
||||
render_target_v_flip = true
|
||||
render_target_clear_mode = 1
|
||||
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="."]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_right = -2.0
|
||||
offset_bottom = -2.0
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
rows = 2
|
||||
cols = 1
|
||||
|
|
|
@ -23,11 +23,12 @@ const Signal = _PTYUnix.Signal
|
|||
signal data_received(data)
|
||||
signal exited(exit_code, signum)
|
||||
|
||||
@export var terminal_path: NodePath := NodePath() :
|
||||
@export var terminal_path: NodePath = NodePath() :
|
||||
get:
|
||||
return terminal_path # TODOConverter40 Non existent get function
|
||||
set(mod_value):
|
||||
mod_value # TODOConverter40 Copy here content of set_terminal_path
|
||||
return terminal_path
|
||||
set(value):
|
||||
terminal_path = value
|
||||
_set_terminal(get_node_or_null(terminal_path))
|
||||
|
||||
var _terminal: _Terminal = null :
|
||||
get:
|
||||
|
@ -36,26 +37,26 @@ var _terminal: _Terminal = null :
|
|||
mod_value # TODOConverter40 Copy here content of _set_terminal
|
||||
|
||||
# The column size in characters.
|
||||
@export var cols: int: int = DEFAULT_COLS :
|
||||
@export var cols: int = DEFAULT_COLS :
|
||||
get:
|
||||
return cols # TODOConverter40 Copy here content of get_cols
|
||||
set(mod_value):
|
||||
mod_value # TODOConverter40 Copy here content of set_cols
|
||||
|
||||
# The row size in characters.
|
||||
@export var rows: int: int = DEFAULT_ROWS :
|
||||
@export var rows: int = DEFAULT_ROWS :
|
||||
get:
|
||||
return rows # TODOConverter40 Copy here content of get_rows
|
||||
set(mod_value):
|
||||
mod_value # TODOConverter40 Copy here content of set_rows
|
||||
|
||||
# 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
|
||||
# the environment variables of the operating system (e.g. printenv), with the
|
||||
# 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 _rows := DEFAULT_ROWS
|
||||
|
@ -97,11 +98,6 @@ func get_rows() -> int:
|
|||
return _rows
|
||||
|
||||
|
||||
func set_terminal_path(value := NodePath()):
|
||||
terminal_path = value
|
||||
_set_terminal(get_node_or_null(terminal_path))
|
||||
|
||||
|
||||
func _set_terminal(value: _Terminal):
|
||||
if _terminal == value:
|
||||
return
|
||||
|
|
|
@ -76,17 +76,15 @@ func get_rows() -> int:
|
|||
|
||||
|
||||
func write(data) -> void:
|
||||
assert(
|
||||
data is PackedByteArray or data is String,
|
||||
"Invalid type for argument 'data'. Should be of type PackedByteArray or String."
|
||||
)
|
||||
# "Invalid type for argument 'data'. Should be of type PackedByteArray or String."
|
||||
assert(data is PackedByteArray or data is String)
|
||||
|
||||
# Will be cleared when _flush() is called after RenderingServer emits the "frame_pre_draw" signal.
|
||||
_buffer.push_back(data)
|
||||
|
||||
# Ensure redraw is requested if terminal is visible.
|
||||
if visible:
|
||||
update()
|
||||
queue_redraw()
|
||||
|
||||
|
||||
func _flush():
|
||||
|
@ -122,7 +120,7 @@ func _ready():
|
|||
_viewport.size = size
|
||||
_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()
|
||||
|
||||
_native_terminal.connect("bell",Callable(self,"_on_bell"))
|
||||
|
@ -151,16 +149,16 @@ func _update_theme():
|
|||
for color in _default_theme.get_color_list("Terminal"):
|
||||
var c: Color
|
||||
if has_theme_color(color, "Terminal"):
|
||||
c = get_color(color, "Terminal")
|
||||
c = get_theme_color(color, "Terminal")
|
||||
else:
|
||||
c = _default_theme.get_color(color, "Terminal")
|
||||
_native_terminal.add_theme_color_override(color, c)
|
||||
for font in _default_theme.get_font_list("Terminal"):
|
||||
var f: Font
|
||||
if has_theme_font(font, "Terminal"):
|
||||
f = get_font(font, "Terminal")
|
||||
f = get_theme_font(font, "Terminal")
|
||||
elif has_theme_font("regular", "Terminal"):
|
||||
f = get_font("regular", "Terminal")
|
||||
f = get_theme_font("regular", "Terminal")
|
||||
else:
|
||||
if _default_theme.has_theme_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
|
||||
# keys pressed in isolation or if Ctrl+Shift modifier keys are pressed.
|
||||
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)
|
||||
):
|
||||
_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 copy_on_selection:
|
||||
var selection = _native_terminal.copy_selection()
|
||||
OS.set_clipboard(selection)
|
||||
# TODO:godot4
|
||||
# OS.set_clipboard(selection)
|
||||
_selection_timer.stop()
|
||||
return
|
||||
|
||||
|
|
|
@ -37,10 +37,8 @@ class ANSIColor:
|
|||
const bright_white = {fg = 97, panel = 107}
|
||||
|
||||
func _init():
|
||||
assert(
|
||||
false,
|
||||
"ANSIColor is an abstract class. You should only use the color constants (e.g. ANSIColor.black)."
|
||||
)
|
||||
# "ANSIColor is an abstract class. You should only use the color constants (e.g. ANSIColor.black)."
|
||||
assert(false)
|
||||
|
||||
|
||||
var terminal
|
||||
|
|
|
@ -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 path="res://examples/menu/menu.gd" type="Script" id=2]
|
||||
[ext_resource type="Script" path="res://addons/godot_xterm/terminal.gd" id="1"]
|
||||
[ext_resource type="Script" path="res://examples/menu/menu.gd" id="2"]
|
||||
|
||||
[node name="Menu" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
script = ExtResource( 2 )
|
||||
script = ExtResource("2")
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Terminal" type="Control" parent="."]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
focus_mode = 1
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
script = ExtResource("1")
|
||||
|
|
|
@ -60,10 +60,12 @@ func _on_Terminal_key_pressed(_data, event: InputEventKey):
|
|||
_tput.sgr0()
|
||||
prompt("\r\n>> ")
|
||||
else:
|
||||
var json = JavaScript.eval("JSON.stringify(%s)" % line, true)
|
||||
_tput.setaf(TPut.ANSIColor.magenta)
|
||||
terminal.write(str(json))
|
||||
_tput.sgr0()
|
||||
# TODO: godot4
|
||||
pass
|
||||
# var json = JavaScript.eval("JSON.stringify(%s)" % line, true)
|
||||
# _tput.setaf(TPut.ANSIColor.magenta)
|
||||
# terminal.write(str(json))
|
||||
# _tput.sgr0()
|
||||
|
||||
line = ""
|
||||
#_tput.srg0()
|
||||
|
|
Loading…
Reference in a new issue