Hi Bruno,

On 5/27/24 4:58 PM, Bruno Haible wrote:
> I would only add tcgetwinsize, for two reasons:
>   - The man page that you cite says "In general, the tcsetwinsize function
>     is best avoided except by applications responsible for actually
>     implementing terminal windows."
>   - How would you write a unit test for tcsetwinsize? Also, so much
>     of its effects is unspecified.
> 
> Terminal stuff is generally a portability pain — see tests/test-openpty.c.
> Therefore I would limit myself to the functionality that applications
> actually need.

Good points. The tcgetwinsize seems more useful to me anyways.
Inetutils has its own functions which do the same thing for wrapping
and such. They appear to be from 4.4BSDLite2 so likely written 30+ years
ago.

>> Windows should be able to support them too [2].
> 
> This needs thought first, because where on the Unix side you have
> two concepts:
>   - winsize from the OS,
>   - lines and columns from the terminfo description of $TERM,
>     and the LINES and COLUMNS environment variables,
> on the Windows side you have only the Consoles.
> 
> How are these concepts delimited (on the Unix side)?
> 
> How do these concepts map to each other?

I've used GetConsoleScreenBufferInfo once in the past and it worked
fine in Wine atleast [1]. I don't use Windows so perhaps it wouldn't
work there.

Here is an example of how you would write a function to get the height
of the console.

int
term_get_height (void)
{
  HANDLE console_output;
  CONSOLE_SCREEN_BUFFER_INFO buffer_info;
  console_output = GetStdHandle (STD_OUTPUT_HANDLE);
  if (console_output != INVALID_HANDLE_VALUE)
    {
      if (GetConsoleScreenBufferInfo (console_output, &buffer_info))
        return (int) buffer_info.dwSize.Y;
    }
  return -1;
}

I guess in Gnulib you probably have to deal with the invalid parameter
handler there.

Collin

[1] https://learn.microsoft.com/en-us/windows/console/getconsolescreenbufferinfo


Reply via email to