Tput cup, print on current line?

Heyas

I'm thinking about a new approach for my core display, basicly as it should make aligments easier.
Issue i'm currently facing, is tput cup capable of printing on the current line?

My best achievements were:

:) tui $ tput cup - 60;echo " ------ testing"                ------ testing
<... some more lines in the terminal...>
+ tui $  tput cup - 60;echo " ------ testing"

Alot better was (but still not working/acceptable):

 ~ $ tput cup $LINENO 50 ; echo another test




                                                  another test
:) ~ $ tput cup $LINENO 50 ; echo another test    another test
:) ~ $ tput cup $LINENO 50 ; echo another test    another test
 ~ $ tput cup $LINENO 50 ; echo another test     another test
+ ~ $ tput cup $LINENO 50 ; echo another test

But that is taking the line number of the bash history, not of the terminal.
However, once screwed up, the which-line-nr-alignemnt seems to be fitting... somehow...

Fill a variable with such output, and print that then, doesnt work too well either, ouput jumps to lline 0.

So basicly my question is, how to figure out on which line of the current terminal i am?
And then just print on that, using the aligment of tput?

       tput cup 0 0
            Send  the sequence to move the cursor to row 0, column 0 (the upper left corner of the screen, usually
            known as the "home" cursor position).

       tput cup 23 4
            Send the sequence to move the cursor to row 23, column 4.

To my eyes it doesnt look like such a 'task' was thought of/is supported?

Any ideas/thoughts where or what i might head for digging?
Thank you in advance

---------- Post updated at 17:54 ---------- Previous update was at 17:45 ----------

Addition:
I was hopeing to avoid 'short lines' if any escaped chars (such as colors... :stuck_out_tongue: ) are/were beeing passed/printed.

You might want to look into (mostly linux, I'm afraid) man console_codes , esp

1 Like

That is it, thanks alot!

$ echo -e "\033[6Gh"
     h

edit:
tui-echo is now ~4 times faster... from 0.013-0.020 down to 0.004-0.007 :slight_smile:

No surprise as echo is a bash builtin, whereas tput is an external command that need process creation every time it is run... I find a factor of about 40 if I compare the two.

Hehe, its just, tui-echo never ever used "echo", its always been printf.
tput, i only use/d to get columns/width :stuck_out_tongue:

What i was saying, printing a 'full' line with the escaped sequence, is still faster than printf, which calculates emptry string and prints them.

Now i only need to print empty strings for the background of the title and header, otherwise there is no 'full-color' background.
Still needs some finetuning, but general handling (align up to 3 variables, or split them according to their lenght/terminal width) is already faster, and lots easier to align.

Was almost asking for help when i had the situation of the screenshot.
A great thing is, the center strings are not more centered than previously. :slight_smile:

Have a nice sunday :smiley:

You don't need to space out line use ESC-[2K (clear line) like this:

$ printf "\e[1;35H\e[42m\e[2KCentered Text\e[0m\e[2;0H"
1 Like