mirror of
https://github.com/lihop/godot-xterm.git
synced 2024-11-10 04:40:25 +01:00
Fix bell behaviour according to tests
This commit is contained in:
parent
dc97c56b17
commit
685884965e
2 changed files with 31 additions and 4 deletions
|
@ -564,12 +564,15 @@ bool Terminal::get_bell_muted() const {
|
|||
|
||||
void Terminal::set_bell_cooldown(const double time) {
|
||||
bell_cooldown = time;
|
||||
|
||||
if (!bell_timer->is_stopped()) {
|
||||
bell_timer->stop();
|
||||
|
||||
double remaining_time = std::max(0.0, bell_cooldown - bell_timer->get_time_left());
|
||||
if (remaining_time > 0)
|
||||
bell_timer->start(remaining_time);
|
||||
}
|
||||
}
|
||||
|
||||
double Terminal::get_bell_cooldown() const {
|
||||
return bell_cooldown;
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
# SPDX-FileCopyrightText: 2021-2024 Leroy Hopson <godot-xterm@leroy.nix.nz>
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
class_name TerminalTest extends "res://addons/gut/test.gd"
|
||||
|
||||
var terminal: Terminal
|
||||
|
@ -22,6 +25,27 @@ class TestBell:
|
|||
terminal.write("'Ask not for whom the \a tolls; it tolls for thee' - John Donne")
|
||||
assert_signal_emit_count(terminal, "bell", 5)
|
||||
|
||||
func test_bell_mute() -> void:
|
||||
watch_signals(terminal)
|
||||
terminal.bell_muted = true
|
||||
terminal.write("\a")
|
||||
assert_signal_emit_count(terminal, "bell", 0)
|
||||
|
||||
func test_bell_cooldown() -> void:
|
||||
watch_signals(terminal)
|
||||
terminal.bell_cooldown = 10000
|
||||
terminal.write("\a")
|
||||
terminal.write("\a")
|
||||
assert_signal_emit_count(terminal, "bell", 1)
|
||||
|
||||
func test_change_cooldown_while_active() -> void:
|
||||
watch_signals(terminal)
|
||||
terminal.bell_cooldown = 10000
|
||||
terminal.write("\a")
|
||||
terminal.bell_cooldown = 0
|
||||
terminal.write("\a")
|
||||
assert_signal_emit_count(terminal, "bell", 2)
|
||||
|
||||
|
||||
class TestCursorPos:
|
||||
extends TerminalTest
|
||||
|
|
Loading…
Reference in a new issue