Fix bell behaviour according to tests

This commit is contained in:
Leroy Hopson 2024-02-18 14:07:07 +13:00
parent dc97c56b17
commit 685884965e
No known key found for this signature in database
GPG key ID: D2747312A6DB51AA
2 changed files with 31 additions and 4 deletions

View file

@ -564,11 +564,14 @@ bool Terminal::get_bell_muted() const {
void Terminal::set_bell_cooldown(const double time) { void Terminal::set_bell_cooldown(const double time) {
bell_cooldown = time; bell_cooldown = time;
if (!bell_timer->is_stopped()) {
bell_timer->stop(); bell_timer->stop();
double remaining_time = std::max(0.0, bell_cooldown - bell_timer->get_time_left()); double remaining_time = std::max(0.0, bell_cooldown - bell_timer->get_time_left());
if (remaining_time > 0) if (remaining_time > 0)
bell_timer->start(remaining_time); bell_timer->start(remaining_time);
}
} }
double Terminal::get_bell_cooldown() const { double Terminal::get_bell_cooldown() const {

View file

@ -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" class_name TerminalTest extends "res://addons/gut/test.gd"
var terminal: Terminal var terminal: Terminal
@ -22,6 +25,27 @@ class TestBell:
terminal.write("'Ask not for whom the \a tolls; it tolls for thee' - John Donne") terminal.write("'Ask not for whom the \a tolls; it tolls for thee' - John Donne")
assert_signal_emit_count(terminal, "bell", 5) 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: class TestCursorPos:
extends TerminalTest extends TerminalTest