0

This is sort of a basic question, I guess it's not a specific issue with Raspbian but my knowledge about terminals is pretty limited.

I wanted to start with some shell programming which includes saving and restoring the content of the terminal / screen (e.g. while using the dialog tool).

I read that the following commands can do this (if the terminal supports this; via):

# 1. save screen:
tput smcup

# 2. restore screen:
tput rmcup

However these do not work with the default Raspbian and I have the impression that this is not supported by the terminal. I also don't know of any command to verify that, if you know which it is, please share.

So which terminal feature is needed? How is it named? Where is it documented? How can I enable /disable it with Raspbian? How can I verify if it is disabled or enabled?

3

Not all terminal devices support all capabilities. Once upon a very long time ago, "terminal device" referred to an actual piece of hardware; now it refers to an abstract device created by the OS or other software on top of actual hardware.

Because of this, you can run into a few different "terminal devices" on the same hardware (and it is the same few on all common hardware). The first is a VT (virtual terminal, aka. a VC, virtual console), which is the basic "linux console" you get outside of a GUI context; this is based on emulating a VT100, which is a real (old) hardware terminal (I would guess the "VT" there stands for "video terminal", since it wasn't virtual). There aren't any alternatives to this AFAIK.

The linux console does not support smcup/tmcup perhaps because the console is really a line interface, as opposed to a screen interface. However, there are screen interface libraries (such as ncurses) that operate within the terminal emulator (as opposed to something like X windows, which does not -- it supplants the VT); most complex console apps use something like that (dialog is more primitive). These are called terminal or console apps (as opposed to pure command-line apps) and includes editors like nano, vim, and emacs.

You can tell smcup is not supported because, as documented in man tput, 1 is returned to indicate this capability is not supported.

> tput smcup
> echo $?
1

That's in a VT. However, X based terminal emulators have more capabilities. If you try tput smcup in a GUI terminal, it will work. There are various flavours of GUI terminal, usually associated with specific DEs (desktop environments) but I think all of them should be fine with this. It works for me on raspian using the XFCE Terminal (it shouldn't matter much whether you use that or something else), which tput longname reports as an "xterm terminal emulator (X Window System)" -- pretty sure most GUI terminals will do the same.

  • Wow, thanks for the lengthy and very informative answer. I'm currently using VT, which explains why vim or less didn't restore as well. Also thank you for answering how I can check that, makes all very much sense. I will chew on it a bit. – hakre Jul 6 '13 at 20:52
  • Just fiddling with this and it all makes sense. Still wondering if i can add this functionality, e.g. by using additional tools like for example screen to add that. Trying inside screen gives me 0 as return value but this storing / resotirng does not work. maybe that check is different? – hakre Jul 6 '13 at 21:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.