I am writing a Python script to print out displayable user interface. The problem is every Linux user would have their own unique terminal size. This will cause the hard-coded user interface to go out of format.
(If there is a lot of example below, the terminal looks Crazy!!!).
Example, in the script. I have print out:
print "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
Format should goes well in my terminal: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
When the terminal is smaller, the print out format will run out. Format become: ++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++
So I am thinking:
I would strongly prefer recommendation in Python
I'd highly suggest using something like the Python Standard Library's curses
module to do this.
Don't reinvent the wheel - using an existing library will both help you avoid corner cases and also save you time. Plus, the curses interface is a familiar one to *nix users, which will make them like you more.
As Amber suggested, you should use a library like curses
.
Still, you could get the width of the terminal using something like this:
import subprocess
int(subprocess.Popen(['tput', 'cols'], stdout=subprocess.PIPE).stdout.read())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With