Swapping xterm for mlterm

Hacking up mlterm to be a better xterm

I hacked mlterm to be almost, but not quite, exactly like xterm. Now it’s my new daily driver.

Friendship ended with xterm. Now mlterm is my best friend.
Now put these on. They’re his old clothes.

Obviously I quite like xterm, but it has one fatal flaw (maybe two) that was driving me crazy.

This crap.

xterm lacks text reflow when the window is resized. It removes text when the window is made smaller rather than re-wrap the lines. This is really painful on small screen sizes. On my chromebook I am constantly resizing to give more horizontal space to either side of a vertical split between a text editor and terminal emulator. If I move the split the terminal history I was referencing becomes practically useless.

Recent versions of mlterm have text reflow and don’t have this problem. Unless I can add text reflow support to xterm, I have to switch to mlterm.

Why mlterm?

There is a classic LWN article that pits terminal emulators against each other in terms of latency.

It shows that xterm and mlterm are really in a league of their own. It’s hard to find anything that hits the the sub 10ms mark. And anecdotally that fits with my experience. Most terminal emulators feel slow to me compared to the dead simple and glorious xterm, and it’s nice to see real data that backs that up.

I spun up the Typometer tool and was able to verify my changes and customizations don’t affect the results.

Title Min Max Avg SD
mlterm 2.0 23.7 3.0 2.3
uxterm 1.9 12.0 2.8 1.2
st 11.4 26.8 12.4 1.5
terminator 27.8 43.2 29.3 1.7
kitty 13.0 32.5 16.3 2.9

I’m not sure why my results had spikes, but it’s still clear that mlterm and xterm are the best options.

Configuring and patching

Much like xterm, mlterm has terrible default settings that make it look like a dumpster fire out of the box. This is part of a concerted effort to keep noobs from using it. If you can’t be arsed to configure a dozen obscure settings you don’t deserve the good terminal emulators.

An incredibly ugly terminal with a left-hand placed scrollbar, black on white text, and very bad kerning.
Kerning only a mother could love.

There is a convenient GUI configurator builtin that is launched by pressing Ctrl + Right Click. After enough enough fiddling and getting the colors right I ended up with:

~/.mlterm/main
scrollbar_mode = none
fg_color = #bfbfbf
bg_color = #202020
fontsize = 14
use_anti_alias = true
use_variable_column_width = false
type_engine = xft
only_use_unicode_font = true
tabsize = 4
logsize = 1024
col_size_of_width_a = 1
use_multi_column_char = true
line_space = 1
bel_mode = none
~/.mlterm/aafont
DEFAULT = DejaVu Sans Mono 14
~/.mlterm/color
black=#202020
red=#9f6060
green=#609f60
yellow=#9f9f60
blue=#60609f
magenta=#9f609f
cyan=#609f9f
white=#bfbfbf
hl_black=#808080
hl_red=#bf4040
hl_green=#40bf40
hl_yellow=#bfbf40
hl_blue=#4040bf
hl_magenta=#bf40bf
hl_cyan=#40bfbf
hl_white=#dfdfdf
~/.mlterm/key
UNUSED=SCROLL_UP

I also pushed a bunch of small hacky changes to a fork on my github. Most of the hacks (and the key config above) have to do with making the scroll behavior more like xterm. mlterm has a “backscroll” mode that you activate by default with Shift + Up. That causes problems selecting text in a terminal text editor like micro. Then once you are in backscroll mode the arrow keys scroll up and down rather than jumping down and navigating command history. That can get annoying fast if you are not used to it. I’m sure there are benefits to the default bindings, but for my own sake I ripped them out.

I also made a small change to get suckless tabbed working properly. tabbed is a fantastic utility to add tabs to any xembed-able application (mostly terminals, but could be lots of things). I have developed my own changes for tabbed as well, most notably one that spawns new tabs in the current working directory of the currently active tab.

~/bin/term
tabbed -c -r 2 mlterm --parent '' >/dev/null 2>&1 &

# the xterm equivalent
#tabbed -c -r 2 uxterm -into '' -bw 0  >/dev/null 2>&1 &

At the end I have a terminal that looks and feels exactly like xterm. But not broken. Which is all I really wanted.

Published
2024-12-28