I'm interested in writing a terminal emulator for fun. I roughly understand the division of labor between the shell and the terminal emulator from this post: What is the exact difference between a 'terminal', a 'shell', a 'tty' and a 'console'?, but I haven't been able to find a full, detailed description of what the mapping between keypresses and control characters needs to be, what sorts of syscalls need to be made to acquire and interact with a pty, etc.

Is there a man page I should look at? Where can I find a full, compete spec for a terminal emulator in Linux?

  • Why not look at the code existing terminal emulators? Commented May 13, 2015 at 9:51
  • @Stephane: it's much harder to wrap your head around existing code bases than to read a high level spec. I'll be writing in Haskell, so there won't be a direct correspondence between lot of the code. Also -- the people who made those implementations must have had some spec to work from, right? Have all terminal emulators been written with the previous implementation as the only reference? Commented May 13, 2015 at 10:29
  • Can anyone explain the downvote? I've looked around without much luck, I apologize if I've missed something obvious -- please let me know how I can change my question to make it a better fit for this site. Commented May 13, 2015 at 10:31

2 Answers 2


I haven't been able to find a full, detailed description of what the mapping between keypresses and control characters needs to be.

What makes you think that it needs to be anything? Hint: Why do you think that every terminal emulator program has, either directly or indirectly (via X or some such), some sort of keyboard map file?

Go and look at existing terminal emulators. Here are just a few of the open source ones that provide user-space virtual terminals using the framebuffer and the Linux input event devices.

Further reading


You should probably start at http://invisible-island.net/xterm/ctlseqs/ctlseqs.html and http://www.vt100.net/ which describe the desired behavior (at least the input/output sequences), as well as of course studying some of the terminal emulators out there, including their changelogs of the issues they addressed.

I don't think there's a complete checklist anywhere. Just a recent example: in order for ^\ to work inside the terminal, the emulator itself should make sure that SIGQUIT handler is set to its default; something we just discovered a couple of days ago to be missing from gnome-terminal, even though it's like 10+ years old. There are probably dozens of such things to care about, you'll notice them as you go along and receive reports from your users.

  • Interesting, this is exactly what I was wondering, thank you. I guess the issue here is that the hardware being emulated is ancient and this kind if info doesn't exist anymore? Commented May 13, 2015 at 16:44
  • @PatrickCollins Partially, yes. E.g. it was 15+ years ago that I last saw a physical terminal working, no clue what terminal that was. Hopefully e.g. xterm's author has much experience. Plus, there were many kinds of such terminals, all working differently. And of course modern emulators try to introduce new features that weren't available way back then, and also fix some of their brokenness which can't really be done due to compatibility issues. There are official specifications which try to describe how e.g. the ANSI sequences should work, unfortunately I'm not really familiar with them.
    – egmont
    Commented May 13, 2015 at 18:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .