Copy Link
Add to Bookmark
Report

NULL mag Issue 06 21 Embed ansi to Python

eZine's profile picture
Published in 
null magazine
 · 3 years ago

  




lets see a way to embed ansi screens/logos/menus to a python script,
without the need to attach external files to a package. all of our
ansi stuff will be in the file of the script. to do so, we have first
to convert the ansi images/files to base64 strings.

in linux is easy as this: base64 <filename>
the output of the command is what we want... almost... as you see below
we have to put all this big string between quotes and add the plus sign
at the end. the quickest way, is with this command:

base64 <ansifile> | sed "s/^/\'/" | sed "s/$/\'+/"

just copy/paste the output into your script, add the libraries we need,
like base64 and os, which are standard and you are ready to go...

just see the example commands at the end of this script example.

--- copy here ----------------------------------------------------------------
#!/usr/bin/python3
import base64
import os
screen = base64.b64decode( \
'ChtbNTZDG1szN23fChtbMTszMG0gICAgICAgICAgICAgICAbWzQxQxtbMDszNzs0MG0gIBtbMzZt'+
'39wbWzE7MzBt3BtbMDszNzs0MG0gICAgIBtbM0MbWzMzbSAbWzBtChtbMTszMG0gICAgICAgICAg'+
'ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgG1swOzM3OzQwbSAbWzM2bd/cG1sxOzMw'+
'bdwbWzA7MzY7NDBtIBtbMTszMG0gICAgICAgICAgG1swOzM3OzQwbSAbWzM2bdvb39zb3BtbMzNt'+
'ICDf3BtbMzA7NDNtICAgIGUbWzMzOzQwbW1hZxtbMG0KIBtbMzZtICAg3Nzc3Nzc3NwbWzE7MzBt'+
'3BtbMDszNzs0MG3fG1szQ9wgG1s1QyAbWzE7MzBt3BtbMDszNzs0MG0gIBtbN0MbWzE7MzBt3xtb'+
'MDszNzs0MG3cG1szQxtbMzZtsLAbWzM3bSAgIBtbMzZt29uystwbWzM3bSAgG1s0QxtbMzZt3xtb'+
'MzdtICAbWzM2bdvb29vbG1szN20gICAbWzMzbSAgG1szN20gG1szM22wsLCwsLCwsBtbMG0KG1s0'+
'QxtbMzZt39/f39+ysrLb29vbG1sxOzMwOzQ2bd8bWzA7MzY7NDBt3NwbWzE7MzBt3BtbMDsz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gICAgICDb29vb29vf'+
'3N8bWzlD3xtbNUMgICDc3yAgICAgIBtbNUPf39/cIN8bWzFtsLCwG1swOzM3OzQwbSAgINzfG1s0'+
'Q9wgIN8gIN/f39/f3xtbMTdDICAbWzE3Q98bWzE2Q9/c3Nzc3Nzf3yAKG1s1NUMbWzM2bWkgcyBz'+
'IHUgZSAgIBtbMUMbWzMwOzQ2bd/cIDAwNiDf3BtbMG0KG1s3MkMbWzM2bbCwsLCwsLAbWzBtCg==')

# for utf8 terminals use this:
print(''.join(str(screen,"cp437")))
# for cp437 terminals use this:
#os.write(1, screen)
--- stop copying here --------------------------------------------------------
--- give credits here --------------------------------------------------------
i had some trouble displaying the exact ansi, in a non utf8 terminal,
so i had to use the os.write function for it. you can make your script
detect the terminal encoding and use the proper function, according
that.





← previous
next →
loading
sending ...
New to Neperos ? Sign Up for free
download Neperos App from Google Play
install Neperos as PWA

Let's discover also

Recent Articles

Recent Comments

Neperos cookies
This website uses cookies to store your preferences and improve the service. Cookies authorization will allow me and / or my partners to process personal data such as browsing behaviour.

By pressing OK you agree to the Terms of Service and acknowledge the Privacy Policy

By pressing REJECT you will be able to continue to use Neperos (like read articles or write comments) but some important cookies will not be set. This may affect certain features and functions of the platform.
OK
REJECT