Using a 1978 terminal in 2026 (DEC VT-100)
Using a 1978 terminal in 2026 (DEC VT-100)
在 2026 年使用 1978 年的终端(DEC VT-100)
made a little terminal explainer, based on the original terminal pic.twitter.com/cdYCTN7jAn— nikhil (@jhanikhil) April 28, 2026
我制作了一个关于终端的小说明,基于原始终端的图片。—— nikhil (@jhanikhil) 2026年4月28日
I spent the last few weeks making a coding agent for the terminal. This strikes me as anachronistic: the terminal is technology from before my lifetime, and I’m using it as the interface to exhilarating, terrifying, cutting-edge, trillion dollar modern day research. I find the juxtaposition nice. It’s a reminder that I build on what came before me, and others will build on what I leave behind.
过去几周,我一直在为终端编写一个编程代理(coding agent)。这让我感到一种时代错位感:终端技术在我出生前就已经存在,而我却用它作为界面,去操作那些令人兴奋、恐惧、尖端且价值万亿美元的现代研究。我发现这种并置很有趣。它提醒我,我是站在前人的肩膀上构建事物,而未来的人们也将站在我留下的基础上继续前行。
All modern terminals are (roughly) emulations of a single terminal released in 1978: the Digital Equipment Corporation VT-100. In theory, I could take the app that I built and run it on the VT-100. If my software ran there, would it run everywhere? To find out, I bought a VT-100 and decided to use it as my main terminal. Here’s what I learned.
所有现代终端(大致上)都是 1978 年发布的一款终端的模拟:数字设备公司(DEC)的 VT-100。理论上,我可以把我构建的应用程序放在 VT-100 上运行。如果我的软件能在那里运行,它是不是就能在任何地方运行?为了找出答案,我买了一台 VT-100,并决定把它当作我的主力终端。以下是我学到的东西。
What is a VT-100? A VT-100 is a terminal: a screen and a keyboard that you plug into a computer. It’s roughly analogous to the Terminal or Console or Command Prompt app on your computer today. It is not a computer itself. The VT-100’s protocol (i.e. ANSI escape sequences, more on this later) are used today by all modern terminals.
什么是 VT-100?VT-100 是一台终端:一个连接到计算机的屏幕和键盘。它大致相当于你今天电脑上的“终端”(Terminal)、“控制台”(Console)或“命令提示符”(Command Prompt)应用程序。它本身不是一台计算机。VT-100 的协议(即 ANSI 转义序列,稍后详述)至今仍被所有现代终端所使用。
The VT100 has a CRT display and a keyboard. You power it on from a stick switch near the power supply. After flipping the switch it makes a startup beep noise. While on there’s an high-pitch whine from the CRT. The pitch is high enough that a couple of my friends can’t hear it at all. The VT-100 has Intel inside (there’s an 8080 in there) and 3 KB RAM. This is less than you need to get to the moon (4 KB, Apollo 11). The keyboard I have is from a VT120, and it is unfortunately awful: the keys are mushy, don’t register without a deep press, and are placed awkwardly for modern usage. We have innovated on keyboard design since then.
VT-100 配备了 CRT 显示器和键盘。你通过电源附近的拨杆开关来启动它。拨动开关后,它会发出启动蜂鸣声。开机时,CRT 会发出一种高频的嗡嗡声。这种声音频率很高,以至于我的几个朋友根本听不见。VT-100 内部搭载了英特尔芯片(里面有一颗 8080 处理器)和 3 KB 的内存。这比登月所需的内存(阿波罗 11 号为 4 KB)还要少。我手里的键盘来自 VT120,遗憾的是它手感极差:按键软绵绵的,不深按就没反应,而且布局对于现代使用习惯来说非常别扭。自那时起,我们在键盘设计上已经有了长足的进步。
How do terminals work? On the terminal end it is pretty simple. There is one stream of bytes going into the VT-100, and one stream of bytes coming out of the VT-100. When you send bytes in via a computer, they show up on the VT-100’s screen. When you type on the keyboard, bytes come out.
终端是如何工作的?在终端这一端,原理非常简单。有一股字节流进入 VT-100,也有一股字节流从 VT-100 输出。当你通过计算机发送字节时,它们会显示在 VT-100 的屏幕上。当你敲击键盘时,字节就会输出。
How do interactive apps like vim work? Special sequences of text called “ANSI escape sequences” can be used to move the VT100’s cursor around. For example, ^[D moves the cursor left. Similar sequences are used for colors, italics, bolding, and other visual features. By moving the cursor around and writing formatted text, programmers can build interactive apps.
像 vim 这样的交互式应用是如何工作的?被称为“ANSI 转义序列”的特殊文本序列可以用来移动 VT-100 的光标。例如,^[D 可以将光标向左移动。类似的序列也被用于颜色、斜体、加粗和其他视觉效果。通过移动光标和写入格式化文本,程序员可以构建交互式应用程序。
The computer end is surprisingly complicated. On Linux and MacOS, there are ttys (teletypewriters) and ptys (pseudoterminals) that exist as files in /dev. A pty has two sides, the host and the client, where the host is controlled by your terminal. The client side is a tty. This is how virtualized (i.e. non-hardware / modern) terminals work. The kernel tty subsystem is remarkably complicated for legacy reasons. It has a raw mode and a cooked mode (chat… it’s cooked) (this isn’t a joke that’s actually what it’s called).
计算机这一端则出奇地复杂。在 Linux 和 MacOS 上,存在着作为 /dev 下文件的 tty(电传打字机)和 pty(伪终端)。pty 有两端,即主机端和客户端,其中主机端由你的终端控制,客户端则是 tty。这就是虚拟化(即非硬件/现代)终端的工作方式。由于历史原因,内核的 tty 子系统非常复杂。它有“原始模式”(raw mode)和“熟模式”(cooked mode)(别开玩笑……它真的叫这个名字)。
If you’re bored you can put your terminal into cooked mode by running stty cooked. In cooked mode, the kernel handles “line discipline”, which handles more than I expected: echoing characters you type to the screen, generating SIGTERM on Control + C, flow control, and even line editing (the kernel can natively handle ^W and ^U, try running cat and typing). If you want full control over the terminal you need to uncook the terminal from userspace first (raw mode). This lets application developers decide what happens when keys are pressed without the kernel getting in the way.
如果你觉得无聊,可以通过运行 stty cooked 将终端置于“熟模式”。在熟模式下,内核会处理“行规程”(line discipline),它处理的事情比我预想的要多:将你输入的字符回显到屏幕上、在按下 Control + C 时生成 SIGTERM 信号、流量控制,甚至包括行编辑(内核可以原生处理 ^W 和 ^U,试着运行 cat 然后输入看看)。如果你想要完全控制终端,首先需要从用户空间将终端“解熟”(即原始模式)。这让应用程序开发者可以在不被内核干扰的情况下,决定按下按键时会发生什么。
The raw and cooked modes are shorthand for a particular list of configuration flags that the kernel’s TTY subsystem has. There are options that are not set in either mode, such as IXON for flow control. But nobody needs flow control in 2026 (foreshadowing).
原始模式和熟模式是内核 TTY 子系统特定配置标志列表的简写。有些选项在两种模式下都不会被设置,例如用于流量控制的 IXON。但在 2026 年,没人需要流量控制了(伏笔)。
How do you use a VT-100? The VT-100 speaks the RS-232 standard, which is in common use today. You can go to the store and buy a cable that plugs into the VT-100, and it’ll show up under /dev/ttyUSB0. I had a mild skill issue plugging it in. I bought a wrongly keyed cable, so I had to run jumper wires instead of using the connector properly. I looked at the wiring diagram and tried wiring the TX, RX, and ground to the cable and tried to send bytes to it via echo foo > /dev/ttyUSB0 but it didn’t work. I then brought out the oscilloscope and noticed that it was sending in both directions. RX and TX were flipped. Classic.
如何使用 VT-100?VT-100 使用的是今天仍在通用的 RS-232 标准。你可以去商店买一根能插进 VT-100 的线,它就会出现在 /dev/ttyUSB0 下。我在连接时遇到了一点小麻烦。我买错了接口类型的线,所以不得不使用跳线,而不是直接使用连接器。我查看了接线图,尝试将 TX、RX 和地线连接到电缆上,并尝试通过 echo foo > /dev/ttyUSB0 发送字节,但没成功。后来我拿出示波器,发现它在两个方向上都在发送信号。原来是 RX 和 TX 接反了。经典错误。
Was that enough to run my app on the VT-100? Unfortunately, that’s where the ease ended. Nobody today uses an external terminal over a USB connection. Why would you want to do that? USB devices have metadata associated with them that tells Linux the device on the other end is a printer or something, not an external terminal.
这样就能在 VT-100 上运行我的应用了吗?遗憾的是,轻松的部分到此为止。今天没人会通过 USB 连接使用外部终端。你为什么要这么做呢?USB 设备带有元数据,会告诉 Linux 另一端的设备是打印机之类的东西,而不是外部终端。
Issue #1: Flow control. At this point I could echo a couple of bytes into the tty device and see them on the VT-100, or cat bytes out of the device and see them on my Mac. However, if I tried to run my shell pointed at the tty device it blew up and half the characters would drop. The issue was that the VT-100 has inline flow control that expects the host (i.e. the computer) to stop sending bytes if it is overwhelmed. It appears that this feature either never existed in MacOS or was removed at some point. We tried forcing it via stty but it just didn’t work. We ended up running a Linux VM and setting the same option, which immediately worked. This is enough to get bash and vim and other simple apps working.
问题 1:流量控制。此时,我可以向 tty 设备 echo 几个字节并能在 VT-100 上看到它们,或者从设备 cat 字节并在我的 Mac 上看到。然而,如果我尝试将 shell 指向该 tty 设备运行,它就会崩溃,并且会丢失一半字符。问题在于 VT-100 具有内联流量控制,它期望主机(即计算机)在过载时停止发送字节。看来这个功能在 MacOS 中要么从未存在,要么在某个时候被移除了。我们尝试通过 stty 强制开启,但没用。最终我们运行了一个 Linux 虚拟机并设置了同样的选项,结果立刻生效了。这足以让 bash、vim 和其他简单的应用程序运行起来。
Issue #2: Full terminal redraws are painful. The VT-100 is slow. It runs at 9600 baud. That might sound like a lot, but text that contains a lot of ANSI escape sequences quickly exceeds this budget. The VT-100 doesn’t even support sending at the full 9600 baud continuously with any escape sequences. Text containing escape sequences is limited to even less than 9600. At this speed, full screen redraws are slow. The solution to this is a “differential renderer”: a render
问题 2:全屏重绘非常痛苦。VT-100 很慢。它的运行速度是 9600 波特。这听起来可能不少,但包含大量 ANSI 转义序列的文本很快就会超出这个带宽限制。VT-100 甚至不支持在包含任何转义序列的情况下持续以 9600 波特的全速发送。包含转义序列的文本传输速度甚至低于 9600。在这种速度下,全屏重绘非常缓慢。解决办法是使用“差异渲染器”(differential renderer):一种渲染……