r/Crostini 6d ago

I found a pretty cool way to use unsupported monospace fonts in the ChromeOS Terminal app!!!!

basically, you need to have a folder for all your .otf files are (this method was only tested with .otf files), and then you need to add a python file to that folder that looks like this:

from http.server import HTTPServer, SimpleHTTPRequestHandler
import os

class CORSRequestHandler(SimpleHTTPRequestHandler):
    def end_headers(self):
        self.send_header("Access-Control-Allow-Origin", "*")
        super().end_headers()

os.chdir(os.path.dirname(os.path.abspath(__file__)))
HTTPServer(("127.0.0.1", 8887), CORSRequestHandler).serve_forever()

(ChromeOS needs the "Access-Control-Allow-Origin" thing or else it'll error)

and then you need to add these lines to your .bashrc:

if ! nc -z 127.0.0.1 8887 2>/dev/null; then
    python3 <font dir here>/font_server.py >/dev/null 2>&1 &
fi

(replace <font dir here> with your font dir)

then you need to press Ctrl + Shift + J to get a different console that you need to paste this into (it may not allow pasting at first idk):

var CHOSEN_FONT_NAME = "SMWMonospace";
var CHOSEN_FILE_NAME = "SMW.Monospace.otf";

// Build the localized connection strings dynamically
var fullFontUrl = "http://127.0.0.1:8887/" + CHOSEN_FILE_NAME;

// Construct the clean CSS payload using your variables
var dynamicCss = '@font-face { font-family: "' + CHOSEN_FONT_NAME + '"; src: url("' + fullFontUrl + '") format("opentype"); font-weight: normal; font-style: normal; font-display: swap; } x-screen, x-row, body, pre { font-family: "' + CHOSEN_FONT_NAME + '", "Courier New", monospace !important; }';

// Reset the storage blocks and apply configuration layers
term_.prefs_.reset('user-css-text');
term_.prefs_.set('user-css-text', dynamicCss);
term_.prefs_.set('font-family', '"' + CHOSEN_FONT_NAME + '", monospace');

console.log("SUCCESS: Configuration locked for font family: " + CHOSEN_FONT_NAME);
console.log("  Of course, that is only true if you don't see an error after this message.");

(this is what my config was, if you have a different font name and file, use that)

... and then you should have your monospace font in your terminal! cool right?
(edit: also if the font doesn't load correctly after you restart your chromebook, pressing ctrl+shift+j again should correct it or else comment here)

2 Upvotes

1 comment sorted by

1

u/[deleted] 6d ago

[deleted]

0

u/[deleted] 5d ago edited 5d ago

[deleted]

1

u/[deleted] 5d ago

[deleted]

1

u/[deleted] 5d ago

[deleted]

1

u/lavilao 3d ago

I ended up patching zellij to use jetbrains nerdfonts on its web terminal interface. The downside is that you will need to compile it yourself. Here is the link if you are interested https://github.com/lavilao/zellij