/terminal-glyph-patcher

Patch your own glyphs to your terminal fonts (e.g., extra powerline separators)

Primary LanguagePython

Terminal Glyph Patcher

Patch your own glyphs to your terminal fonts (e.g., extra powerline separators).

Enjoy your original statusline in the terminal!

statusline.png

Characteristics

  • Your own SVG files (.svg) can be used to generate glyphs.
    • Preset glyphs below are also pure SVG files.
  • Generated glyphs are always half-width.
  • The position of separator glyphs can be finely adjusted.

Try it

1. Clone this repo

git clone https://github.com/s417-lama/terminal-glyph-patcher.git

2. Patch your font by using preset glyphs

python-fontforge package is required. Install instruction: Installing FontForge

cd terminal-glyph-patcher
fontforge -script terminal-glyph-patcher.py /path/to/your/font.ttf

Then install the patched font to your system, and apply it to your terminal.

3. Show statusline

./statusline_test.sh

Then statuslines like the top image should be shown.

Patch your own glyphs

For now you should modify terminal-glyph-patcher.py directly. What you should modify is symbols list in the source code. This list looks like the below.

{'unicode': 0xe0b0, 'align': 'l', 'stretch': 'xy', 'overlap': 0.05, 'path': 'svg/arrow_right.svg'     },
{'unicode': 0xe0b1, 'align': 'l', 'stretch': 'xy', 'overlap': 0.05, 'path': 'svg/arrow_right_thin.svg'},
{'unicode': 0xe0b2, 'align': 'r', 'stretch': 'xy', 'overlap': 0.01, 'path': 'svg/arrow_left.svg'      },
{'unicode': 0xe0b3, 'align': 'r', 'stretch': 'xy', 'overlap': 0.01, 'path': 'svg/arrow_left_thin.svg' },

unicode :: int

Unicode number to be register. If a glyph already exists in the font, it will be overwritten.

align :: 'l', 'r', or 'c'.

If l is set, the glyph is aligned to the left edge. If r, it is aligned to the right. If c is set, the glyph is aligned in the center.

stretch :: '', 'x', 'y', or 'xy'.

If x is set, the glyph is expanded to fill up the entire horizontal space. y is for the vertical space.

overlap :: float

Sometimes there exists a gap between glyphs. To fill it up, overlap parameter is used. The output glyph width will be Glyph width * (1 + overlap), which means the glyph will be a bit leaked from the normal bounding box. If align parameter is l, the overflow goes to the left side. If r, it goes to the right side.

path :: string

Path to your SVG file.


For example, U+E0B0 glyph should align to the left (align='l'), and it should fill up the entire glyph space (stretch='xy'). To fill up the left gap, overlap parameter is set to some value (this parameter is decided in an ad-hoc way).

Preset Glyphs

The glyphs below are included in svg/ directory by default. These glyphs are pure SVG files.

Basically it follows the layout convention of Powerline Extra Symbols (not exactly same, though).

U+E0B0 U+E0B1 U+E0B2 U+E0B3 U+E0B4 U+E0B5 U+E0B6 U+E0B7
U+E0B0 U+E0B1 U+E0B2 U+E0B3 U+E0B4 U+E0B5 U+E0B6 U+E0B7
U+E0B8 U+E0B9 U+E0BA U+E0BB U+E0BC U+E0BD U+E0BE U+E0BF
U+E0B8 U+E0B9 U+E0BA U+E0BB U+E0BC U+E0BD U+E0BE U+E0BF
U+E0C0 U+E0C1 U+E0C2 U+E0C3 U+E0C4 U+E0C5
U+E0C0 U+E0C1 U+E0C2 U+E0C3 U+E0C4 U+E0C5

Tips to adjust position

Sometimes powerline separators are misaligned because of the mismatch between fonts and terminal emulators. It depends on terminal emulators you use, the font size, the resolution of displays, and so on. So it is hard to create powerline fonts that will work well on every environment.

You can adjust some parameters (overlap in symbols list, y_scale and y_offset in terminal-glyph-patcher.py) to make it fit in your environment. If there is a horizontal gap between glyphs, try to increase overlap parameter of each glyph. If glyphs are smaller than the line height, try to increase y_scale parameter. If glyphs are vertically misaligned, try to change y_offset parameter.

Reference