st as an Alacritty replacement

2021-08-01 (last update on 2022-12-17)

Coming from Alacritty

Until some weeks ago I used Alacritty. I liked it from the first day:

First impression of st

When I started using dwm over one year ago, I also tried st and wanted to see if it could replace Alacritty as my daily terminal. My first impressions:

  1. I don't like the colors (dark blue text on black background).
  2. The font is too small.
  3. Some usual shortcuts don't work (like Ctrl-+ for increasing the font size).
  4. You can't scroll.
  5. You can't copy text to the clipboard.
  6. You can't open links in a web browser by clicking on them.
  7. st crashes when it sees a color emoji.
Screenshot of Alacritty and st

Screenshot: Alacritty 0.8.0 on the left side, st 0.8.2 on the right side

The responsiveness seems to be about the same for st and Alacritty (this depends on which benchmark you look at).

The main advantage of st is that it's small (both the source code and the binary) and therefore easily maintainable.

VIRT RES SHR
alacritty unconfigured 868504 61776 42428
st unconfigured 20308 9560 7012
st with patches below applied 22380 11796 7108

Table: Memory usage in kB (as printed by top)

So why would I want to tackle all these cons listed above for saving some megabytes of RAM (on a modern laptop that has around 10 GB of unused memory)?

The answer is: As a matter of principle I prefer the more efficient software (though not at any price).

st configured and patched

Of course, you need to invest some time to get everything configured as you like it. But having the possibility to configure everything is one of the reasons you use Linux (or BSD), isn't it?

1. The colors

You can spend a lot of time choosing the perfect colors for your terminal. I just thought, Alacritty's colors are fine, so I quickly searched its source code and found the default colors here. If you copy that block and apply some vim magic, you'll get this patch:

diff --git a/config.def.h b/config.def.h
index c9c196a..08d515b 100644
--- a/config.def.h
+++ b/config.def.h
@@ -95,32 +95,34 @@ char *termname = "st-256color";
 unsigned int tabspaces = 8;

 /* Terminal colors (16 first used in escape sequence) */
+/* Alacritty's default colors */
 static const char *colorname[] = {
     /* 8 normal colors */
-    "black",
-    "red3",
-    "green3",
-    "yellow3",
-    "blue2",
-    "magenta3",
-    "cyan3",
-    "gray90",
+    [0] = "#1d1f21", /* black   */
+    [1] = "#cc6666", /* red     */
+    [2] = "#b5bd68", /* green   */
+    [3] = "#f0c674", /* yellow  */
+    [4] = "#81a2be", /* blue    */
+    [5] = "#b294bb", /* magenta */
+    [6] = "#8abeb7", /* cyan    */
+    [7] = "#c5c8c6", /* white   */

     /* 8 bright colors */
-    "gray50",
-    "red",
-    "green",
-    "yellow",
-    "#5c5cff",
-    "magenta",
-    "cyan",
-    "white",
+    [8]  = "#666666", /* black   */
+    [9]  = "#d54e53", /* red     */
+    [10] = "#b9ca4a", /* green   */
+    [11] = "#e7c547", /* yellow  */
+    [12] = "#7aa6da", /* blue    */
+    [13] = "#c397d8", /* magenta */
+    [14] = "#70c0b1", /* cyan    */
+    [15] = "#eaeaea", /* white   */

     [255] = 0,

     /* more colors can be added after 255 to use with DefaultXX */
     "#cccccc",
     "#555555",
+    "black",
 };

2. Font and default font size

@@ -5,7 +5,8 @@
  *
  * font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html
  */
-static char *font = "Liberation Mono:pixelsize=12:antialias=true:autohint=true";
+static char *font = "DejaVu Sans Mono:pixelsize=19:antialias=true:autohint=true";
 static int borderpx = 2;

3. More common shortcuts

Use Ctrl++/-/0 for increasing/decreasing/resetting the font size:

@@ -199,6 +199,9 @@ static Shortcut shortcuts[] = {
     { TERMMOD,              XK_Prior,       zoom,           {.f = +1} },
     { TERMMOD,              XK_Next,        zoom,           {.f = -1} },
     { TERMMOD,              XK_Home,        zoomreset,      {.f =  0} },
+    { ControlMask,          XK_plus,        zoom,           {.f = +1} },
+    { ControlMask,          XK_minus,       zoom,           {.f = -1} },
+    { ControlMask,          XK_0,           zoomreset,      {.f =  0} },
     { TERMMOD,              XK_C,           clipcopy,       {.i =  0} },
     { TERMMOD,              XK_V,           clippaste,      {.i =  0} },
     { TERMMOD,              XK_Y,           selpaste,       {.i =  0} },

4. Scroll up

Apply the scrollback patch(es):

5. Write access to the clipboard

This is as easy as setting allowwindowops to 1:

@@ -46,7 +46,7 @@ int allowaltscreen = 1;

 /* allow certain non-interactive (insecure) window operations such as:
    setting the clipboard text */
-int allowwindowops = 0;
+int allowwindowops = 1;

6. Open a link in browser

Apply the patches copyurl + open_copied_url as a workaround. Then you can cycle through visible URLs with Alt-l and open the selected URL with Alt-o (via xdg-open).

7. Don't crash because of color emojis

This is not a bug it st but in its dependency libxft. → How to patch it (in Ubuntu).

8. Other features available in Alacritty

Alacritty has a vi mode for "moving around Alacritty's viewport and scrollback using the keyboard". And you can search the buffer. The vim browse patch could bring you these functions to st. (Not tested because I always work in byobu (plain) tmux which has the copy mode for moving around and searching.)

Summary

Alacritty is great and probably has everything you need. But if you want to save some memory, you can use st as a replacement (at the price of non-clickable URLs).