Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Licence CC BY-NC-ND, Thierry Parmentelat

Unicode comes with a few characters that can be used to draw squares or rectangles on the terminal

See e.g. this page for a list

Box-drawing character

NOTE these examples may look a little awkward on the notebook, but will look fine when run on a terminal, provided that it uses a fixed-width font, something that any decent terminal does

a first example

wide box
┏━┓
┃ ┃
┗━┛

for creating this example, all I had to do was to find the codepoint for each of the characters that I need, and insert them in a Python string using the ‘\unnnn’ notation, where nnnn is the 4-digit hexadecimal codepoint.

'┏'

adding color

optionnally, like we’ve seen for the evaluation, we can draw color on the terminal with the colorama library; note that it is useful mostly for Windows terminals (as other devices has standard ways to do color).

'hello \x1b[31mto the\x1b[0m world'

well here again, the output is awkward on the notebook, never mind...

putting it together

thin box
┌─┐
│ │
└─┘
wide connectable box
╋━┓
┃ ┣
┗━┛
┏━┓
┃ ┃
┗━┛
┏━┓
┃ ┃
┗━┛
╔╦╗
╠╬╣
╚╩╝
╔╦╗
╠╬╣
╚╩╝

well, you get the picture..

assignment

v0

We want to be able to write sentences like this

┏━━━━━━┓
┃      ┃
┃      ┃
┗━━━━━━┛

v1

or even better: add style

┌──┐
│  │
└──┘

and then color

┌────────┐
│        │
│        │
└────────┘

v2

or better still

┌──┐
│  │
└──┘
┌────────┐
│        │
│        │
└────────┘

assignment - if you’re done

a few suggestions about how to improve