Question

I need to turn automatic margins off according the following statement from Screen's manual in my Mac

If your terminal is a "true" auto-margin terminal (it doesn't allow the last position on the screen to be updated without scrolling the screen) consider using a version of your terminal's termcap that has automatic margins turned off.

How can you turn automatic margins off by your terminal's termcap?

Was it helpful?

Solution

According to XTerm Control Sequences, this sequence should do what was asked:

CSI ? 7 l

That is,

printf '\033[?7l'

The 7 is documented as

        Ps = 7  -> Wraparound Mode (DECAWM).

and the final character l (lowercase L) denotes this as a reset rather than a set control.

For whatever reason, the terminfo name for this is more obscure: "automatic margins". These terminfo capabilities deal with the feature (see terminfo(5)):

   auto_right_margin             am         am        terminal has auto‐
                                                      matic margins
   enter_am_mode                 smam       SA        turn on automatic
                                                      margins
   exit_am_mode                  rmam       RA        turn off automatic
                                                      margins

Interestingly, the vt100-nam terminal description in ncurses (which apparently no one uses) initializes the terminal to use automargins margins using this string:

rs2=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h, 

(the \E[?7h sets it), and asserts that the terminal does not use automatic margins by cancelling am. It also has the terminfo capabilities rmam and smam. So you could do this to prove that it works:

tput rmam
stty columns 999
ps -efwwwwwl

and (for the ordinary user) see the ps listing nicely truncated against the right margin of the terminal window.

The other variants vt220-nam and vt320-nam appear correct...

By the way, for Mac, you would use the terminfo names such as rmcup rather than the termcap RA, because OSX uses ncurses' tput (terminfo) rather than the BSD variant.

Further reading:

Occasionally someone asks about suppressing automargins because they suppose that terminals can pan/scroll left/right to show the information which was not wrapped to a new line. Terminals which do this are rare, and OSX Terminal is not one of those. It behaves like a subset of xterm, which itself emulates the series of DEC terminals vt52/vt100/vt220/etc. In this question, OP is concerned/confused about this paragraph from the screen manual:

If your terminal is a "true" auto-margin terminal (it doesn't allow the last position on the screen to be updated without scrolling the screen) consider using a version of your terminal's termcap that has automatic margins turned off. This will ensure an accurate and optimal update of the screen in all circumstances. Most terminals nowadays have "magic" margins (automatic margins plus usable last column). This is the VT100 style type and perfectly suited for screen. If all you've got is a "true" auto-margin terminal screen will be content to use it, but updating a character put into the last position on the screen may not be possible until the screen scrolls or the character is moved into a safe position in some other way. This delay can be shortened by using a terminal with insert-character capability.

That last position on the screen refers to the lower-right corner of the terminal. In the normal case, if your cursor is on the lower-right corner and you print a character, you would expect the display to scroll up by one line and show the character on the next line. Also (because terminals can be implemented in different ways), some could scroll up when you print a character in the last position. The VT100 does not do this. Not only does it not scroll up in that case, but it ignores non-printing characters while on the margin (see xterm FAQ That description of wrapping is odd, say more?). There is a terminfo flag xenl which is set to show when the terminal does this special behavior. About a third of the terminal descriptions in the terminal database have this flag. While most of those are for terminals which you likely will never encounter, keep in mind that the advice in the manual page was written back in an era when those other terminals were as likely to be found as a VT100-lookalike. The early change-history for screen is poor, but the text was in screen's second posting to Usenet in 1992. The initial posting in 1987 said something similar:

Screen never writes in the last position of the screen, unless the boolean capability LP is found in the termcap entry of the terminal. Usually, screen cannot predict whether or not a particular terminal scrolls when a character is written in the last column of the last line; LP indicates that it is safe to write in this position. Note that the LP capability is independent of am (automatic margins); for certain terminals, such as the VT100, it is reasonable to set am as well as LP in the corresponding termcap entry (the VT100 does not move the cursor when a character is written in the last column of each line).

The later wording reflects the fact that the terminfo system was prevalent, and the name LP was not termcap name chosen for corresponding with xenl (it is xn).

The point of all of this is that screen attempts to convert between programs writing to different terminal types and make them all appear like one type of terminal — which means that it tries to put text on the terminal's display in all of the locations. The lower-right corner is a problem because some terminals would scroll up, spoiling the attempt to write there. As a workaround, some terminals provided an alternative:

  • using a different mode (insert),
  • put the cursor on the next to last position of the display,
  • write characters to fill in, pushing a character into the last position, and
  • turn insert-mode off once it is done (otherwise a nuisance).

About two thirds of the descriptions in the terminal database have the capability to do this insert-mode (smir). That still was not perfect, but it certainly was worth mentioning in 1992. About a quarter implement a similar similar feature ich1. Some implement both (and vi could get confused by those, by trying to do both methods).

VT100-lookalikes provide a third way to write that last position; screen checks for and uses whatever is there.

OTHER TIPS

Most terminal emulators, including the mac default terminal, are not "true auto-margin terminals" in the sense being discussed here - they emulate a vt100-series terminal, which had "smart" wraparound. You can check by running cat and typing to the end of the last line - after you type the last character, the cursor remains at the end of the line (highlighting the character you just typed) until you type another character.

The only consequence of a 'true auto-margin terminal' is that a character cannot be displayed in the lower right hand corner (though some programs are able to work around that by shifting a character into place with ich/ich1)

If I understand you correctly you're looking to set the autowrap feature to NO using terminfo database. If so I believe you can use the -nam flag to turn it off - something like vt100-nam should do it. You can also check by looking at the man pages for terminfo.

If this solves your question, mark this up. (^_^) If not... well comment back and I'll check again for you. Cheers!

Update: There's also a shortcut that may apply to you to toggle the wrap off and on. Check out the shortcut sheet here. And additional information for Screen can be found here (search for wrap). You can also check here on how to use setterm (section 17.14 Changing the Terminal Settings). Also check here for examples of changing settings.

Good luck again. (^_^)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top