Recent

Author Topic: Screen Width versus Output File Width  (Read 1183 times)

CVAlkan

  • New member
  • *
  • Posts: 5
Screen Width versus Output File Width
« on: December 27, 2018, 06:33:30 pm »
I've been away from Pascal for some time, so realize this may be a dumb question (and, yes, I do believe there are such things), but here goes:

I'm using what reports itself as "Free Pascal Compiler version 3.0.4+dfsg-18ubuntu2 [2018/08/29] for x86_64" and running this on Linux Mint 19 with Cinnamon 3.8.9 and kernel version "4.15.0-42-generic".

I've written a utility that writes many numbered lines as output to the screen (gnome terminal to be specific).

The lines, each of which consists of an arbitrary number of five-character chunks (e.g. '[xxx]') can be quite long, so I have a routine that sets a variable to determine the number of such chunks that will fit on each line without wrapping (which would make the output very confusing to read), and ignore the rest of the line as it isn't really necessary to see more. The number of whole chunks that can be displayed is calculated as ":= ((WindMaxX - 29) div 5);" since I have a 29 character label at the beginning of each row.

I have read that there are known issues with WindMaxX, but the displays come out just fine; if I want to see more chunks on each line, I simply stretch out the terminal screen and rerun my utility.

BUT, BUT: if I try to save the results to a text file by running the utility and redirecting the output (with >) or by using tee (e.g. | tee file), *both* the display and the text in the output file is limited to an 80 column width.

I'm also aware through experimentation that Gnome terminal determines the number of Bytes that can be displayed and incorrectly reports it as the number of characters, but I'm using nothing but Latin characters in UTF-8 format, so don't believe that is an issue; the restriction to 80 characters, though, suggests that somehow using the redirect or tee makes everything default to "standard."

Can anyone tell me what I'm missing here?

Thanks in advance for any advice or suggestions

engkin

  • Hero Member
  • *****
  • Posts: 2286
Re: Screen Width versus Output File Width
« Reply #1 on: December 29, 2018, 06:18:35 pm »
First of all, I am a Windows person.

WindMaxX is based on ScreenWidth as visible in the initialization section:
Code: Pascal  [Select]
  1. //fpc\3.0.4\source\packages\rtl-console\src\unix\crt.pp
  2. Initialization
  3. ...
  4.   GetConsoleBuf;
  5. ...
  6.   WindMaxX:=ScreenWidth;

Notice how GetConsoleBuf sets ScreenWidth:
Code: Pascal  [Select]
  1. //fpc\3.0.4\source\packages\rtl-console\src\unix\crt.pp
  2. Procedure GetConsoleBuf;
  3. ..
  4.   ScreenWidth:=0;
  5. ..
  6.   if (not OutputRedir) ...  then
  7. ..
  8.     ScreenWidth:=Wininfo.ws_col;
  9. ...
  10.   // Set some arbitrary defaults which make some sense...
  11.   If (ScreenWidth=0) then
  12.      ScreenWidth:=80;
  13. ...
  14.  

That is the 80 column width you are seeing when you redirect the output to a file. Probably you can change the logic to suit your app. Or correct the values at beginning of your code.

CVAlkan

  • New member
  • *
  • Posts: 5
Re: Screen Width versus Output File Width
« Reply #2 on: January 11, 2019, 01:42:11 pm »
Thanks so much for the detailed reply ...

I apologize for not answering sooner, but I haven't used this forum much and was used to others where I receive an e-mail notification when someone posts a reply. I missed the "Attachments and other options" selector when I posted the original.