* * *

Author Topic: Crt console scroll back problem  (Read 2970 times)

theflakes

  • Newbie
  • Posts: 2
Crt console scroll back problem
« on: December 18, 2015, 04:34:18 pm »
Been searching on how to work around the Crt scroll back problem in Windows and can't find anything.  I'm writing a console application with a lot of text output and the output is always truncated at the top of the console window.  I just started programming in FPC and am loving it as I used to program in Delphi a very long time ago.  Any help anyone can offer is very appreciated.  Thanks

Cyrax

  • Hero Member
  • *****
  • Posts: 540
Re: Crt console scroll back problem
« Reply #1 on: December 19, 2015, 03:35:12 am »
Unfortunately max console scroll buffer is limited to 9999 rows. You can raise that limit programmatically to maximum of 32767 - 2 rows, but it is still low for heavy duty console programs.

You can read output of your console program into your GUI program and show it inside TMemo/TSynEdit component. Now the limits of output are bitness of your program and how much memory your computer have.

Thaddy

  • Hero Member
  • *****
  • Posts: 4505
Re: Crt console scroll back problem
« Reply #2 on: December 19, 2015, 10:36:04 am »
If 9999 is not enough one would normally use a buffer that is large enough (can be a file or memory) and write a windowing procedure to do the display. That's for example how a virtual listview or a virtual treeview works. Although these not are for console mode use they demonstrate the principle. FreeVision works in much the same way and can hold data of more or less arbitrary length. (Up to certain limits). E.g.: the textmode editor fp itself can hold very large files, much larger than normally can be handled by the console.

E.g: Use a Tstringlist to load the file and write your data to and select the position in that stringlist for the top line to display anything after that. Write some code for ctrl-home/end and up/down arrow to scroll the Tstringlist and then write some code to write that part of the stringlist to the number of visible lines in the console (let's say 43 or 25 starting from the position in the stringlist you read from and write to.)

What I mean in the practical sense:
The up/down arrow goes to line Y in the string list. Then display lines Y to Y+ the number of console lines visible. The part that is displayed is called a window on your data.
« Last Edit: December 19, 2015, 10:50:21 am by Thaddy »
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

theflakes

  • Newbie
  • Posts: 2
Re: Crt console scroll back problem
« Reply #3 on: December 19, 2015, 04:14:58 pm »
Thanks, I stopped using Crt as it wasn't the 9999 limit I was running up against(Using Lazarus on Win10).  The problem was always the top of the visible command window where the output would be cut off.  And, it would vary based upon window size but it was always the visible top of the window.  Was hoping to use color in the output to make certain entries stand out more.

The utility needs to be completely console based for it to function as it will be used in pentesting/vulnerability enumeration hopefully.  As long as I can figure out how to do all the things I want to.  Been a long time since I programmed in Delphi.  Lazarus is bringing back a lot of good memories.

Writing a console based viewer would be interesting and fun; something like less in NIX would be helpful.

Cyrax

  • Hero Member
  • *****
  • Posts: 540
Re: Crt console scroll back problem
« Reply #4 on: December 19, 2015, 04:24:49 pm »
You can't create a console program with unlimitless scrolling buffer under Windows without workarounds (fake your console with GUI one or create console program which uses scrolling keys (up, down, left, right) to display your output from TStringList class. In this case you can't use default console window scrollbars. You can't even have access to them under console program due to their Windows nature/security.) .

Top buffer line will be always replaced with new one and old ones will be lost when your output lines grow greater than maxium scoll buffer row.

Thaddy

  • Hero Member
  • *****
  • Posts: 4505
Re: Crt console scroll back problem
« Reply #5 on: December 19, 2015, 04:56:06 pm »
You can't create a console program with unlimitless scrolling buffer under Windows without workarounds (fake your console with GUI one or create console program which uses scrolling keys (up, down, left, right) to display your output from TStringList class. In this case you can't use default console window scrollbars. You can't even have access to them under console program due to their Windows nature/security.) .

Top buffer line will be always replaced with new one and old ones will be lost when your output lines grow greater than maxium scoll buffer row.

Well, that would not be a work-around. As I explained, that's how things are done in every proper written viewer or editor.
Basically, mis-using the console buffer itself is more of an accidental thing when it works  than proper programming. I tried to explain he should use a windowed view on his data and display only that part. That's how things should be done and that is how he can achieve his goal.
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

alejandor

  • Newbie
  • Posts: 1
Re: Crt console scroll back problem
« Reply #6 on: April 19, 2017, 04:05:31 pm »
Sorry for resurrecting this old thread, but I've run into the same problem and I think the OP was misunderstood. In current windows10 console, scrollback is broken for freepascal console programs. Regardless of the buffer size in the console, after the pascal program ends only the visible portion remains in the buffer. If you scroll back you'll see whatever was in the console at program launch.

I'm trying to find a solution for this right now, in case of success I will reply back.

Thaddy

  • Hero Member
  • *****
  • Posts: 4505
Re: Crt console scroll back problem
« Reply #7 on: April 19, 2017, 04:21:51 pm »
Oh, well.

Nothing wrong with fpc or fp.
Plz also report back WHEN - I promised my wife to live until 2174, we have therefor a limit built in for your answer  -  you fail, not IF you fail...(I know that..)
« Last Edit: April 19, 2017, 04:24:12 pm by Thaddy »
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5730
Re: Crt console scroll back problem
« Reply #8 on: April 19, 2017, 08:45:53 pm »
Sorry for resurrecting this old thread, but I've run into the same problem and I think the OP was misunderstood. In current windows10 console, scrollback is broken for freepascal console programs.

Do you use any units, like Crt or Video that take over control over the console?

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus