2

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
}
4
  • 2
    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)
    – Drav Sloan
    Sep 7, 2013 at 16:00
  • 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.
    – user44920
    Sep 7, 2013 at 16:49
  • 3
    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.
    – Drav Sloan
    Sep 7, 2013 at 16:54
  • it is said otherwise
    – user44920
    Sep 7, 2013 at 16:59

2 Answers 2

3

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.

5
  • printf("╢") works. But printing it with a string like \e(0\x78\e(B is better if there's any.
    – user44920
    Sep 7, 2013 at 16:41
  • 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)? Sep 7, 2013 at 16:44
  • 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.
    – user44920
    Sep 7, 2013 at 16:47
  • the language is: en_US.UTF-8
    – user44920
    Sep 7, 2013 at 16:51
  • I asked why this happens in stackoverflow.com/questions/18675720/cout-or-wcout-l
    – user44920
    Sep 8, 2013 at 16:52
1

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

You must log in to answer this question.