mirror of
https://github.com/lihop/godot-xterm.git
synced 2025-05-23 11:15:32 +02:00
feat(term): implement clear() method
Clears all but the bottommost row of the terminal (including scrollback buffer) and moves the bottommost row to the top.
This commit is contained in:
parent
fc03595e29
commit
d00a31fb45
4 changed files with 82 additions and 12 deletions
|
@ -12,7 +12,7 @@ func get_described_class():
|
|||
func pick_cell_color(cell := Vector2i(0, 0)) -> Color:
|
||||
var cell_size = subject.get_cell_size()
|
||||
var pixelv = Vector2(cell) * cell_size + (cell_size / 2)
|
||||
return get_viewport().get_texture().get_image().get_pixelv(cell_size / 2)
|
||||
return get_viewport().get_texture().get_image().get_pixelv(pixelv)
|
||||
|
||||
|
||||
func before_each():
|
||||
|
@ -27,9 +27,20 @@ func before_each():
|
|||
class TestRendering:
|
||||
extends RenderingTest
|
||||
|
||||
# Fill the terminal with colored blocks.
|
||||
func fill_color(color = Color.BLACK, rows: int = subject.get_rows()):
|
||||
subject.write("\u001b[38;2;%d;%d;%dm" % [color.r8, color.g8, color.b8])
|
||||
subject.write("█".repeat(subject.get_cols() * rows))
|
||||
|
||||
func test_render():
|
||||
fill_color(Color.BLUE)
|
||||
await wait_for_signal(subject.draw, 3)
|
||||
await wait_frames(15)
|
||||
var cell_color = pick_cell_color()
|
||||
assert_eq(cell_color, Color.BLUE)
|
||||
|
||||
func test_update():
|
||||
subject.write("\u001b[38;2;255;0;0m")
|
||||
subject.write("█".repeat(subject.get_cols() * subject.get_rows()))
|
||||
fill_color(Color.RED)
|
||||
await get_tree().physics_frame
|
||||
subject.queue_redraw()
|
||||
await wait_for_signal(subject.draw, 3)
|
||||
|
@ -37,6 +48,30 @@ class TestRendering:
|
|||
var cell_color = pick_cell_color(Vector2i(0, 0))
|
||||
assert_eq(cell_color, Color.RED)
|
||||
|
||||
func test_clear_clears_all_but_the_first_row():
|
||||
await wait_frames(15)
|
||||
var cell = Vector2i(0, 1) # Pick a cell not on the first row.
|
||||
var original_color = pick_cell_color(cell)
|
||||
call_deferred("fill_color", Color.CYAN)
|
||||
await wait_for_signal(subject.draw, 3)
|
||||
await wait_frames(15)
|
||||
subject.clear()
|
||||
await wait_for_signal(subject.draw, 3)
|
||||
await wait_frames(15)
|
||||
var cell_color = pick_cell_color(cell)
|
||||
assert_eq(cell_color, original_color)
|
||||
|
||||
func test_clear_keeps_the_last_row():
|
||||
fill_color(Color.GREEN)
|
||||
fill_color(Color.ORANGE, 1)
|
||||
await wait_for_signal(subject.draw, 3)
|
||||
await wait_frames(15)
|
||||
subject.clear()
|
||||
await wait_for_signal(subject.draw, 3)
|
||||
await wait_frames(15)
|
||||
var cell_color = pick_cell_color(Vector2i(0, 0))
|
||||
assert_eq(cell_color, Color.ORANGE)
|
||||
|
||||
|
||||
class TestKeyPressed:
|
||||
extends RenderingTest
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue