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.
This commit is contained in:
Leroy Hopson 2022-08-15 10:35:01 +12:00
parent f49410838c
commit 6cd5facb98
No known key found for this signature in database
GPG key ID: D2747312A6DB51AA
8 changed files with 93 additions and 55 deletions

View file

@ -265,8 +265,8 @@ func _on_Panel_resized():
var size = tab_container.rect_size
if tabs.get_tab_count() > 0:
var terminal = tab_container.get_child(tabs.current_tab)
var cols = terminal.cols
var rows = terminal.rows
var cols = terminal.get_cols()
var rows = terminal.get_rows()
size_label.text = "Size: %d cols; %d rows\n(%d x %d px)" % [cols, rows, size.x, size.y]
else:
size_label.text = "Size:\n(%d x %d px)" % [size.x, size.y]

View file

@ -102,7 +102,7 @@ func _set_terminal(value: _Terminal):
return
# Connect the new terminal.
resize(_terminal.cols, _terminal.rows)
resize(_terminal.get_cols(), _terminal.get_rows())
if not _terminal.is_connected("size_changed", self, "resizev"):
_terminal.connect("size_changed", self, "resizev")
if not _terminal.is_connected("data_sent", self, "write"):

View file

@ -26,8 +26,8 @@ enum SelectionMode {
export(UpdateMode) var update_mode = UpdateMode.AUTO setget set_update_mode
var cols = 2
var rows = 2
var cols = 2 setget _set_cols, _get_cols # Deprecated.
var rows = 2 setget _set_rows, _get_rows # Deprecated.
# If true, text in the terminal will be copied to the clipboard when selected.
export(bool) var copy_on_selection
@ -44,6 +44,9 @@ export var bell_cooldown: float = 0.1
export var blink_on_time: float = 0.6
export var blink_off_time: float = 0.3
var _cols := 2
var _rows := 2
var _default_theme: Theme = preload("./themes/default.tres")
var _viewport: Viewport = preload("./nodes/terminal/viewport.tscn").instance()
var _native_terminal: Control = _viewport.get_node("Terminal")
@ -55,12 +58,6 @@ var _selecting := false
var _selecting_mode: int = SelectionMode.NONE
var _selection_timer := Timer.new()
var _dirty := false
var buffer := StreamPeerBuffer.new()
var times = 0
var _buffer := []
@ -69,12 +66,38 @@ func set_update_mode(value):
_native_terminal.update_mode = value
func get_rows() -> int:
return 0
func get_cols() -> int:
return 0
return _cols
func _get_cols() -> int:
push_warning(
"The 'cols' property of Terminal is deprecated and will be removed in a future version. Please use the `get_cols()` method instead."
)
return get_cols()
func _set_cols(_value) -> void:
push_error(
"The 'cols' property of Terminal is read-only and determined by rect_size and the theme's font size."
)
func get_rows() -> int:
return _rows
func _get_rows() -> int:
push_warning(
"The 'rows' property of Terminal is deprecated and will be removed in a future version. Please use the `get_rows()` method instead."
)
return get_rows()
func _set_rows(_value) -> void:
push_error(
"The 'rows' property of Terminal is read-only and determined by rect_size and the theme's font size."
)
func write(data) -> void:
@ -277,8 +300,8 @@ func _on_key_pressed(data: PoolByteArray, event: InputEventKey):
func _on_size_changed(new_size: Vector2):
cols = new_size.x
rows = new_size.y
_cols = new_size.x
_rows = new_size.y
emit_signal("size_changed", new_size)
@ -291,10 +314,3 @@ func _on_bell():
func _mouse_to_cell(pos: Vector2) -> Vector2:
return Vector2(pos / _native_terminal.cell_size)
func _set_size_warning(value):
if value:
push_warning(
"Terminal cols and rows are read only and determined by the font and rect sizes."
)