The only place i use
tput is as a fallback if
$COLUMNS is not set, as this is required to print the output according to the currently available columns/width.
Allthough i've seen several scripts using
tput as they're core output, i was used (from batch files) to use
echo as output.
Quickly after i joined this forum, i've figured
echo might not be available on all systems, and changed to
printf instead.
An executable for each and every task, yeno...
The core/key components are:
- tui-printf (absolute core!, this is even the base for: )
- tui-echo
- tui-header (the blue one)
- tui-title (the white one)
If you look at the screenshot, the 'lower' output also uses:
tui-value-get, which only returns either all variable names (all strings/lines not starting with
# and having a string like
VARNAME= without the
=) or just the single value of the provided varname of a file. (eg:
tui-value-get -l CONFFILE /
value=$(tui-value-get CONFFILE VARNAME)).
So this is called 8 times in the screenshot above... 1 time to list all the VARIABLES, and 1 time per variable (7) to be read/displayed.
So to print those 20 lines, i'm calling/using:
- 1 x tui-header
- 4 x tui-title
- 15 x tui-echo
- 8 x tui-value-get (in a for-loop)
and it 'only' needs 0.433 seconds, that is around 0.021 secs per line (0.015 respectivly per command) on average, to my feeling this is fast already, at least considering that 28 commands were executed (of which some rely on sed/grep/awk combinations) and all but tui-value-get rely on
tui-printf.
And keep in mind, its always printing a full line - using all available width of the terminal, not only a few chars / words per line.
Some parts of the first 'performance-rewrite' also caused several vars to be placed in
$env beeing set using
/etc/profile.d/tui.sh. Also,
tui-printf was using a custom function
'printx' which had to be sourced first, changing that completly to
tui-printf was a speed increase of like 0.250 secs.
Initialy, like 2-2.5 years ago, i've had a folder containing several scripts providing functions.
But back then TUI was part of another script-package, completly 'involved', not seperate at all.
But since TUI is ment as an 'interface framework' i wanted the users/scripters to simply call the function they want, instead of sourcing just 'everything'.
So by now, the scripts only source files upon real need, as in username/email/prefered licence/licence url are only read/sourced by
tui-new-script.
Well, i'm learning python now anyway, for future projects at least.
This thread is merly to figure if TUI has to be rewritten for the 5th or 6th time
Code examples:
tui (to config the vars)
tui-printf (absolute core fuction)
tui-value-get
So, writing this in python, would decrease the time used (those 0.433s from the screenshot) down to 0.090 or even as less as 0.043 for all those 20 lines?
(friend promised 500-1000% speed gain, which i hardly can imagine)
And if i may ask along, what do you think of this TUI framework?
EDIT:
I keep learning python, maybe i understand your arguments better later on.