Stop XTerm from moving text upwards on window resize, when cursor is at last row? - terminal

In the Alternate Screen Buffer mode in XTerm-like terminal emulators, when the cursor is on the last row and the terminal window is resized so that it has less rows, all text in the terminal is shifted upwards.
Can anyone point me to what is going on here? I can't find any related escape sequences to turn this behavior off, or any way to intercept SIGWINCH to move the cursor before the shift happens. It seems like it may be related to scrolling to keep the cursor on the screen.
I'd really like the screen display to not change, even if the cursor is no longer on screen after a resize.
I'm not using ncurses or other libraries, just escape sequences and system calls.

Related

How to scroll completely to the top of large terminal text buffers w/o adding additional dependencies?

I have a couple shell scripts which output git diffs which can get very long. When this happens, the terminal is left scrolled to the bottom of that text.
Ideally I'd like to programmatically scroll to the very top of the text buffer in a way which is as platform independent as possible, without requiring additional software installation.
The following works to move cursor to top of the currently visible text, but not to the top of the entire text buffer:
printf '\e[H'
This does basically the same thing:
printf '\e[0;d'
But neither of these scroll completely to the top, they just move the cursor to the top of the visible text.
My platform dependent (macOS) workaround is here:
https://github.com/montehurd/gitshorts/blob/main/utility#L3
Any pointers for how to scroll to the very start of the text buffer?

Display iTerm on screen with cursor [or Active Screen]

I always have iTerm running in the background, and use a hotkey to show/hide it when needed, which works great when using only one screen.
Now, with two screens, I notice that with the option to have it appear with the "Screen with Cursor", the first time I press the hotkey, it appears on the screen with the cursor (first screen), but when I hide it, move the cursor to another screen (second screen) and press the hotkey again, it appears on the first screen and not the second one.
Is there another setting that I might be missing to have work properly?

Printed contents disappear in terminal

The thing is I have printed something in the terminal, but when I accidentally resize the terminal, the printed contents at the bottom of my terminal disappear. Why is that? Is there anyway to recover these printed messages since the program runs a long time each time.
When you resize a terminal window, the terminal has to paint or repaint part of the window. If you lost text at the bottom of the window, that sounds as if you shrank the window when using one of the terminals which leave the upper-left corner of the window in a fixed position, while adjusting the rest of the window. Offhand, that could be rxvt, putty, konsole. xterm (which is configurable) defaults to the other direction.
If the window shrinks, then the location of the "bottom" row of text should be moved up (to match user's expectations). But there is a complication: GNU screen will besides redrawing the window, attempt to wrap long lines so that they fit the new margins. Developers for a few terminals have imitated that in the past few years, and you may notice some bug reports when that new feature does not work well.
For instance, if you shrank the window vertically, but changed its width, then a miscalculation of the wrapped lines could cause text to vanish. Then again, resizing it again might get the text back into view. But if that does not work, then it's gone.

How to scroll horizontally in emacs?

I can't get emacs to scroll horizontally!
To replicate the problem:
Open the *scratch* buffer.
Write a long line.
Make the long line exceed the window width with M-xtoggle-truncate-lines. The left hand text (column 0) will now be off the left of the window.
Try M-xscroll-left or its shortcut C-x < to scroll left.
Type y to enable the disabled commands.
NOTHING HAPPENS!
I also tried C-a to go to the beginning of the line.
I also tried M-xtoggle-horizontal-scroll-bar but got the error message "Horizontal scroll bars aren't implemented yet".
There seems to be no way to scroll horizontally!
I need this because I have many wide CSV files to read.
I'm using the latest prelude on emacs 24.5 on Windows 10.
I filed an issue on the prelude project in case it is a genuine bug and could be fixed there.
You seem not to understand how horizontal scrolling works. It's not intuitive, that's why the command is disabled by default.
When I press C-x< at the end of the long line, the line disappears to the left. When I press C-x> there, nothing happens.
Pressing C-x< at the beginning of the long line, though, shows the second part of the long line.
Consider using visual-line-mode or even the csv-mode instead.
There is new a feature in Emacs 26. You can customize mwheel-tilt-scroll-p and use mouse to scroll.
M-x customize group RET mouse
Then set mwheel-tilt-scroll-p to t
No need to handroll it yourself. This is provided out of the box in emacs 27, and it probably was available for longer:
This feature is off by default; the variable mouse-wheel-tilt-scroll turns it on, if you customize it to a non-nil value.
(setq mouse-wheel-tilt-scroll t)
Sounds like xemacs have horizontal scroll in a 'natural' way.
As far as I can see it there is a [Options] button in the menubar, when clicking on it there is a [Frame Appearance] sub menu and there, there are 2 button []scrollbars, [] Truncate Lines
When these 2 buttons are checked in, long line are truncated and scrolling is smooth.
May be xemacs is non standard though.
I use it, I find it easy to cut/paste even rectangular areas, selection is faster and more precise to me that what I could achieve with keyboard meta-ctrl-shift stroke alone.
Cheers
Phi
I

Emacs SplitScreen and GnuScreen Causing Line Wrap Problems

I have gnuscreen on with multiple "tabs" open. Emacs is on tab 0.
When I tab to a different screen and return to Emacs, the lines do not wrap properly anymore. They blend into each other. If I have a vertical split open in Emacs, the two views blend into each other as if the bar in the middle fails to constrain the line wraps.
How do I prevent this? This is in Terminal.app and the only solution I've found is to force a redraw by dragging the corner slightly. That's not a good long term solution.

Resources