<?xml version="1.0" encoding="UTF-8"?>
<!-- **************************************************************************
.... For copyright and licensing terms, see the file named COPYING.
.... **************************************************************************
.-->
<?xml-stylesheet href="docbook-xml.css" type="text/css"?>

<refentry id="vc-reset-tty">

<refmeta xmlns:xi="http://www.w3.org/2001/XInclude">
<refentrytitle>vc-reset-terminal</refentrytitle>
<manvolnum>1</manvolnum>
<refmiscinfo class="manual">user commands</refmiscinfo>
<refmiscinfo class="source">nosh</refmiscinfo>
<xi:include href="version.xml" />
</refmeta>

<refnamediv>
<refname>vc-reset-tty</refname>
<refpurpose>chain-load utility for resetting virtual console terminals</refpurpose>
</refnamediv>

<refsynopsisdiv>
<cmdsynopsis>
<command>vc-reset-terminal</command>
<arg choice='opt'>--hard-reset</arg>
<arg choice='opt'>--no-utf8</arg>
<arg choice='opt'>--no-tostop</arg>
<arg choice='opt'>--text-mode</arg>
<arg choice='req'><replaceable>next-prog</replaceable></arg>
</cmdsynopsis>
</refsynopsisdiv>

<refsection><title>Description</title>

<para>
<command>vc-reset-terminal</command> is a chain-loading utility that attempts to initialize the terminal and line discipline state of the terminal that is on its standard output, and then (if successful) chain loads to <replaceable>next-prog</replaceable> with the <citerefentry><refentrytitle>execvp</refentrytitle><manvolnum>3</manvolnum></citerefentry> function.
If its standard output is not a terminal, it aborts without attempting to initialize anything.
</para>

<para>
<replaceable>next-prog</replaceable> may contain its own command line options, which <command>vc-reset-terminal</command> will ignore.
</para>

<para>
<command>vc-reset-terminal</command> makes no alteration to process state.
</para>

<para>
It initializes the terminal by resetting the kernel virtual terminal mode, resetting the line discipline, and then outputting the escape sequences appropriate to the terminal type that initialize the terminal itself.
</para>

<refsection><title>Kernel virtual terminal mode reset</title>

<para>
If the <arg choice='plain'>--text-mode</arg> command line option is used, <command>vc-reset-terminal</command> will use operating-system-specific <citerefentry><refentrytitle>ioctl</refentrytitle><manvolnum>2</manvolnum></citerefentry> calls to attempt to switch a kernel virtual terminal to text mode.
</para>

</refsection>
<refsection><title>Line discipline reset</title>

<para>
The line discipline is reset to approximately the same state as would be done by the <command>stty</command> <arg choice="plain">sane</arg> command, with several exceptions:
</para>

<itemizedlist>

<listitem>
<para>
The <code>istrip</code> option is not set.
8-bit cleanliness is the norm nowadays.
</para>
</listitem>

<listitem>
<para>
The <code>tostop</code> option is set, unless the <arg choice='plain'>--no-tostop</arg> command-line option has been used.
Job control is the norm nowadays.
</para>
</listitem>

<listitem>
<para>
The <code>iutf8</code> option is set, unless the <arg choice='plain'>--no-utf8</arg> command-line option has been used.
UTF-8 is the norm nowadays, and <citerefentry><refentrytitle>console-terminal-emulator</refentrytitle><manvolnum>1</manvolnum></citerefentry> sends UTF-8 input sequences to virtual terminals.
</para>
</listitem>

</itemizedlist>

</refsection>
<refsection><title>Terminal reset</title>

<para>
<command>vc-reset-terminal</command> writes terminal escape and control sequences to soft (re-)initialize the terminal state, including tabstops, margins, windows, scrolling mode, and overstrike mode.
If the <arg choice='plain'>--hard-reset</arg> command line option is used, different escape sequences are written to hard reset the terminal.
</para>

<para>
It emits these terminal control sequences by spawning <citerefentry><refentrytitle>console-control-sequence</refentrytitle><manvolnum>1</manvolnum></citerefentry> with various options including <arg choice='plain'>--rows</arg>, <arg choice='plain'>--columns</arg>, and <arg choice='plain'>--soft-reset</arg>.
</para>

<para>
For compatibility of the actual control sequences emitted with various terminals and terminal emulators, see the <citerefentry><refentrytitle>console-control-sequence</refentrytitle><manvolnum>1</manvolnum></citerefentry> manual.
</para>

</refsection>

</refsection><refsection><title>Use</title>

<para>
The major use case for <command>vc-reset-terminal</command> is to reset the terminal and line discipline to some known states before printing the login banner (see <citerefentry><refentrytitle>login-banner</refentrytitle><manvolnum>1</manvolnum></citerefentry>) and running the <citerefentry><refentrytitle>login</refentrytitle><manvolnum>1</manvolnum></citerefentry> program.
The use case covers terminals that are "always on" and retain state from one terminal log-on session to the next, as is the case with real terminals (remote and local) and kernel virtual terminals.
</para>

<para>
<command>vc-reset-terminal</command> is, on the other hand, not particularly useful with <citerefentry><refentrytitle>console-terminal-emulator</refentrytitle><manvolnum>1</manvolnum></citerefentry>, which initializes the line discipline and terminal state itself to much the same state, and exits at hangup; making each log-on session start with an <emphasis>already</emphasis> freshly initialized terminal and line discipline.
</para>

<para>
The program is much the same as the BSD <citerefentry><refentrytitle>reset</refentrytitle><manvolnum>1</manvolnum></citerefentry> command, except that it chain-loads to another command, has a more modern view of what a "sane" line discipline is, does not touch the line discipline's size information, and defaults to a softer reset.
This is behaviour more suitable and streamlined for kernel virtual terminals, at which the command is specifically aimed.
</para>

<para>
Virtual terminals update the line discipline size themselves, either in response to control sequences that change the terminal size or as part of specialized idiosyncratic resizing utilities.
So there is no need for a VT reset utility to adjust them directly.
(Conversely, real terminals have no access to the line discipline and require that it be expressly kept in synch.)
</para>

<para>
Real terminals should not normally be sent the hard reset escape sequence, for reasons explained in the <citerefentry><refentrytitle>console-control-sequence</refentrytitle><manvolnum>1</manvolnum></citerefentry> manual and DEC VT documentation.
Conversely, the Linux and FreeBSD kernel virtual terminals do not implement the DEC soft reset control sequence.
In line with the general principle of avoiding hard resets, the <arg choice='plain'>--hard-reset</arg> command line option should only be used with these kernel virtual terminals.
</para>

</refsection><refsection><title>SEE ALSO</title>

<itemizedlist>
<listitem><para>
<citerefentry><refentrytitle>stty</refentrytitle><manvolnum>1</manvolnum></citerefentry>
</para></listitem>
</itemizedlist>

</refsection><refsection><title>Author</title>
<para><author><personname><firstname>Jonathan</firstname> <surname>de Boyne Pollard</surname></personname></author></para>
</refsection>

</refentry>
