Code Adventures: fancypants, a Command-Line Text Conversion Utility

๐•‹๐•™๐•š๐•ค ๐•จ๐•–๐•š๐•ฃ๐•• ๐•ฅ๐•–๐•ฉ๐•ฅ ๐•จ๐•’๐•ค ๐•”๐• ๐•Ÿ๐•ค๐•ฅ๐•ฃ๐•ฆ๐•”๐•ฅ๐•–๐•• ๐•จ๐•š๐•ฅ๐•™ ๐•ฅ๐•™๐•– ๐•ฆ๐•ฅ๐•š๐•๐•š๐•ฅ๐•ช ๐•ž๐•–๐•Ÿ๐•ฅ๐•š๐• ๐•Ÿ๐•–๐•• ๐•š๐•Ÿ ๐•ฅ๐•™๐•– ๐•ฅ๐•š๐•ฅ๐•๐•–. ๐“ข๐“ธ ๐”€๐“ช๐“ผ ๐“ฝ๐“ฑ๐“ฒ๐“ผ ๐“ฝ๐“ฎ๐”๐“ฝ ๐“ฑ๐“ฎ๐“ป๐“ฎ. ๐—”๐—ป๐—ฑ ๐—ฎ๐—น๐˜€๐—ผ ๐˜๐—ต๐—ถ๐˜€. ๐•ฌ๐–‰๐–‰๐–Ž๐–™๐–Ž๐–”๐–“๐–†๐–‘๐–ž, ๐–™๐–๐–Ž๐–˜.

Can you read those? There’s a good chance you can! If you can’t (like if they all show up as hollow boxes) it’s because the font you’re reading this post in doesn’t support those kinds of characters, which are from the math symbols section of the Unicode character set.

It’s a command-line version of a web Unicode text converter, of the sort found at the other end of this link. It’s written in Python, and the source is at the end of this post. I saved it to a file named “fancypants” and put it in my home directory’s bin directory (which you’ll probably have to make first), where many Linux distributions are configured to look for things to execute if you type their names at the command prompt. (Yes, all of this assumes you’re running Linux. It’s not just for supergeeks anymore! If you’re running Windows you’ll have some adjustments to make, including figuring out how to add the script’s home to your path. It should work on Macs, although I don’t know if it’ll look in your home’s bin either.)

Oh, you will have to run a chmod +x fancypants on it. And the script as written assumes Python is at /usr/bin/python, where most distros will put it.

The script expects to be executed in the form:

fancypants [style] [text to convert]

The text should probably be in quotes if there’s any spaces in it, as should the style just in case. So to produce the first text mentioned at the start of the post, I entered:

fancypants "=" "This weird text was constructed with the utility mentioned in the title."

Usable style specifiers are “=” for double-stroke, “/” for script, “!” for a boldface kind of thing, “f” for the medieval script-looking fractur, and a few others that you can pretty easily see in the source code below. In fact each specifier has some synonyms if the single-character versions are too obscure for you to remember. And hey, if you don’t like the names I gave them you can use your own! The moment you paste it into a text file, this all becomes yours to do with as you please. Think of it as the blog version of a type-in program from an 80s computer magazine.

As a bonus, the names “r”, “rot” or “rot13” will perform a ROT13 code on the letters, useful for encoding spoiler text that readers can decode at ROT13.com. There are utilities that you can use to send the generated text directly to the clipboard, for pasting wherever you want, but since those differ if you’re using X.org or Wayland for your display manager (or, sure, Windows or Mac) I’ll leave those for you to figure out.

And if you can’t read the characters above, then I’m sorry that you’re missing out on the fun. It’s all pretty whimsical really, it’s not some huge thing that you’re missing. Come back tomorrow, I’m sure we’ll have a post about Mario or somesuch.

#!/usr/bin/python
import sys

base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()-_=+[]{};':\",./<>?~"
equals = "๐”ธ๐”นโ„‚๐”ป๐”ผ๐”ฝ๐”พโ„๐•€๐•๐•‚๐•ƒ๐•„โ„•๐•†โ„™โ„šโ„๐•Š๐•‹๐•Œ๐•๐•Ž๐•๐•โ„ค๐•’๐•“๐•”๐••๐•–๐•—๐•˜๐•™๐•š๐•›๐•œ๐•๐•ž๐•Ÿ๐• ๐•ก๐•ข๐•ฃ๐•ค๐•ฅ๐•ฆ๐•ง๐•จ๐•ฉ๐•ช๐•ซ๐Ÿ™๐Ÿš๐Ÿ›๐Ÿœ๐Ÿ๐Ÿž๐ŸŸ๐Ÿ ๐Ÿก๐Ÿ˜!@#$%^&*()-_=+[]{};':\",./<>?~"
script = "๐“๐“‘๐“’๐““๐“”๐“•๐“–๐“—๐“˜๐“™๐“š๐“›๐“œ๐“๐“ž๐“Ÿ๐“ ๐“ก๐“ข๐“ฃ๐“ค๐“ฅ๐“ฆ๐“ง๐“จ๐“ฉ๐“ช๐“ซ๐“ฌ๐“ญ๐“ฎ๐“ฏ๐“ฐ๐“ฑ๐“ฒ๐“ณ๐“ด๐“ต๐“ถ๐“ท๐“ธ๐“น๐“บ๐“ป๐“ผ๐“ฝ๐“พ๐“ฟ๐”€๐”๐”‚๐”ƒ1234567890!@#$%^&*()-_=+[]{};':\",./<>?~"
bold = "๐€๐๐‚๐ƒ๐„๐…๐†๐‡๐ˆ๐‰๐Š๐‹๐Œ๐๐Ž๐๐๐‘๐’๐“๐”๐•๐–๐—๐˜๐™๐š๐›๐œ๐๐ž๐Ÿ๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐Ÿ๐Ÿ๐Ÿ‘๐Ÿ’๐Ÿ“๐Ÿ”๐Ÿ•๐Ÿ–๐Ÿ—๐ŸŽ!@#$%^&*()-_=+[]{};':\",./<>?~"
bolditalic = "๐‘จ๐‘ฉ๐‘ช๐‘ซ๐‘ฌ๐‘ญ๐‘ฎ๐‘ฏ๐‘ฐ๐‘ฑ๐‘ฒ๐‘ณ๐‘ด๐‘ต๐‘ถ๐‘ท๐‘ธ๐‘น๐‘บ๐‘ป๐‘ผ๐‘ฝ๐‘พ๐‘ฟ๐’€๐’๐’‚๐’ƒ๐’„๐’…๐’†๐’‡๐’ˆ๐’‰๐’Š๐’‹๐’Œ๐’๐’Ž๐’๐’๐’‘๐’’๐’“๐’”๐’•๐’–๐’—๐’˜๐’™๐’š๐’›1234567890!@#$%^&*()-_=+[]{};':\",./<>?~"
monospace = "๐™ฐ๐™ฑ๐™ฒ๐™ณ๐™ด๐™ต๐™ถ๐™ท๐™ธ๐™น๐™บ๐™ป๐™ผ๐™ฝ๐™พ๐™ฟ๐š€๐š๐š‚๐šƒ๐š„๐š…๐š†๐š‡๐šˆ๐š‰๐šŠ๐š‹๐šŒ๐š๐šŽ๐š๐š๐š‘๐š’๐š“๐š”๐š•๐š–๐š—๐š˜๐š™๐šš๐š›๐šœ๐š๐šž๐šŸ๐š ๐šก๐šข๐šฃ๐Ÿท๐Ÿธ๐Ÿน๐Ÿบ๐Ÿป๐Ÿผ๐Ÿฝ๐Ÿพ๐Ÿฟ๐Ÿถ!@#$%^&*()-_=+[]{};':\",./<>?~"
block = "๐—”๐—•๐—–๐——๐—˜๐—™๐—š๐—›๐—œ๐—๐—ž๐—Ÿ๐— ๐—ก๐—ข๐—ฃ๐—ค๐—ฅ๐—ฆ๐—ง๐—จ๐—ฉ๐—ช๐—ซ๐—ฌ๐—ญ๐—ฎ๐—ฏ๐—ฐ๐—ฑ๐—ฒ๐—ณ๐—ด๐—ต๐—ถ๐—ท๐—ธ๐—น๐—บ๐—ป๐—ผ๐—ฝ๐—พ๐—ฟ๐˜€๐˜๐˜‚๐˜ƒ๐˜„๐˜…๐˜†๐˜‡๐Ÿญ๐Ÿฎ๐Ÿฏ๐Ÿฐ๐Ÿฑ๐Ÿฒ๐Ÿณ๐Ÿด๐Ÿต๐Ÿฌ!@#$%^&*()-_=+[]{};':\",./<>?~"
fraktur = "๐•ฌ๐•ญ๐•ฎ๐•ฏ๐•ฐ๐•ฑ๐•ฒ๐•ณ๐•ด๐•ต๐•ถ๐•ท๐•ธ๐•น๐•บ๐•ป๐•ผ๐•ฝ๐•พ๐•ฟ๐–€๐–๐–‚๐–ƒ๐–„๐–…๐–†๐–‡๐–ˆ๐–‰๐–Š๐–‹๐–Œ๐–๐–Ž๐–๐–๐–‘๐–’๐–“๐–”๐–•๐––๐–—๐–˜๐–™๐–š๐–›๐–œ๐–๐–ž๐–Ÿ1234567890!@#$%^&*()-_=+[]{};':\",./<>?~"
rot = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm1234567890!@#$%^&*()-_=+[]{};':\",./<>?~"
tilde = len(equals)-1

def convert(convertchar, intext):
outlist = []
match convertchar:
case "=" | "equal" | "equals":
clist = equals
case "/" | "slant" | "script":
clist = script
case "!" | "bold":
clist = bold
case "!/" | "bolditalic" | "boldital":
clist = bolditalic
case "m" | "mono" | "monospace":
clist = monospace
case "b" | "block" | "mathbold":
clist = block
case "f" | "fraktur":
clist = fraktur
case "r" | "rot" | "rot13":
clist = rot
case _:
raise ValueError("Unknown charset " + convertchar)
return intext
for char in intext:
try:
index = base.index(char)
except:
outlist.append(char)
continue
outchr = clist[index]
if outchr != "~":
outlist.append(outchr)
else:
outlist.append(base[index])
return "".join(outlist)

if __name__ == "__main__":
convertchar = sys.argv[1]
intext = sys.argv[2]
print(convert(convertchar, intext))

Leave a Reply

Your email address will not be published. Required fields are marked *