Visit Our UNIX and Linux User Community

Tput cup, print on current line?

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Tput cup, print on current line?
# 1  
Old 05-16-2015
Tput cup, print on current line?


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 ----------

I was hopeing to avoid 'short lines' if any escaped chars (such as colors... Smilie ) are/were beeing passed/printed.
This User Gave Thanks to sea For This Post:
# 2  
Old 05-16-2015
You might want to look into (mostly linux, I'm afraid)man console_codes, esp
ESC [ r DECSTBM Set scrolling region; parameters are top and bottom row.

ESC [ 6 n
Cursor position report (CPR): Answer is ESC [ y ; x R, where x,y is the cursor location.
This User Gave Thanks to RudiC For This Post:
# 3  
Old 05-16-2015
That is it, thanks alot!
$ echo -e "\033[6Gh"

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

Last edited by sea; 05-16-2015 at 04:21 PM..
# 4  
Old 05-17-2015
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.
# 5  
Old 05-17-2015
Hehe, its just, tui-echo never ever used "echo", its always been printf.
tput, i only use/d to get columns/width Smilie

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. Smilie

Have a nice sunday Smilie
Tput cup, print on current line?-tui-printf-rework-nobgcolorjpg
# 6  
Old 05-19-2015
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"

This User Gave Thanks to Chubler_XL For This Post:

Previous Thread | Next Thread
Test Your Knowledge in Computers #195
Difficulty: Easy
The top 2 programming languages, according to the TIOBE Index for October 2019, was Java and C.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Print out my current http connection

Good evening Need you help please I just wanna to print out my current https connection and other users http connection which the application resides, for instance i connect to the below url to login into the application: https://serverappp01:14100/portal/Portal.html# In another session... (4 Replies)
Discussion started by: alexcol
4 Replies

2. Shell Programming and Scripting

Compare between current and next line and print

Dear All I want below to compare two Consecutive line(i.e. current and next line). Based in that i need OP. Below is the IP file in that in i find "M" and if in next line i find "*" then i need both line in single line. If i dont find "*" in next line then i need to put commend "DOWN" . I am... (4 Replies)
Discussion started by: jaydeep_sadaria
4 Replies

3. Shell Programming and Scripting

Sed Comparing Parenthesized Values In Previous Line To Current Line

I am trying to delete lines in archived Apache httpd logs Each line has the pattern: <ip-address> - - <date-time> <document-request-URL> <http-response> <size-of-req'd-doc> <referring-document-URL> This pattern is shown in the example of 6 lines from the log in the code box below. These 6... (1 Reply)
Discussion started by: Proteomist
1 Replies

4. Shell Programming and Scripting

Print the current directory using perl

Hi I have this code to print the current directory using Perl use Cwd qw(abs_path); my $path = abs_path($0); print "$path\n"; But it is displaying my perl source code file along with the directory. like this C:\Perl\ But I want it only to display this... (1 Reply)
Discussion started by: srijith
1 Replies

5. UNIX for Dummies Questions & Answers

Awk to print data from current and previous line

Hi guys, I have found your forum super useful. However, right now I am stuck on a seemingly "simple" thing in AWK. I have two columns of data, the first column in Age (in million years) and the second column is Convergence Rate (in mm/yr). I am trying to process my data so I can use it to... (2 Replies)
Discussion started by: awk_noob_456
2 Replies

6. Shell Programming and Scripting

Vi Editor - How to paste the line concatenated with current line

I generally use yy to copy a line and then p to paste the line at end of current line. But is there a way to paste the copied line in concatenation with the current line with out going to next line. (3 Replies)
Discussion started by: paragkalra
3 Replies

7. Shell Programming and Scripting

How to use sed to search for string and Print previous two lines and current line

Hello, Can anybody help me to correct my sed syntax to find the string and print previous two lines and current line and next one line. i am using string as "testing" netstat -v | sed -n -e '/test/{x;2!p;g;$!N;p;D;}' -e h i am able to get the previous line current line next line but... (1 Reply)
Discussion started by: nmadhuhb
1 Replies

8. Shell Programming and Scripting

awk print the next line on the current line

Ok I have a file with hundreds of lines, four columns, space delimited, TESTB.TXT for example TESTB.TXT --- AA ZZ 12 34 BB YY 56 78 CC XX 91 23 DD VV 45 67 --- I want a new file that has 7 columns, the first four are identical, and the next 3 are the last three of the next (5 Replies)
Discussion started by: ajp7701
5 Replies

9. Shell Programming and Scripting

Print previous, current and next line using sed

Hi, how can i print the previous, current and next line using sed? current line is the matching line. The following prints all lines containing 'Failure' and also the immediate next line cat $file | sed -n -e '/Failure/{N;p;}' Now, i also want to print the previous line too. Thanks,... (8 Replies)
Discussion started by: ysrinu
8 Replies

10. UNIX for Dummies Questions & Answers

awk to print current date?

List, I want to print the first line of my text file (say "me you"), preceded by the current date/time. Something like (pseudo code): awk '{print date,$1}' I don't have a lot of awk knowledge (understatement), so forgive me if the answer is obvious... (3 Replies)
Discussion started by: philipz
3 Replies

Featured Tech Videos