Skip to content
Advertisement

Print rectangles to terminal

I’m trying to write a text editor for Linux that looks like MS-DOS EDIT.

However, I’m stuck because I can’t figure out how to draw the thin rectangles around the editor screen and dialog box. I know the Linux dialog command can do something similar:

How can I draw rectangles like that around the screen (preferably without curses)?

Advertisement

Answer

┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃These are box-drawing characters.      ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│They live in the U+2500-U+257F range of│
│Unicode characters.                    │
└───────────────────────────────────────┘

░▒▓▛▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▜▓▒░
░▒▓▌ The shadows are block elements, ▐▓▒░
░▒▓▌ Unicode U+2580-U+259F.          ▐▓▒░
░▒▓▙▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▟▓▒░

Once upon a time, box-drawing characters and block elements and were common in CP-437. Modern terminals likely expect UTF-8. (They don’t work very well in web browsers… see here if the above text looks odd.)

There are also ANSI escapes to set the background color, foreground color, and other attributes of text displayed on a terminal. I can’t demonstrate it well on Stack Overflow, though.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement