mirror of
https://github.com/lihop/godot-xterm.git
synced 2024-11-10 04:40:25 +01:00
Update bell
- Don't add the bell to the archive to keep it small a simplify licensing. Also bells seem to be rarely used with terminal emulators. - Don't play the bell directly from the Terminal node by adding an AudioStreamPlayer, but make it easy to tune the "bell" signal behavior from the Terminal node so that only an AudioStreamPlayer node's play() method needs to be connected to it. - Keep the bell.wav sound around for testing/demo.
This commit is contained in:
parent
d702021d02
commit
55b0a0577d
8 changed files with 42 additions and 30 deletions
|
@ -24,4 +24,7 @@ env = {
|
|||
"TERM": "xterm-256color"
|
||||
}
|
||||
|
||||
[node name="Bell" type="AudioStreamPlayer" parent="."]
|
||||
|
||||
[connection signal="bell" from="." to="Bell" method="play"]
|
||||
[connection signal="exited" from="PTY" to="." method="_on_PTY_exited"]
|
||||
|
|
|
@ -41,7 +41,7 @@ export var ctrl_scroll_to_resize_font := true
|
|||
# Bell settings.
|
||||
export var visual_bell := true
|
||||
export var audio_bell := true
|
||||
export var bell_sound: AudioStream = preload("../../../themes/audio/bell.wav")
|
||||
export var bell_sound: AudioStream
|
||||
|
||||
# Exec args.
|
||||
export (FileType) var file_type := FileType.USE_SHELL_ENV
|
||||
|
|
|
@ -35,14 +35,16 @@ var rows = 2
|
|||
export (bool) var copy_on_selection
|
||||
|
||||
# Bell
|
||||
# If enabled, bell_sound will play when the ASCII BELL "\u0007" character is printed.
|
||||
export var bell_enabled := true
|
||||
export var bell_sound: AudioStream
|
||||
# Number of milliseconds that must pass before emitting a new bell sound.
|
||||
# This important in cases where the bell character is being printed frequently
|
||||
# such as `while true; do echo -e "\a"; done`, as adding additional AudioStreamPlayer
|
||||
# nodes too frequently has a negative performance impact.
|
||||
export var bell_cooldown_msec: int = 100
|
||||
# If muted, the "bell" signal will not be emitted when the bell "\u0007" character
|
||||
# is written to the terminal.
|
||||
export var bell_muted := false
|
||||
# Amount of time in seconds that must pass before emitting a new "bell" signal.
|
||||
# This can be useful in cases where the bell character is being written too
|
||||
# frequently such as `while true; do echo -e "\a"; done`.
|
||||
export var bell_cooldown: float = 0.1
|
||||
|
||||
export var blink_on_time: float = 0.6
|
||||
export var blink_off_time: float = 0.3
|
||||
|
||||
var _viewport: Viewport = preload("./viewport.tscn").instance()
|
||||
var _native_terminal: Control = _viewport.get_node("Terminal")
|
||||
|
@ -229,20 +231,10 @@ func _on_size_changed(new_size: Vector2):
|
|||
|
||||
|
||||
func _on_bell():
|
||||
if bell_enabled and bell_sound and _bell_timer.time_left == 0:
|
||||
var player := AudioStreamPlayer.new()
|
||||
player.stream = bell_sound
|
||||
player.autoplay = true
|
||||
player.playing = true
|
||||
player.connect("finished", self, "_on_player_finished", [player])
|
||||
add_child(player)
|
||||
_bell_timer.start(0.001 * bell_cooldown_msec)
|
||||
|
||||
emit_signal("bell")
|
||||
|
||||
|
||||
func _on_player_finished(player: AudioStreamPlayer):
|
||||
player.queue_free()
|
||||
if not bell_muted and (bell_cooldown == 0 or _bell_timer.time_left == 0):
|
||||
emit_signal("bell")
|
||||
if bell_cooldown > 0:
|
||||
_bell_timer.start(bell_cooldown)
|
||||
|
||||
|
||||
func _mouse_to_cell(pos: Vector2) -> Vector2:
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
[gd_scene load_steps=4 format=2]
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_xterm/nodes/terminal/terminal.gd" type="Script" id=1]
|
||||
[ext_resource path="res://examples/menu/menu.gd" type="Script" id=2]
|
||||
[ext_resource path="res://addons/godot_xterm/themes/audio/bell.wav" type="AudioStream" id=3]
|
||||
|
||||
[node name="Menu" type="Control"]
|
||||
anchor_right = 1.0
|
||||
|
@ -21,6 +20,5 @@ script = ExtResource( 1 )
|
|||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
bell_sound = ExtResource( 3 )
|
||||
|
||||
[connection signal="key_pressed" from="Terminal" to="." method="_on_Terminal_key_pressed"]
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
[gd_scene load_steps=3 format=2]
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://themes/audio/bell.wav" type="AudioStream" id=1]
|
||||
[ext_resource path="res://addons/godot_xterm/nodes/pty/unix/pty_unix.gd" type="Script" id=2]
|
||||
[ext_resource path="res://examples/terminal/terminal.gd" type="Script" id=3]
|
||||
|
||||
|
@ -12,6 +13,7 @@ __meta__ = {
|
|||
"_edit_use_anchors_": false
|
||||
}
|
||||
copy_on_selection = true
|
||||
bell_cooldown = 0.1
|
||||
|
||||
[node name="PTY" type="Node" parent="."]
|
||||
script = ExtResource( 2 )
|
||||
|
@ -20,3 +22,8 @@ env = {
|
|||
"COLORTERM": "truecolor",
|
||||
"TERM": "xterm-256color"
|
||||
}
|
||||
|
||||
[node name="Bell" type="AudioStreamPlayer" parent="."]
|
||||
stream = ExtResource( 1 )
|
||||
|
||||
[connection signal="bell" from="." to="Bell" method="play"]
|
||||
|
|
|
@ -10,6 +10,7 @@ func before_each():
|
|||
|
||||
|
||||
func test_bell() -> void:
|
||||
term.bell_cooldown = 0
|
||||
term.write(char(7))
|
||||
term.write(char(0x07))
|
||||
term.write("\a")
|
||||
|
@ -17,3 +18,14 @@ func test_bell() -> void:
|
|||
term.write("'Ask not for whom the \a tolls; it tolls for thee' - John Donne")
|
||||
yield(yield_to(term, "bell", 1), YIELD)
|
||||
assert_signal_emit_count(term, "bell", 5)
|
||||
|
||||
|
||||
func test_bell_cooldown() -> void:
|
||||
watch_signals(term)
|
||||
term.bell_cooldown = 0.5
|
||||
term.write("\a")
|
||||
term.write("\a")
|
||||
yield(yield_for(0.5), YIELD)
|
||||
term.write("\a")
|
||||
yield(yield_to(term, "bell", 1), YIELD)
|
||||
assert_signal_emit_count(term, "bell", 2)
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
importer="wav"
|
||||
type="AudioStreamSample"
|
||||
path="res://.import/bell.wav-54a2dcec0c35ce7bf9aa23071616df00.sample"
|
||||
path="res://.import/bell.wav-0bb68f27c3e29a9aad676dc03d89b163.sample"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/godot_xterm/themes/audio/bell.wav"
|
||||
dest_files=[ "res://.import/bell.wav-54a2dcec0c35ce7bf9aa23071616df00.sample" ]
|
||||
source_file="res://themes/audio/bell.wav"
|
||||
dest_files=[ "res://.import/bell.wav-0bb68f27c3e29a9aad676dc03d89b163.sample" ]
|
||||
|
||||
[params]
|
||||
|
Loading…
Reference in a new issue