terminalterminal-emulator

ANSI Terminal layering characters one on top of another


Is it possible within the context of an ANSI Terminal (or an emulator, it can be of any flavor) to draw two characters over one-another? Or, at least, is there a way to print a character and a bar on top of it (like underline, with line up)?


Solution

    1. It is impossible to draw characters one over another in terminal. It is simply against the basic principle of the terminal where each cell contains 1 character.

    2. If your terminal supports Unicode, there are special Unicode characters called combining characters, one of which is overline. Its code is U+0305. So, using this, you can draw an overline on another character.

    Here is a sample C code that does it

     #include <stdio.h>
     #include <wchar.h>
     #include <locale.h>
     int main() {
         setlocale(LC_CTYPE, "");
         for (wchar_t ch = 'a'; ch <= 'z'; ++ch) {
             wprintf(L"%lc\u0305 ", ch);
        }
     }
    

    should yield something like that

    a̅ b̅ c̅ d̅ e̅ f̅ g̅ h̅ i̅ j̅ k̅ l̅ m̅ n̅ o̅ p̅ q̅ r̅ s̅ t̅ u̅ v̅ w̅ x̅ y̅ z̅

    Thats about as close as it gets to what you want.