randy3k / Terminus

Bring a real terminal to Sublime Text
https://packagecontrol.io/packages/Terminus
MIT License
1.37k stars 83 forks source link

Add option to suppress bell in Terminus with Sublime Text #390

Open tbullock opened 1 year ago

tbullock commented 1 year ago

Description: Currently, when using Terminus with Sublime Text, there is no option to suppress the bell sound when a shell generates it. This is particularly problematic when connecting over SSH or when running shell commands that produce a bell character, such as when a command is completed, or when there is an error. The lack of an option to suppress the bell can be disruptive and distracting to users.

Suggested Solution: Suggest adding an option to Terminus that would allow users to disable the bell sound when it is generated by the shell. This could be a simple boolean in the Terminus settings that when true, would suppress the bell sound. This would provide users with greater control over the sound settings in Terminus and improve their overall user experience.

Steps to Reproduce:

  1. Open Terminus with Sublime Text.
  2. Run a shell command that generates a bell character.
    • For Windows: Type the command echo ^G and press Enter where ^G is entered by pressing Ctrl and G simultaneously.
    • For Unix-like systems: Type the command echo -e '\a' and press Enter.
  3. Notice that the bell sound is played and cannot be disabled.

Note that bell characters are regularly generated in many shells when failing to auto-complete, attempting to back-space before the beginning of a line, etc. It is quite distracting.

Expected Result: The bell sound is not played when the option to suppress it is enabled.

Actual Result: The bell sound is played even when there is no option to suppress it.

Environment:

Additional Information: This feature request would greatly benefit users who work with Terminus on a regular basis, particularly those who connect to remote servers via SSH or work with shell commands that produce a bell character. The ability to suppress the bell sound would make it easier to focus on their work without being disrupted by unnecessary sounds.

randy3k commented 1 year ago

It is only a windows issue? echo -e '\a' doesn't produce a bell sound on macOS.

Anyway, it could be fixed by overriding some methods in TerminalPtyProcess. Need to check what it is.

tbullock commented 1 year ago

I'm not entirely certain if this is true, but I would be willing to bet that Macos disables the bell character from doing anything by default. It's a terminal feature from the era when teletype operators needed to get the attention of each other, they could send a bell character which would ring the bell at the remote end of a teletype. This was adopted in early Unix and Windows and remains to this day. Many modern terminals (including the new-fangled Windows terminal) can disable it entirely.

To answer your question, it definitely does impact Windows. I'm sitting here going batty when I try to use Terminus and get bells going off when I hit a typo!

For instance on Windows terminal: image

and PuTTY

image

etc etc, it's a common feature.

I think the solution might be something like this

# Within the _parser_fsm method

if char in basic:
    if (char == ctrl.SI or char == ctrl.SO) and self.use_utf8:
        continue

    # Add this conditional check to suppress the bell character if the setting is enabled
    if char == "\a" and self.suppress_bell:
        continue

And just add a boolean option suppress_bell to sublime settings

randy3k commented 1 year ago

I meant it doesn’t produce a bell sound on macOS Terminus. It certainly makes a noise in the system Terminal.

I tracked upstream, it seems that the default implementation is empty https://github.com/selectel/pyte/blob/a1c089e45b5d0eef0f3450984350254248f02519/pyte/screens.py#L958

randy3k commented 1 year ago

Found it. https://github.com/rprichard/winpty/issues/147

It is an windows specific issue because of the use of winpty on windows. There is a workaround in an upstream bug.

Ultimately, we want to move to newer version of pywinpty which uses the ConPTY instead of winpty.

randy3k commented 1 year ago

Besides the workaround, there is nothing we could do here. The signal was intercepted by winpty and the sound was made even before it reaches Terminus.

tbullock commented 1 year ago

For the time being, I've switched from KSH to CSH on the target machine since it can be configured not to emit bell characters as a workaround.

Ideally, the terminal should be able to handle this though. Thanks for the footwork.