Author Topic: Is there a way to set a scrolling region on console output?  (Read 1588 times)

0 Members and 1 Guest are viewing this topic.

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
Is there a way to set a scrolling region on console output?
« on: April 20, 2021, 09:28:31 am »
As an example, I have a program that runs a lot of Windows command line utilities using SHELL and displays the output in a console. Let's assume that we are copying a lot of files using Robocopy and the output is being displayed to the screen. I would like to have the output displayed to the screen and the information scroll up and off the screen just as if the command was run manually at a command prompt, but with one exception: I would like to have a couple of static lines of information at the bottom of the screen that don't get affected by the region that is scrolling.

Is anyone aware of a way to accomplish something like that using QB64
« Last Edit: April 20, 2021, 09:31:27 am by hanness »

Marked as best answer by hanness on April 20, 2021, 10:13:17 am

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Is there a way to set a scrolling region on console output?
« Reply #1 on: April 20, 2021, 11:06:18 am »
I believe it is VIEW PRINT, though I do not know if that works in console.
http://www.qb64.org/wiki/VIEW_PRINT
Granted after becoming radioactive I only have a half-life!

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
Re: Is there a way to set a scrolling region on console output?
« Reply #2 on: April 20, 2021, 11:27:16 am »
Thanks very much for pointing me to that. You are right, it doesn't seem to apply to a console window, at least it didn't work in the quick test I did so far. This may still help me anyway, so thanks again.

Offline visionmercer

  • Newbie
  • Posts: 8
    • View Profile
Re: Is there a way to set a scrolling region on console output?
« Reply #3 on: April 20, 2021, 03:12:34 pm »
If you are using Windows 8 or later you can use escape codes.
Code: QB64: [Select]
  1. Width 80, 25
  2. Width 80, 25, 80, 25
  3. Terminal.ScrollRegion 2, 22
  4.  
  5. Locate 1, 1
  6. Color 7, 4
  7. Print "Lets see if it works:"
  8.  
  9. Locate 23, 1
  10. Print "Testing Scroll Regions"
  11.  
  12. Locate 2, 1
  13. Color 7, 0
  14. Shell "dir /s"
  15.  
  16. Sub Terminal.ScrollRegion (Top As Integer, Buttom As Integer)
  17.     Print Chr$(27) + "[" + _Trim$(Str$(Top)) + ";" + _Trim$(Str$(Buttom)) + "r";
  18.  

Writing this i found that if there is not a CLS it will not work in cmd.exe.
it will work in windows terminal without CLS but the width command is not functioning there.

A list of escape codes that is supported in windows:
https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences

Offline JohnUKresults

  • Newbie
  • Posts: 40
    • View Profile
Re: Is there a way to set a scrolling region on console output?
« Reply #4 on: April 21, 2021, 12:21:35 pm »
Hi

I use the view print commands in my program. Ignore the various variables shown, but the Head.Statusline prints various things at the top of the QB64 window by calling Window.High and then the Window.Low sub returns the focus to the lower part. I've set my top window as the top 4 lines and the bottom window as lines 5 to 25 (I'm sunning this program in the standard screen 0 or whatever QB64 defaults to). The bottom window can scroll happily with new text. I don't know if it would work the other way round i.e. to fix the lower window for information and scroll the top part.

Sorry if this code isn't copied in correctly - not sure how to do that!

SUB Head.StatusLine

    CALL Window.High: COLOR 0, 15
    LOCATE 2, 39: PRINT "[Using-> "; "c:\race\rrcmob\";
    PRINT "]"; SPACE$(32 - LEN("c:\race\rrcmob\"))
    LOCATE 3, 1: PRINT " [File: "; fil$; "]"; SPACE$(8 - LEN(fil$));
    PRINT TAB(19); "[Date: "; racedate$; "]";
    PRINT TAB(47); "[Recs:"; _TRIM$(STR$(loaded%)); "]   "; TAB(62); "[->";
    IF pr% = 0 THEN
        PRINT "Scrn ] ";
    ELSEIF pr% = 1 THEN
        PRINT "Print] ";
    ELSE
        PRINT "Disk ] ";
    END IF
    PRINT "         ";
    COLOR 7, 1: CALL Window.Low

END SUB

SUB Window.High

    VIEW PRINT 1 TO 4

END SUB

SUB Window.Low
 
    VIEW PRINT 5 TO 25

END SUB