Featured post
unix - Drawing tables in terminal using ANSI box characters -
i'm trying print table that's more pleasant eye pure text representation of it. want convert this:
+-----+--------+ | age | weight | +-----+--------+ | 10 | 100 | | 80 | 500 | +-----+--------+
to this:
┌─────┬────────┐ | age | weight | ├─────┼────────┤ │ 10 │ 100 │ │ 80 │ 500 │ └─────┴────────┘
here screenshot of see in terminal:
notice gaps between rows. problem not connecting while other unix tools use ansi printing fine in terminal. example, tree, if run tree -a
in terminal `i this:
notice how vertical lines connected together. it's funny because when copy , paste output of tree text editor , run script this:
obviously i'm missing printing ansi chars in terminal , couldn't find googling it. can shed light on topic?
i guess should answer own question. after little research , of friend , boss ,linus, found need force terminal go graphical mode first, print special characters , return text mode. ascii code switching graphical mode 14 , 15 return text mode. here code in ruby:
printf("%c\n", 14) printf("%c ", 0x6a) # ┘ printf("%c ", 0x6b) # ┐ printf("%c ", 0x6c) # ┌ printf("%c ", 0x6d) # └ printf("%c ", 0x6e) # ┼ printf("%c ", 0x71) # ─ printf("%c ", 0x74) # ├ printf("%c ", 0x75) # ┤ printf("%c ", 0x76) # ┴ printf("%c ", 0x77) # ┬ printf("%c\n", 0x78) # │ = sprintf("%c", 0x6c) + # ┌ sprintf("%c", 0x71) + # ─ sprintf("%c", 0x71) + # ─ sprintf("%c", 0x71) + # ─ sprintf("%c", 0x71) + # ─ sprintf("%c", 0x71) + # ─ sprintf("%c", 0x71) + # ─ sprintf("%c\n", 0x6b) + # ┐ sprintf("%c", 0x78) + # │ #print(" ") " " + sprintf("%c\n", 0x78) + # │ sprintf("%c", 0x6d) + # └ sprintf("%c", 0x71) + # ─ sprintf("%c", 0x71) + # ─ sprintf("%c", 0x71) + # ─ sprintf("%c", 0x71) + # ─ sprintf("%c", 0x71) + # ─ sprintf("%c", 0x71) + # ─ sprintf("%c", 0x6a) # ┘ puts printf("%c\n", 15)
- Get link
- X
- Other Apps
Comments
Post a Comment