Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a terminal menu with scrollable text

Status
Not open for further replies.
Sep 10, 2013
4
US
I am using a terminal only so no GUI and using Free Pascal 2.6.2. If I have a screen that begins on line 5 I can use the arrow keys to move down to say line 26, and if I get to line 27 it goes back to line 5, and line 4 wraps to line 25. All good and works with enter if a line is selected.

My problem is, if I have text that is say 100 lines long, I want to keep using the arrow keys go down, and if at line 27, line 27 moves to line 26 and line 26 to line 25 and line 5 would be removed from view.

Does anyone have an example of how to accomplish this?
 
I pulled out an old text viewer project in Turbo Pascal which was rather interesting to see still works in Windows 8. Anyhow, there's a lot there, but here's a clue on how I handled it (too much here to repost the whole thing):

Code:
 { header changed along with corresponding calls }
  procedure processdown(textarray: array of Pchar; textstring: string;
               var beginline: integer; var endline: integer;
               totallines: integer);
    begin
      if endline < totallines then
        begin
          gotoxy(1,2);
          delline;
          beginline := beginline + 1;
          endline := endline + 1;
          gotoxy(1,25);
          write(textarray[endline]);
          redrawtop(textstring);
        end;
    end;

{ header changed along with all corresponding calls }
  procedure processup(textarray: array of Pchar; textstring: string;
             var beginline: integer; var endline: integer);
    begin
      if beginline <> 0 then
        begin
          gotoxy(1,2);
          insline;
          beginline := beginline - 1;
          endline := endline - 1;
          write(textarray[beginline]);
          redrawtop(textstring);
        end;
    end;
This is what gets called when the user presses the DOWN or UP key. RedrawTop() is just a procedure that puts a status line on the top of the screen that says "Viewing <XYZ>, Press F1 for Help", nothing relevant to what your question is. Textarray is the place where the text lines are stored in memory.

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top