LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-22-2017, 11:09 AM   #1
pedropt
Member
 
Registered: Aug 2014
Distribution: Devuan
Posts: 113

Rep: Reputation: Disabled
Update screen without blinking , multiple variables , bash


Does anyone have an idea how to update screen with multiples variables without having to clear the screen , and avoid blink refresh of it ?

a quick example using tput :

(tput goes line by line and deletes its content , however , it makes the screen blink)
Code:
#!/bin/bash
var1="text1"
var2="text2"
var3="test3"
while :; do
    echo "-------------------------"
    echo "|       Variables       |"
    echo "-------------------------"                     
    echo "$var1"
    echo "$var2"
    echo "$var3"
    sleep 1
    tput cuu1 
    tput el 
    tput cuu1
    tput el
    tput cuu1
    tput el
    tput cuu1 
    tput el 
    tput cuu1
    tput el
    tput cuu1
    tput el
done
Example 2 : with clear

Code:
#!/bin/bash
var1="text1"
var2="text2"
var3="test3"
while :; do
    echo "-------------------------"
    echo "|       Variables       |"
    echo "-------------------------"                     
    echo "$var1"
    echo "$var2"
    echo "$var3"
    sleep 1
    clear
  done
Is there another way to do this example without blinking the screen when new variable data have to be replaced ?

Last edited by pedropt; 12-29-2017 at 03:13 AM.
 
Old 12-22-2017, 11:17 AM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 5,673

Rep: Reputation: 501Reputation: 501Reputation: 501Reputation: 501Reputation: 501Reputation: 501
Maybe use tput cup to position the cursor where you want to update screen?
 
1 members found this post helpful.
Old 12-22-2017, 11:23 AM   #3
GazL
Senior Member
 
Registered: May 2008
Posts: 4,560
Blog Entries: 9

Rep: Reputation: 2055Reputation: 2055Reputation: 2055Reputation: 2055Reputation: 2055Reputation: 2055Reputation: 2055Reputation: 2055Reputation: 2055Reputation: 2055Reputation: 2055
And you may also want to tput civis so that you don't see the cursor movement. Just remember to re-enable visibility before your script exits.
 
Old 12-23-2017, 10:40 AM   #4
pedropt
Member
 
Registered: Aug 2014
Distribution: Devuan
Posts: 113

Original Poster
Rep: Reputation: Disabled
i found a better way to do the job , which is not deleting the line with tput but moving the cursor to the first line and let it write over the current text .

Code:
#!/bin/bash
var1="text1"
var2="text2"
var3="test3"
echo "-------------------------"
echo "|       Variables       |"
echo "-------------------------"   
while :; do               
    echo "$var1"
    echo "$var2"
    echo "$var3"
    sleep 1
    tput civis
    tput cuu1 
    tput cuu1
    tput cuu1

done
Can someone help me to get CTRL+Z interrupt from keyboard with trap , so i can reactivate the cursor again ?

Last edited by pedropt; 12-23-2017 at 10:42 AM.
 
Old 12-23-2017, 12:32 PM   #5
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 5,673

Rep: Reputation: 501Reputation: 501Reputation: 501Reputation: 501Reputation: 501Reputation: 501
Code:
cursorVisible() {
    tput cnorm
}

trap cursorVisible SIGINT
 
Old 12-24-2017, 12:49 PM   #6
pedropt
Member
 
Registered: Aug 2014
Distribution: Devuan
Posts: 113

Original Poster
Rep: Reputation: Disabled
thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Black screen, blinking cursor, 'asking for cache data failed';after Ubuntu update nutoubuntu Linux - Newbie 5 01-18-2014 02:50 AM
[SOLVED] Multiple Variables from a BASH Command zer0signal Programming 4 11-11-2012 12:34 PM
[SOLVED] replace multiple variables in file? bash nuser Programming 15 10-21-2012 02:02 PM
How do I create multiple variables from a list in Bash? Passions Programming 12 05-23-2009 06:23 PM
bash: random creation of multiple variables vicious1 Programming 3 04-23-2007 04:34 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration