Re: scroll in dos
- Posted by ghaberek (admin) Mar 09, 2013
- 1146 views
DonCole said...
Does anyone have some simple code that only does vertical scroll?
Boy, this sure does take me back. I had to bust out DOSBOX for this one! I sort of miss the good ol' days.
This little app will display itself on screen and scroll up/down with the arrow keys. Press Escape or 'q' to quit.
include file.e include get.e include graphics.e integer fn, rows, top, key sequence cmd, lines, vc object line -- get the command line parameters cmd = command_line() -- hold a buffer of lines lines = {} -- open the file fn = open( cmd[2], "r" ) if fn = -1 then printf( 2, "cannot read file: %s\n", {cmd[2]} ) abort( 1 ) end if -- read all the lines into the buffer line = gets( fn ) while sequence( line ) do -- trim the line while length(line) and find( line[$], " \r\n\t" ) do line = line[1..$-1] end while -- append it to the buffer lines = append( lines, line ) -- get the next line line = gets( fn ) end while -- close the file close( fn ) -- get the screen configuration vc = video_config() rows = vc[VC_LINES] -- turn off cursor and wrap cursor(NO_CURSOR) wrap(0) -- track the top row top = 1 -- display the initial lines on the screen for i = top to length(lines) by 1 do position( i, 1 ) puts( 1, lines[i] ) if i = rows then -- that's enough exit end if end for -- begin key loop key = wait_key() while key != 27 and key != 'q' do -- escape or 'q' quits if key = 328 then -- up -- are there more lines to display? if top > 1 then -- scroll down scroll( -1, 1, rows ) top -= 1 -- write the top line position( 1, 1 ) puts( 1, lines[top] ) end if elsif key = 336 then -- down -- are there more lines to display? if (top + rows - 1) < length(lines) then -- scroll up scroll( 1, 1, rows ) top += 1 -- write the bottom line position( rows, 1 ) puts( 1, lines[top+rows-1] ) end if end if key = wait_key() end while
Enjoy!
-Greg