33

The reset command includes a delay, between clearing the screen and returning. This is even on the latest terminal type xterm-256color. Why?

man reset does not mention a delay, only the printing of special strings. (It doesn't mention clearing the screen either. I assume this is included under the terminal initialization string).

I notice the follow output in strace -f reset:

nanosleep({tv_sec=1, tv_nsec=0}, 0x7ffe1964f100) = 0
ioctl(2, SNDCTL_TMR_STOP or TCSETSW, {B38400 opost isig icanon echo ...}) = 0
0

2 Answers 2

39

Real (hardware) terminals need that. For instance, with some, the only way to reset them is to do a hardware-reset.

It's harmless with a terminal emulator, and since there's no conventional way to tell the difference (and too hard to determine if some escape sequence might do a hardware-reset), reset assumes your terminal is real.

The time-delay dates back to tset in 3BSD in 1979, like this:

    /* output startup string */
    if (!RepOnly && !NoInit)
    {
            bufp = buf;
            if (tgetstr("is", &bufp) != 0)
                    prs(buf);
            bufp = buf;
            if (tgetstr("if", &bufp) != 0)
                    cat(buf);
            sleep(1);       /* let terminal settle down */
    }

It's evolved somewhat in ncurses, but using the same guideline:

        if (!noinit) {
            if (send_init_strings(my_fd, &oldmode)) {
                (void) putc('\r', stderr);
                (void) fflush(stderr);
                (void) napms(1000);         /* Settle the terminal. */
            }
        }

Further reading:

6
  • 3
    While we're here could you explain how to remove the delay if possible?
    – user541686
    Commented Jan 8, 2017 at 3:02
  • 12
    @Mehrdad You could try tput reset. It doesn't seem to use the delay.
    – Ross Ridge
    Commented Jan 8, 2017 at 6:40
  • 4
    @Mehrdad stty sane appears to fix the first condition, without any delay.
    – sourcejedi
    Commented Jan 8, 2017 at 9:08
  • 3
    The release (6.0) of ncurses doesn't modify terminal modes (as "reset" or "stty sane" does). currrent ncurses "tput reset" does all but the delay. For OpenBSD... wait 10 years. Commented Jan 8, 2017 at 11:26
  • 3
    @Mehrdad this works fine for me: alias reset='tput reset' in ~/.bashrc
    – hanshenrik
    Commented Dec 4, 2017 at 17:53
2

Note that as of release 6.5 of ncurses (April 27, 2024), the one-second delay has been removed in most cases.

See the release note:

tput and tset

  • add “-v” option to tput, to show warnings
  • modify reset command to avoid altering clocal if the terminal uses a modem
  • modify reset feature to avoid 1-second sleep if running in a pseudo-terminal

Using reset in a terminal with an updated package is now basically instantaneous.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .