jquast / blessed

Blessed is an easy, practical library for making python terminal apps

Home Page:http://pypi.python.org/pypi/blessed

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request: change scrolling region

wookayin opened this issue · comments

I wonder if it is possible to implement a fixed-height window with blessed. We could have some scrolling feature with this (like less), either programmatically or through keybindings, with other part of the terminal screen being intact (rather than a full-screen window).

One example of similar terminal UI can be found in fzf (e.g. fzf --height 30%):

image

I quickly searched the current Terminal API but didn't find any relevant methods.

We can absolutely add this to blessed, it is a very basic capability. This is a vt100 sequence, "set scrolling region", it is \x1b[10;20r, where 10 is starting row, 20 is ending row.

http://www.termsys.demon.co.uk/vtansi.htm
https://vt100.net/docs/vt102-ug/chapter5.html
https://github.com/0x5c/VT100-Examples/blob/master/vt_seq.md#scrolling-margins

@jquast Thanks, I didn't know it was such a basic sequence. I tried the following example and it works for me. Look forward to blessed having this feature!

printf "\033[5;20r"        # needs to set proper value for top,bottom 
seq 1 100 | xargs -I{} bash -c 'echo {}; printf "\033[K"; sleep 0.01'
printf "\033[r"            # reset (it may clear the screen though)

the change scrolling region attribute is already in blessed because it is a termcap capability.

It is just not documented.

from blessed import Terminal
term = Terminal()
term.csr(10, 20)
'\x1b[11;21r'