From 685884965ebf9a863b2ae2172eac50799727efd9 Mon Sep 17 00:00:00 2001 From: Leroy Hopson Date: Sun, 18 Feb 2024 14:07:07 +1300 Subject: [PATCH] Fix bell behaviour according to tests --- addons/godot_xterm/native/src/terminal.cpp | 11 ++++++---- test/test_terminal.gd | 24 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/addons/godot_xterm/native/src/terminal.cpp b/addons/godot_xterm/native/src/terminal.cpp index 74d9ca6..9f29a2a 100644 --- a/addons/godot_xterm/native/src/terminal.cpp +++ b/addons/godot_xterm/native/src/terminal.cpp @@ -564,11 +564,14 @@ bool Terminal::get_bell_muted() const { void Terminal::set_bell_cooldown(const double time) { bell_cooldown = time; - 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); + 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 { diff --git a/test/test_terminal.gd b/test/test_terminal.gd index 49c59ad..8d50d30 100644 --- a/test/test_terminal.gd +++ b/test/test_terminal.gd @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021-2024 Leroy Hopson +# 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