LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 10-26-2013, 07:10 AM   #1
waddles
Member
 
Registered: Sep 2012
Posts: 372

Rep: Reputation: 1
Using shell script how can I move text lines up over an unchanging background


Just like it said. I need to be able to move several lines of text over an unchanging background. The rub is doing it with shell script.
I have tried several solutions with use of tput to no avail. However, I have not yet tried using tput capname and using the equivalent tput entry for the termcap equivalents. Does that work? Does anything work to do this?
 
Old 10-26-2013, 08:07 AM   #2
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,382

Rep: Reputation: Disabled
I don't know what you mean with an "unchanging background". Other than that you can use the terminfo capabilities of the treminfo database. I would write a few simple functions and variables.

Examples taken from an old text installer I wrote not using curses:
Code:
bold="\033[1m"; normal="\033[0m"; red="\033[0;31m"
underline_on="\033[4m";underline_off="\033[24m";
blink_on="\033[5m"; blink_off="\033[25m"
invisible_on="\033[25h"; invisible_off="\033[25l"
erase_end_of_screen="\033[0J"
up_delete_line () { tput cuu1; tput el; }
line_4_delete_eol () { tput cup 4 0; echo -e "\033[0J"; }
Of course see "man terminfo" for the codes.

Last edited by Didier Spaier; 10-26-2013 at 09:17 AM.
 
1 members found this post helpful.
Old 10-26-2013, 08:16 AM   #3
chemfire
Member
 
Registered: Sep 2012
Posts: 466

Rep: Reputation: Disabled
I would suggest you look at using something like dialog (what pkgtool uses). If you are looking to give the appearance of window; I am not clear on what you mean by background. You can certainly do a lot with escape sequences like Didier Spaier is suggesting as well, but you will find behavior changes a bit between the console, and various terminal emulators.
 
1 members found this post helpful.
Old 10-26-2013, 08:41 AM   #4
fskmh
Member
 
Registered: Jun 2002
Location: South Africa
Distribution: Custom slackware64-current
Posts: 308

Rep: Reputation: 92
waddles, do you mean displaying text at an arbitrary position in the X root window or using something that reads user input?

If you mean the former, then have a look at xosd. You could probably also abuse conky to get the job done, although it has some additional dependencies (lua, tolua++, imlib2, giblib and feh).
 
1 members found this post helpful.
Old 10-26-2013, 05:15 PM   #5
waddles
Member
 
Registered: Sep 2012
Posts: 372

Original Poster
Rep: Reputation: 1
@Didier: aware of tput & BTW U can save the escape typing by assigning to a variable. I will check on the tput el as I thing that is a terminfo usage but U can also do tput capname which is what I think that is where capname (terminfo) is el.
The unchanging background would be like and image of a flower or spacecraft as a background to moving foreground objects.
Thanks.
@fskmh: Thanks. What I am after is like above where I could create an image (actually foreground or background) that does not move as text rises from the bottom or descends from the top.
xosd looks close but not sure without testing. Will look into it further Thanks. Years ago the "COHERENT" a *nix OS, had capability to scroll text inside a field within an X-window but that does not seem to be a Linux/Slackware capability.
At least I can vary the background color to keep people awake during lectures.
@chemfire: I considered Dialog and Curses but don't know if that would allow auto-scrolling text.
I have thought of putting out a foreground image and re-echoing it before plunking down a line of text, then plunking down the image and 2 lines of text, the repeat for the 3rd line of text, etc. but that gets time consuming and after a few more lines of text. Reprinting 20+ lines of the "background" for the text will get SLOOOOOW.

LATER... BTW I have used esc[[col;row H before with Slacware but it no longer works with current versions.

Last edited by waddles; 10-30-2013 at 10:40 AM.
 
Old 10-30-2013, 10:40 AM   #6
waddles
Member
 
Registered: Sep 2012
Posts: 372

Original Poster
Rep: Reputation: 1
I was thinking about something like xwd and xwud where I could take a "picture", save it, recall it, position new text on it, recall it, position more new text so that text would appear to scroll up over the "picture". I think using GIMP is a bit too much for what I am after and I would need to encode all the button pushes which could be lengthy.
 
Old 10-31-2013, 03:28 AM   #7
waddles
Member
 
Registered: Sep 2012
Posts: 372

Original Poster
Rep: Reputation: 1
After struggling with this I have the solution that I required. However I would have liked to do it with a scroll region established with tput csr. For anyone interested:
Code:
#!/bin/sh
rm -f tstfil
rm -f tstfil2
rm -f tstfil3
# NOTE should make cursor invisible during display
echo "^[[40m"      # Set BG to black
clear              # goes with black
echo "^[[40m^[[1;37m" # Set FG (stars) to bold;white
knt=50             # Make 50 astronomic bodies
wid=`tput cols`    # Get width of display screen
base=`tput lines`  # Get bottom line of screen

# Create background scene of random stars
while [ $knt -gt 0 ]
do
  y=`expr $RANDOM % $wid`    # Create random y value
  x=`expr $RANDOM % $base`   # Create random x value
  tput cup $x $y             # Position for next astro body
  if [ `expr $knt % 8` == 0 ]
  then echo "^[[40m^[[1;31m¤^[[0m"        # Red Dwarf star
  else if [ `expr $knt % 10` == 0 ]
       then echo "^[[40m^[[1;32m§^[[0m"   # Green galaxy
       else echo "^[[40m^[[1;37m.^[[0m"   # Regular star
       fi
  fi
  knt=`expr $knt - 1`
done

# FIND text to display at end of script and COPY it to a file
txln=`egrep "^>" spactst2 | wc -l`
tail -$txln spactst2 > tstfil # Put history into a file

# Create file of lines with ">" 1st character removed & centered
while read line
do
   line=`echo ${line:1}`     # Drop 1st char in line (>)
   echo $line | \
   sed -e :a -e "s/^.\{1,$wid\}$/ &/;ta" -e 's/\( *\)\1/\1/' \
       >> tstfil2            # Output centered line to 2nd file
done < tstfil                # Input file
# Create "WIPE" file of spaces & with size to fit history display
for i in $(seq 1 $base)
do
   printf "%${wid}s\n" >> tstfil3  # Print line of spaces "$wid" wide
done

# Read successively more lines and as head moves up due to nl
# bump line start likewise
# NOTE: To prevent new lines merging with old ones this must start
#       above the very last screen line and the positioning of lines
#       using tput must be 1 above because of new line output.
echo "^[[40m^[[1;37m"        # Make FG white and bold
n=`wc -l tstfil2 | cut -d" " -f1` # Get lines in 2nd file
base=`expr $base - 1`        # Reset baseline prevents line push up 
for i in $(seq 1  $n)
do
   base=`expr $base - 1`     # Moves up another line 
   tput cup $base 0
   head -$i tstfil3          # Wipes current diplay of text plus 1
   tput cup $base 0
   head -$i tstfil2          # Text now 1 line longer
   sleep 2
done
echo "^[[0m"                 # Return to default colors
exit

>In the year 1492 ol' Big Chris hit the boards and sailed off
>on a quest thought as foolish to our parents.
>Traveling to the Moon is as likely..
>Yet today here we are with flags and streamers.
>We welcome a much slimmer Christopher Columbus and his
>bounty.
>Let us hope that we will be less critical of
>our explorers and scientists when they reach for the stars
>or the Yetti.
Hope it helps somebody else.
 
  


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
need help to slit multiple lines of text output at whitspaces in shell Ryanjon7 Programming 4 10-20-2011 09:44 PM
Cannot read text from text file and store it in a variable using shell script anurupr Linux - Newbie 2 03-03-2010 01:38 PM
Shell script to read lines in a text file and filter user data srimal Linux - Newbie 5 10-21-2009 07:41 AM
How to find and change a specific text in a text file by using shell script Bassam Programming 1 07-18-2005 07:15 PM
how change text (and background) color within the bash shell? Xavius Linux - Newbie 4 03-29-2004 02:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 01:29 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
Open Source Consulting | Domain Registration