Page MenuHomeFreeBSD

Add small tool to query terminal for window size
ClosedPublic

Authored by darius-dons.net.au on Dec 8 2015, 1:41 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Apr 25, 5:16 AM
Unknown Object (File)
Fri, Apr 12, 6:10 AM
Unknown Object (File)
Mar 25 2024, 11:49 PM
Unknown Object (File)
Mar 25 2024, 11:11 PM
Unknown Object (File)
Feb 23 2024, 1:55 AM
Unknown Object (File)
Jan 10 2024, 2:39 PM
Unknown Object (File)
Jan 10 2024, 2:39 PM
Unknown Object (File)
Jan 10 2024, 2:39 PM

Details

Summary

This tool is a smaller, less featured version of resize from the xterm port.

It's very useful when accessing systems via serial console that don't run X (e.g. dev boxes).

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

darius-dons.net.au retitled this revision from to Add small tool to query terminal for window size.
darius-dons.net.au updated this object.
darius-dons.net.au edited the test plan for this revision. (Show Details)
darius-dons.net.au set the repository for this revision to rS FreeBSD src repository - subversion.
cem added a reviewer: cem.
cem added a subscriber: cem.
cem added inline comments.
usr.bin/resizewin/resizewin.c
48 ↗(On Diff #10906)

__unused goes after parameter name, I think.

This revision is now accepted and ready to land.Dec 8 2015, 10:13 PM

What happens if user ^Cs the program while it loops?

In D4438#93753, @kan wrote:

What happens if user ^Cs the program while it loops?

Pretty sure read gets EINTR and it exits.

Certainly if I test it on a distant system (so I have time to press something before the terminal replies) pressing ^C results in it printing "Unable to parse response".

Default action for SIGTERM/SIGINT is to terminate process, not to interrupt read. So, this will not do what you think it will.

In D4438#93753, @kan wrote:

What happens if user ^Cs the program while it loops?

Pretty sure read gets EINTR and it exits.

Certainly if I test it on a distant system (so I have time to press something before the terminal replies) pressing ^C results in it printing "Unable to parse response".

Hm, isn't this surprising? Isn't the default SIGINT handler "Exit immediately?"

If we get a Terminate Program signal mid-run, do we leave the terminal in a usable state (echo, cursor in the right place, etc)?

In D4438#93765, @cem wrote:

Hm, isn't this surprising? Isn't the default SIGINT handler "Exit immediately?"

If we get a Terminate Program signal mid-run, do we leave the terminal in a usable state (echo, cursor in the right place, etc)?

I just realised my previous statement about EINTR was wrong. The code disables ISIG which stops the terminal processing for signal key presses, i.e. ^C becomes just another character (specifically 0x03) so the process doesn't get a signal at all.

kan added a reviewer: kan.

I do like having something similar in our tree actually, thought this was committed already.

wblock added inline comments.
usr.bin/resizewin/resizewin.1
35 ↗(On Diff #10906)

This whole sentence is fairly vague. This program only needs VT100 compatibility in terminal size reporting. Being more specific and possibly also citing the ANSI spec might help. (I suspect we are past the days where everyone knows what VT100 compatibility is). It is not clear what "update the kernel with it" actually means.

40 ↗(On Diff #10906)

This is a really long sentence that says several things and could be split into a couple of sentences.

.Nm
is functionally similar to
.Xr resize 1
from the
.Xr xterm 1
distribution.
However,
.Nm
only works on VT100 (ANSI?)-compatible terminals, and does not emit commands to set environment variables.

Overall, this command is defined in terms of the resize(1) command. But that command or its man page might not be available to the reader. So again, more specifics on what this command does would be better.

We probably don't need an examples section, but it would be nice to add a sentence or two about when and how this command would be used: "After a terminal window has been resized, running .Nm will update the kernel's..."

darius-dons.net.au edited edge metadata.
darius-dons.net.au removed rS FreeBSD src repository - subversion as the repository for this revision.
darius-dons.net.au marked an inline comment as done.

Update man page based on feedback.

This revision now requires review to proceed.Mar 16 2016, 10:32 PM
usr.bin/resizewin/resizewin.1
40 ↗(On Diff #10906)

I split it into two, replaced VT100 with VT100/ANSI and added when you'd use it.

I'm not really sure what else to add for the "what it does" part without going and explaining how curses applications work out how big the terminal is and why it matters (which seems out of scope)

Do you have something more specific I should add?

usr.bin/resizewin/resizewin.1
28 ↗(On Diff #14380)

This needs to be bumped before commit.

35 ↗(On Diff #14380)

Still an aside, but easier to read with commas:

Query the terminal emulator, which is assumed to be VT100/ANSI compatible, for
37 ↗(On Diff #14380)

Use the command name, because "It" is vague:

.Nm
is functionally similar to
.Xr resize 1
from the
.Xr xterm 1
distribution.
41 ↗(On Diff #14380)

Start new sentences on new lines.

46 ↗(On Diff #14380)

s/will update/updates/

57 ↗(On Diff #14380)

"resize" again here is redundant.

35 ↗(On Diff #10906)

Still needs a bit more to explain what "update the kernel" means.

From IRC: "Perform the TIOCSWINSZ ioctl on the terminal file descriptor..."
...which makes certain the kernel knows the actual current width and height of the terminal window?

Man page looks okay to me. :)

wblock added a reviewer: wblock.
This revision is now accepted and ready to land.Mar 17 2016, 2:59 AM
This revision was automatically updated to reflect the committed changes.