Pages

Saturday, 16 July 2022

A terminal emulator written in Python with 100+ lines of code!

 As a Linux admin, I have been working with terminals every day for many years. For most IT people, a terminal just works as it works, we hardly think about it while using it to do our real work.

My workflow heavily depends on "Tmux + vim", while all of them are closely related to terminals. Even though I have spent a lot of time reading materials on the internet and books to understand how terminals work, I have NOT made one by myself. To write my own terminal emulator was put on my to-do list a long time ago.

1 Why do I need to write my own terminal emulator?

There're so many stable terminal emulators right there. Most of them are free to use. Putty and MobaXterm are my favorites when I work on Windows. Recently my work laptop has been changed from Windows 10 to Ubuntu 22.04, so GNOME Terminal is my daily driver now.

My intention to write another terminal emulator is for education purposes only.  No matter how much you know about terminals until you write your own, you cannot say you really master it.

2 How is this terminal emulator implemented?

Basically, any terminal emulator has two parts, one is PTY, and the other is GUI.
Fortunately, both parts are super easy in Python.  Actually, Python's standard library provides all that a terminal emulator needs. "pty" module and "tkinter" module are what I used in the project.

3 How many lines of code?

100+ including comments!!!!

4 Where's the source code?

https://github.com/smstong/pyterm

No comments:

Post a Comment