Is there a way scroll text instead of page?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Is there a way scroll text instead of page?
# 8  
Old 12-18-2001
Using head and tail like that is terribly inefficient. I decided to try a rewrite. Sheesh...I spent all morning on this....
Code:
#! /usr/bin/ksh
#
#  scroller ---  display text, but sleep every few lines.
#
#
#  scroller will copy 5 lines from standard input to the 
#  local terminal and then sleep for one second.  
#
#  You  can override the 5 lines with a "-l n" option.  
#  And you use  a "-s n" to override the sleep time.
#
#  You can type your interrupt character (often control c)
#  to get a menu that will let you adjust these values.
#
#  You can use -m to go straight to the menu at startup
#  
#  You can specify filenames or scroller can just read from 
#  standard in.
#
USAGE="usage: scroller [-s n] [-l n] [-m] [filename1] [filename2] ..."
  
#
#  initialize variables
#
#  Set reasonable initial values here.  TASK controls the main 
#  loop as described below.  snooze is the number of seconds for
#  the sleep.  lpp (lines per page) is the number of lines to
#  dispaly before sleeping.  lines will repeatedly cycle from 0
#  to npp as the program runs.  totallines is a count of lines
#  processed so far.  And we turn off IFS so the reads work with
#  data that has leading white space.
  
TASK=2
snooze=1
lpp=5
lines=0
totallines=0
IFS=""

#
#  Now Process the command line
#

error=0
while getopts :s:l:m  o ; do
        case $o in
        s)      if [[ $OPTARG -gt 0 && $OPTARG -lt 100 ]] ; then
                        snooze=$OPTARG
                else
                        print $OPTARG is illegal
                        error=1
                fi
                ;;
        l)      if [[ $OPTARG -gt 0 && $OPTARG -lt 100 ]] ; then
                        lpp=$OPTARG
                else
                        print $OPTARG is illegal
                        error=1
                fi
                ;;
        m)      TASK=2
                ;;
        ?)      print error argument $OPTARG is illegal
                error=1
                ;;
        esac
done
shift OPTIND-1
if ((error)) ; then
        print $USAGE
        TASK=0
fi


#
#  Open first file or indicate that we are using stdin
#

if (($# >= 1)) ; then
        input=$1
        exec < $input
        shift
else
        input="(standard input)"
fi


#
#  Major loop.  TASK can be 0 or 1 or 2.  If TASK is set we 
#  loop doing either task 1 or task 2.  Either task can switch 
#  to the other.  And both tasks can abort by setting TASK=0.  
#  But control c will switch to task 1.
#

trap interrupt=1 2
interrupt=0
while ((TASK)) ; do
        if ((interrupt)) ; then
                interrupt=0
                TASK=1
        fi
        case $TASK in

#
#   Task 1 --- display service menu
#

        1)      print  
                print  '=====[[ scroller service menu ]]====='
                print
                print  "      $totallines lines processed so far from $input"
                print  "      sleep seconds = $snooze"
                print  "      lines per page = $lpp"
                print  
                print  '   1) list the text'
                print  '   2) set lines per page'
                print  '   3) set sleep seconds'
                print  '   4) abort'
                print
                print -n  "[Enter Selection]====>>"
                read < /dev/tty
                case $REPLY in 
                1)      TASK=2
                        ;;
                2)      print lines per page is currently $lpp
                        print -n enter new value --
                        read val < /dev/tty
                        if [[ $val -gt 0 && $val -lt 100 ]] ; then
                                lpp=$val
                        else
                                print $val is illegal
                        fi
                        ;;
                3)      print sleep seconds is currently $snooze
                        print -n  enter new value --
                        read val < /dev/tty
                        if [[ $val -gt 0 && $val -lt 100 ]] ; then
                                snooze=$val
                        else
                                print $val is illegal
                        fi
                        ;;
                4)      TASK=0
                        ;;
                *)      print illegal response
                        print REPLY = $REPLY
                        ;;
                esac
                ;;

#
#  Task 2 --- copy lines from stdin to stdout
#
#    Read a line, increment counts, sleep if it's time
#

        2)      if read line ; then
                        print -r -- "$line"
                        ((totallines=totallines+1))
                        ((lines=lines+1))
                        if ((lines >= lpp)) ; then
                                lines=0
                                sleep $snooze
                        fi
                else
#
#    No more input.  Open a new file or give up.
#

                        if [[ $# -ge 1 ]] ; then
                                input=$1
                                exec < $input
                                shift
                        else
                                TASK=0
                        fi
                fi
                ;;

#
#   Task * --- can't happen
#
        *)      print -u2 $0: impossible error TASK = $TASK
                TASK=0
                ;;
        esac
done

((totallines)) && print "$totallines" total lines processed

exit 0


Last edited by Perderabo; 12-18-2001 at 01:52 PM..
# 9  
Old 12-21-2001
Thanks Perderabo -

This script is a little over my head but I will test it out. Thanks.
# 10  
Old 12-21-2001
This scroller is exactly what i needed

Perderabo,

This script is perfect. Do you know if there is a way to sleep for less than 1 second? I couldn't find any doc on whether that was possible or not. I think this would make it scroll smoother.
# 11  
Old 12-22-2001
Sleeping for less than a second is not a real good idea in a script. The overhead required to launch a process is too great. The right thing would be to switch to c. But it is easy to write a program like sleep that will sleep for less than a second if you want to give it a try. I wrote one that I call "nodoff". It sleeps for milliseconds. So "nodoff 500" is a half a second. Here it is...
Code:
#ifdef __STDC__
#define PROTOTYPICAL
#endif
#ifdef __cplusplus
#define PROTOTYPICAL
#endif

#include <stdlib.h>
#include <sys/time.h>

#ifdef PROTOTYPICAL
int main(int argc, char *argv[])
#else
main(argc,argv)
char *argv[];
#endif

{
        int millisecs, microsecs;
        struct timeval tv;

        millisecs=atoi(argv[1]);
        microsecs=millisecs*1000;

        tv.tv_sec=microsecs/1000000;
        tv.tv_usec=microsecs%1000000;

        select(0, NULL, NULL, NULL, &tv);
        exit(0);
}


Last edited by Perderabo; 01-16-2005 at 03:17 PM.. Reason: Remove html which is no longer supported
# 12  
Old 12-28-2001
wish I knew c

Hey that's cool.
It looks like me learning c would be a good thing. Any suggestions on a good place to start for a beginner?
# 13  
Old 01-03-2002
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Forum Support Area for Unregistered Users & Account Problems

UZoo ad disabling scroll on page

The ad for UZoo disables scrolling. Very annoying (0 Replies)
Discussion started by: Unregistered
0 Replies

2. UNIX for Beginners Questions & Answers

Converting text file to html page

Hello Everyone, I have the following text file with the each field separated by newline Text file P file1-en-us_US-20170718T150157Z.json Wed 19 Jul 2017 06:10:13 AM EDT P file2-en-us_US-20170718T160150Z.json Wed 19 Jul 2017 06:10:13 AM EDT P file3-en-us_US-20170718T163218Z.json Wed... (9 Replies)
Discussion started by: nextStep
9 Replies

3. Shell Programming and Scripting

Copy text from web page and add to file

I need help to make a script for Ubuntu to OSCam that copy the text on this website that only contains "C: ip port randomUSERNAME password" and want to exclude the text "C:" and replace the rest with the old in my test.server file. (line 22) device = ip,port (line 23) user =... (6 Replies)
Discussion started by: baxarn
6 Replies

4. Shell Programming and Scripting

Web page with picture, text, php function

Hello. I'm trying to create a web page which the presentation is as follows: 1 °) at the top of page an image 2 °) below the text 3 °) to complete a php function that returns information. I tried different things but none work. Script 1: <!DOCTYPE html> <html> <head> <style> div { ... (5 Replies)
Discussion started by: jcdole
5 Replies

5. Shell Programming and Scripting

Grep text matching problem with script which checks if web page contains text.

I wrote a Bash script which checks to see if a text string exists on a web page and then sends me an email if it does (or does not e.g. "Out of stock"). I run it from my crontab, it's quite handy from time to time and I've been using it for a few years now. The script uses wget to download an... (6 Replies)
Discussion started by: gencon
6 Replies

6. UNIX for Dummies Questions & Answers

Possible to download web page's text to a file?

Hi, Say there is a web page that contains just text only - that is, even the source code is just the text itself, nothing more. An example would be "http://mynasadata.larc.nasa.gov/docs/ocean_percent.txt" Is there a UNIX command that would allow me to download this text and store it in a... (1 Reply)
Discussion started by: Breanne
1 Replies

7. Solaris

How to scroll through the man page in Solaris

Hey All, I generally login to the Solaris box using Putty. But when I read a man page, I am not being able to scroll line by line using traditional 'j' or 'k' keys. Any idea about how can we scroll through line by line while reading a manage page over Putty (2 Replies)
Discussion started by: paragkalra
2 Replies

8. HP-UX

Pid X killed due to text modification or page I/O error

Hello everybody, I have a HP-UX B.11.11. I had one disk and added one new. When trying to configure the second disk Not Using the Logical Volume Manager(from SAM) I have this error: Pid X killed due to text modification or page I/O error I tryed to add another partion on the first disk,... (5 Replies)
Discussion started by: savus
5 Replies

9. Shell Programming and Scripting

linking unix generated text file to html page

i am trying to link the text files that i generated from my shell script to an html page, to that i can view them using a browser, like internet explorer. i want to open the text files in html page when i enter a command to view the text file from the shell command. please could anyone help... (1 Reply)
Discussion started by: alexd
1 Replies

10. Programming

Text Modification and page I/O error

Hi!, while launching my C application on HP-UX 10.2 workstation, I get the following error message sometime: Pid 9951 killed due to text modification or page I/O error Could someone tell me what does this error means?? and how is this caused? Thanx in Advance, JP (4 Replies)
Discussion started by: jyotipg
4 Replies
Login or Register to Ask a Question