Skip to content

Instantly share code, notes, and snippets.

@dsample
Last active November 8, 2024 09:08
Show Gist options
  • Save dsample/79a97f38bf956f37a0f99ace9df367b9 to your computer and use it in GitHub Desktop.
Save dsample/79a97f38bf956f37a0f99ace9df367b9 to your computer and use it in GitHub Desktop.
ASCII art diagrams

ASCI art characters for creating diagrams

Characters:

Single line

  • ASCII code 191 = ┐ ( Box drawing character single line upper right corner )
  • ASCII code 192 = β”” ( Box drawing character single line lower left corner )
  • ASCII code 193 = β”΄ ( Box drawing character single line horizontal and up )
  • ASCII code 194 = ┬ ( Box drawing character single line horizontal down )
  • ASCII code 195 = β”œ ( Box drawing character single line vertical and right )
  • ASCII code 196 = ─ ( Box drawing character single horizontal line )
  • ASCII code 197 = β”Ό ( Box drawing character single line horizontal vertical )
  • ASCII code 217 = β”˜ ( Box drawing character single line lower right corner )
  • ASCII code 218 = β”Œ ( Box drawing character single line upper left corner )
  • ASCII code 179 = β”‚ ( Box drawing character single vertical line )
  • ASCII code 180 = ─ ( Box drawing character single vertical and left line )

Double line

  • ASCII code 185 = β•£ ( Box drawing character double line vertical and left )
  • ASCII code 186 = β•‘ ( Box drawing character double vertical line )
  • ASCII code 187 = β•— ( Box drawing character double line upper right corner )
  • ASCII code 188 = ╝ ( Box drawing character double line lower right corner )
  • ASCII code 200 = β•š ( Box drawing character double line lower left corner )
  • ASCII code 201 = β•” ( Box drawing character double line upper left corner )
  • ASCII code 202 = β•© ( Box drawing character double line horizontal and up )
  • ASCII code 203 = ╦ ( Box drawing character double line horizontal down )
  • ASCII code 204 = β•  ( Box drawing character double line vertical and right )
  • ASCII code 205 = ═ ( Box drawing character double horizontal line )
  • ASCII code 206 = ╬ ( Box drawing character double line horizontal vertical )

Shading

  • ASCII code 176 = β–‘ ( Graphic character, low density dotted )
  • ASCII code 177 = β–’ ( Graphic character, medium density dotted )
  • ASCII code 178 = β–“ ( Graphic character, high density dotted )
  • ASCII code 219 = β–ˆ ( Block, graphic character )
  • ASCII code 220 = β–„ ( Bottom half block )
  • ASCII code 223 = β–€ ( Top half block )
  • ASCII code 254 = β–  ( black square )
β”Œβ”€β”€β”€β”
β”‚   β”‚
β””β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”  β”Œβ”€β”€β”€β”
β”‚   β”œβ”€β”€β”€   β”‚
β””β”€β”€β”€β”˜  β””β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”
β”‚   β”‚
β””β”€β”¬β”€β”˜
  β”‚
β”Œβ”€β”΄β”€β”
β”‚   β”‚
β””β”€β”€β”€β”˜

@dsample
Copy link
Author

dsample commented Mar 8, 2023

You should add this ─

@Lop010, Isn't that the last item in the 'Single Line' section?

ASCII code 180 = ─ ( Box drawing character single vertical and left line )

@tuanchauict
Copy link

tuanchauict commented Jun 4, 2023

Hi,
If you're looking for a tool for drawing with ASCII, MonoSketch is a good option. It's free and Open Source.
The source code is at https://github.com/tuanchauict/MonoSketch

@Jamesm46
Copy link

Jamesm46 commented Jul 8, 2024

@dsample I am using c++ (g++) on an Ubuntu 24.04 server (accessed via Terminus SSH terminal on my iMac M1) and I am getting some unexpected results trying to draw a box using the above codes. For example when using ASCII code 192 instead of getting "Box drawing character single line lower left corner" I am getting a white hexagon with a question mark in it. What am I doing wrong?

@kareiku
Copy link

kareiku commented Jul 9, 2024

Found this while trying to avoid this problem in ASCII art drawing.
From my experience, the "?" hexagon appears when trying to use the extended part of ASCII. That is, trying to make use of the most significant bit of a char type.
I have yet to test it, but I thought maybe unsigned char or wider char types (like char16_t) may work, if you wanna try it.

@Jamesm46
Copy link

Jamesm46 commented Jul 9, 2024

@kareiku Thank you for your suggestion, I have now tried what you suggested and using unsigned char still gave me a white hexagon with a question mark in it and using char16_t just gave me the numeric ASCII code (196). I just wonder if it might be something to do with the SSH terminal emulator I am using????????

@Jamesm46
Copy link

Jamesm46 commented Jul 9, 2024

@kareiku NOPE, I tried it on the console and got the same results. I have even gone back to plain C and used printf instead of cout and still got the same results. So I am out of ideas.

@Jamesm46
Copy link

Jamesm46 commented Jul 9, 2024

@kareiku Spent all day researching this and in the end, I used Unicode box drawing codes and I achieved what I wanted. I now have a headache and I am going for a lie-down. πŸ€•πŸ˜΄

@kareiku
Copy link

kareiku commented Jul 10, 2024

@Jamesm46 So sorry my suggestions weren't useful at all. I thought characters with values 128 to 255 were from the "extended ASCII", but it seems I got that concept wrong. At least you got a solution.
I've just been researching and testing it a bit on Windows and on one of these compiler websites that run on Linux (bc I don't have my Linux computer available rn) and I concluded that Windows has all of them char, unsigned char, wchar_t and char16_t working with values between 128 and 255, buuuut other OS doesn't. So it doesn't seem reliable to me to use values over 128 on char-like types.
Anyway, how do those Unicode box drawing work? Because, if I'm not mistaken, they do use an encoding different than UTF-8, so how does it happen to work to you?

@Jamesm46
Copy link

@kareiku I do not know the answers to your questions. I learnt coding at university 40 years ago, and my first Job was coding in Kernngam and Richie C long before C++, and I have not done any coding since. I am retired now and have started coding again to give myself something to do. I have spent most of the last 40 years building and managing Linux systems along with mainly Apple computers, though some Windows.
I have used ASCII codes 128 upwards to draw boxes but that was 40 years ago and things have obviously changed since then. I am not very familiar with Unicode and how it works, but I found a website that showed how to use it from Linux using XTerm terminal emulation and it has worked for me. I don't know why!! πŸ€”πŸ€”

@TheBigRoomXXL
Copy link

TheBigRoomXXL commented Jul 13, 2024

@dsample you might want to add this :

Join single and double line

  • ASCII code 181 = β•‘ ( Box drawings vertical single and left double)
  • ASCII code 182 = β•’ ( Box drawings vertical double and left single)
  • ASCII code 183 = β•– ( Box drawings down double and left single)
  • ASCII code 184 = β•• (Box drawings down single and left double)
  • ASCII code 198 = β•ž (Box drawings vertical single and right double)
  • ASCII code 199 = β•Ÿ (Box drawings vertical double and right single)
  • ASCII code 207 = ╧ (Box drawings up single and horizontal double)
  • ASCII code 208 = ╨ (Box drawings up double and horizontal single)
  • ASCII code 209 = β•€ (Box drawings down single and horizontal double)
  • ASCII code 210 = β•₯ (Box drawings down double and horizontal single)
  • ASCII code 211 = β•™ (Box drawings up double and right single)
  • ASCII code 212 = β•˜ ( Box drawings up single and right double)
  • ASCII code 213 = β•’ (Box drawings down single and right double)
  • ASCII code 214 = β•“ (Box drawings down double and right single)
  • ASCII code 215 = β•« (Box drawings vertical double and horizontal single)
  • ASCII code 216 = β•ͺ (Box drawings vertical single and horizontal double)

Shading

  • ASCII code 221 = β–Œ ( Left half block )
  • ASCII code 223 = ▐ ( Right half block )

Thank you for the gist, it saved me some time.

@Jamesm46
Copy link

@dsample you have proved that it is possible to use extended ASCII codes to produce the box drawing characters by responding to this gist, but how have you entered the characters?

@kareiku
Copy link

kareiku commented Jul 13, 2024

@dsample

XTerm terminal

Ohh so XTerm it was. IIRC, I used that one last year when I was exploring a Linux distro, and I think it got UTF-16, so it makes sense it'd work.
For context, I started university not so long ago and I hadn't really used any Linux distro as deeply as I'm doing now, that's why I'm talking about recent things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment