mirror of
https://github.com/lihop/godot-xterm.git
synced 2024-11-22 01:30:25 +01:00
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:
parent
f49410838c
commit
6cd5facb98
8 changed files with 93 additions and 55 deletions
|
@ -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]
|
||||
|
|
|
@ -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"):
|
||||
|
|
|
@ -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."
|
||||
)
|
||||
|
|
|
@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
|
||||
## [Unreleased](https://github.com/lihop/godot-xterm/compare/v2.1.1...HEAD)
|
||||
### Changed
|
||||
- Deprecated the `cols` and `rows` properties of Terminal.
|
||||
These properties will be removed in a future version.
|
||||
Please use `get_cols()` and `get_rows()` instead.
|
||||
|
||||
### Removed
|
||||
- Dropped support for Godot version 3.3.x.
|
||||
|
||||
|
|
|
@ -47,19 +47,21 @@ For example if the string `"\u001b[38;2;0;255;0;mA"` was written to the terminal
|
|||
|--------------|--------------------------------------|---------|
|
||||
| [bool] | [bell_muted](#prop-bell_muted) | `false` |
|
||||
| [float] | [bell_cooldown](#prop-bell_cooldown) | `0.1` |
|
||||
| [int] | [cols](#prop-cols) | `2` |
|
||||
| [int] | [rows](#prop-rows) | `2` |
|
||||
| [int] | [cols](#prop-cols) *(deprecated)* | `2` |
|
||||
| [int] | [rows](#prop-rows) *(deprecated)* | `2` |
|
||||
| [UpdateMode] | [update_mode](#prop-update_mode) | `AUTO` |
|
||||
|
||||
|
||||
## Methods
|
||||
|
||||
| Returns | Signature |
|
||||
|----------|-----------------------------------------------------------------|
|
||||
| void | [clear](#mthd-clear) **()** |
|
||||
| [String] | [copy_all](#mthd-copy_all) **()** |
|
||||
| [String] | [copy_selection](#mthd-copy_selection) **()** |
|
||||
| void | [write](#mthd-write) **(** [String]\|[PoolByteArray] data **)** |
|
||||
| Returns | Signature |
|
||||
|----------|-------------------------------------------------------------------|
|
||||
| void | [clear](#mthd-clear) **()** |
|
||||
| [String] | [copy_all](#mthd-copy_all) **()** |
|
||||
| [String] | [copy_selection](#mthd-copy_selection) **()** |
|
||||
| [int] | [get_cols](#mthd-get_cols) **()** |
|
||||
| [int] | [get_rows](#mthd-get_rows) **()** |
|
||||
| void | [write](#mthd-write) **(** [String] \| [PoolByteArray] data **)** |
|
||||
|
||||
|
||||
## Signals
|
||||
|
@ -105,19 +107,6 @@ For example if the string `"\u001b[38;2;0;255;0;mA"` was written to the terminal
|
|||
|
||||
## Property Descriptions
|
||||
|
||||
- <a name="prop-rows" /> [int] **rows**
|
||||
|
||||
| | |
|
||||
|-----------|------------|
|
||||
| *Default* | `2` |
|
||||
| *Setter* | None |
|
||||
| *Getter* | None |
|
||||
|
||||
The number of rows in the terminal's rect.
|
||||
When using a monospace font, this is typically the number of characters that can fit from the top to the bottom.
|
||||
It will automatically update as the Control's rect_size changes, and therefore shouldn't be used to set the size of the terminal directly.
|
||||
|
||||
---
|
||||
|
||||
- <a name="prop-cols" /> [int] **cols**
|
||||
|
||||
|
@ -125,11 +114,23 @@ For example if the string `"\u001b[38;2;0;255;0;mA"` was written to the terminal
|
|||
|-----------|------------|
|
||||
| *Default* | `2` |
|
||||
| *Setter* | None |
|
||||
| *Getter* | None |
|
||||
| *Getter* | get_cols() |
|
||||
|
||||
The number of columns in the terminal's rect.
|
||||
When using a monospace font, this is typically the number of characters that can fit from one side to another.
|
||||
It will automatically update as the Control's rect_size changes, and therefore shouldn't be used to set the size of the terminal directly.
|
||||
*Deprecated*. This property is deprecated and will be removed in a future version.
|
||||
Please use [get_cols](#mthd-get_cols) instead.
|
||||
|
||||
---
|
||||
|
||||
- <a name="prop-rows" /> [int] **rows** ***Deprecated***
|
||||
|
||||
| | |
|
||||
|-----------|------------|
|
||||
| *Default* | `2` |
|
||||
| *Setter* | None |
|
||||
| *Getter* | get_rows() |
|
||||
|
||||
*Deprecated*. This property is deprecated and will be removed in a future version.
|
||||
Please use the [get_rows](#mthd-get_rows) instead.
|
||||
|
||||
---
|
||||
|
||||
|
@ -195,6 +196,22 @@ For example if the string `"\u001b[38;2;0;255;0;mA"` was written to the terminal
|
|||
|
||||
---
|
||||
|
||||
- <a name="mthd-get_cols" /> [int] **get_cols** **()**
|
||||
|
||||
Returns the width of the terminal in characters.
|
||||
When using a monospace font, this is the number of visible characters that can fit from one side of the terminal to the other in a single row.
|
||||
It will automatically update according to the terminal's rect_size and theme's font size.
|
||||
|
||||
---
|
||||
|
||||
- <a name="mthd-get_rows" /> [int] **get_rows** **()**
|
||||
|
||||
Returns the height of the terminal in characters.
|
||||
When using a monospace font, this is the number of visible characters that can fit from the top of the terminal to the bottom in a single column.
|
||||
It will automatically update according to the terminal's rect_size and theme's font size.
|
||||
|
||||
---
|
||||
|
||||
- <a name="mthd-write" /> void **write** **(** [String] \| [PoolByteArray] data **)**
|
||||
|
||||
Writes data to the terminal emulator. Accepts either a [String] or [PoolByteArray].
|
||||
|
|
|
@ -52,7 +52,7 @@ func _ready():
|
|||
|
||||
|
||||
func draw_all(_size = Vector2.ZERO):
|
||||
offset = int(floor(($Terminal.cols / 2.0) - (TITLE_WIDTH / 2.0)))
|
||||
offset = int(floor(($Terminal.get_cols() / 2.0) - (TITLE_WIDTH / 2.0)))
|
||||
tput.reset()
|
||||
row = 5
|
||||
tput.civis() # Hide the cursor.
|
||||
|
@ -94,7 +94,7 @@ func draw_menu():
|
|||
var item = menu_items[i]
|
||||
|
||||
if not col_offset:
|
||||
col_offset = int(floor(($Terminal.cols / 2) - (item.name.length() / 2)))
|
||||
col_offset = int(floor(($Terminal.get_cols() / 2) - (item.name.length() / 2)))
|
||||
|
||||
tput.cup(row, offset)
|
||||
|
||||
|
|
|
@ -212,12 +212,12 @@ class TestPTYSize:
|
|||
|
||||
assert_eq(
|
||||
stty_rows,
|
||||
terminal.rows,
|
||||
terminal.get_rows(),
|
||||
"Expected stty to report correct number of rows for layout '%s'" % s
|
||||
)
|
||||
assert_eq(
|
||||
stty_cols,
|
||||
terminal.cols,
|
||||
terminal.get_cols(),
|
||||
"Expected stty to report correct number of columns for layout '%s'" % s
|
||||
)
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ onready var terminal = $Terminal
|
|||
|
||||
|
||||
func _ready():
|
||||
print("terminal size; rows %d; cols %d;" % [terminal.rows, terminal.cols])
|
||||
print("terminal size; rows %d; cols %d;" % [terminal.get_rows(), terminal.get_cols()])
|
||||
terminal.write("h")
|
||||
yield(get_tree().create_timer(1), "timeout")
|
||||
terminal.write(" i")
|
||||
|
|
Loading…
Reference in a new issue