Ringing the Terminal Bell
I’ve had to work a lot with terminal UIs at Serverpod to power our agentic coding engine which is currently in public beta. And because we’re building a first class framework for Flutter and Dart, our TUIs are also written in Dart using a pretty nice library called nocterm.
nocterm is still quite young, and so is the terminal UI space for Dart really, so we occasionally run into some issues that we tend to fix upstream to improve the library.
We received an internal report recently about the cursor not showing when the TUI is exited on iTerm2.
The cursor can easily be restored using printf '\e[?25h' but it was still an inconvenient experience. This was something that no one else had reproduced using different terminals on macOS, Linux and Windows. So far, it is unique to iTerm2.
A quick triage pointed out a few inconsistencies in the way nocterm writes the OSC commands to restore colors before leaving alternate screen mode. Specifically, the commands were not terminated using either of BEL or ST control characters.
Get Crazelu’s stories in your inbox
Join Medium for free to get updates from this writer.
The fix is to just terminate those OSC commands with the BEL character — quite straightforward . I landed a quick fix in our internal serverpod_tui library first and planned to upstream to nocterm.
While fixing this, I was very curious what BEL and ST meant so I did some digging and found something interesting.
“Historically rings the terminal bell.” What is that?
Turns out modern terminals keep a feature that used to exist physically on electromechanical teleprinters. For instance, the Teletype Model 33 had a physical bell mechanism that was activated using BEL. The completion of a remote operation could be marked by physically ringing a bell to draw the attention of the operator without printing anything. CRT terminals kept the behaviour but replaced the the mechanical bell with electronics such that an audible ‘bell’ sound can be produced for BEL. ASCII standardized BEL at byte 0x07.
Modern terminals retain support for this protocol. Some terminals will display a flash instead of playing an audible sound. The script below produces a flash in the Mac Terminal.app when the system’s volume is reduced to 0 and produces an audible sound when volume > 0.
import 'dart:io';
void main() {
stdout.write('\x07');
}You can also try this on Mac (and other POSIX-like shells) with printf '\a' instead of running a Dart script.









