Double line box_drawing characters in terminal

7,409

Solution 1

What charset do you have your terminal set to use? If you are still using ASCII, you don't have double-line box-drawing characters available to you. If you are using UTF-8, you can send out the UTF-8 character sequence for these characters. I believe printf("╢") will work if you compiler accepts UTF-8 in the source code, e.g. gcc with -finput-charset=UTF-8.

Solution 2

Some of the comments suggested ncurses as a possible solution. There are pros/cons to that:

  • ncurses is useful for drawing text while moving about the screen (either full-screen, or a full-line using filter). OP's example prints a fragment of a single line, and the discussion gave no clues whether this was a typical use, or part of something more elaborate.
  • ncurses has a repertoire of symbols for commonly-used lines. The particular example shown (a mixed single-width and double-width symbol) is not in that list, i.e., Unicode Character 'BOX DRAWINGS VERTICAL DOUBLE AND LEFT SINGLE' (U+2562)

enter image description here

ncurses accepts UTF-8 strings, and keeps track of the current position, but attaches no particular significance to box-drawing symbols not in its repertoire. Since 2009 (after the 5.7 release), it has symbols for double- and thick-linedrawing, but those are far from the full set of Unicode box-drawing graphics since they are not mixed. Here are some screenshots from the ncurses test-program showing the predefined symbols that ncurses supports:

normal line-drawing

double line-drawing

thick line-drawing

Share:
7,409
Gilles 'SO- stop being evil'
Author by

Gilles 'SO- stop being evil'

Updated on September 18, 2022

Comments

  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' over 1 year

    This piece of code in wikipedia:

    $ char=( 6a 6b 6c 6d 6e 71 74 75 76 77 78 )
    $ for i in ${char[*]}; do printf "0x$i \x$i \e(0\x$i\e(B\n"; done
    

    includes one-line box-drawing characters. Are there double-line box-drawing characters in terminal?

    For example how can I print the character "╢".

    I'll use them in a C++ program like this:

    #include <stdio.h>
    
    int main()
    {
        printf("\e(0\x6a\e(B "); // 188
        printf("\e(0\x6b\e(B "); // 187
        printf("\e(0\x6c\e(B "); // 201
        printf("\e(0\x6d\e(B "); // 200
        printf("\e(0\x6e\e(B "); // 206
        printf("\e(0\x71\e(B "); // 205
        printf("\e(0\x74\e(B "); // 204
        printf("\e(0\x75\e(B "); // 185
        printf("\e(0\x76\e(B "); // 202
        printf("\e(0\x77\e(B "); // 203
        printf("\e(0\x78\e(B "); // 186
    }
    
    • Drav Sloan
      Drav Sloan over 10 years
      You might be better off looking at something like ncurses, which provides boxes, windows and other features for terminal "menu" systems. tldp.org/HOWTO/NCURSES-Programming-HOWTO (this options is also more portable)
    • Admin
      Admin over 10 years
      I need them in normal terminal. Because ncurses is not open source and is not contained normally with compilers. It's not convenient to explain to people they must first add or install ncurses then they'll be able to compile run the program.
    • Drav Sloan
      Drav Sloan over 10 years
      ncurses is opensource, it is maintained by GNU. I'd be suprised to find any "compiler" that provides that kind of functionality. I don't see the problem in installing a library to provide functionality that is required (especially as it's as simple as installing the appropriate package on most Linux distribtions apt-get install ncurses-dev on Debian as an example). Hard coding unicode characters into print statements is horribly unportable.
    • Admin
      Admin over 10 years
  • Admin
    Admin over 10 years
    printf("╢") works. But printing it with a string like \e(0\x78\e(B is better if there's any.
  • user1579506
    user1579506 over 10 years
    By "cannot be printed" do you mean when you try to print it you see a string of incorrect characters, or do you see a single box with hex digits inside it? Also, what is LANG set to (echo $LANG)?
  • Admin
    Admin over 10 years
    I rememeber unicode was printed as ???? but now it works. probably some option was not enabled. or I was using unicode literal string with L and wcout. It's strange.
  • Admin
    Admin over 10 years
    the language is: en_US.UTF-8
  • Admin
    Admin over 10 years