]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - include/ttyutils.h
2 * No copyright is claimed. This code is in the public domain; do with
5 * Written by Karel Zak <kzak@redhat.com>
7 #ifndef UTIL_LINUX_TTYUTILS_H
8 #define UTIL_LINUX_TTYUTILS_H
13 #ifdef HAVE_SYS_IOCTL_H
14 #include <sys/ioctl.h>
16 #ifdef HAVE_SYS_TTYDEFAULTS_H
17 #include <sys/ttydefaults.h>
20 /* Some shorthands for control characters. */
21 #define CTL(x) ((x) ^ 0100) /* Assumes ASCII dialect */
22 #define CR CTL('M') /* carriage return */
23 #define NL CTL('J') /* line feed */
24 #define BS CTL('H') /* back space */
25 #define DEL CTL('?') /* delete */
27 /* Defaults for line-editing etc. characters; you may want to change these. */
28 #define DEF_ERASE DEL /* default erase character */
29 #define DEF_INTR CTL('C') /* default interrupt character */
30 #define DEF_QUIT CTL('\\') /* default quit char */
31 #define DEF_KILL CTL('U') /* default kill char */
32 #define DEF_EOF CTL('D') /* default EOF char */
34 #define DEF_SWITCH 0 /* default switch char */
36 /* Fallback for termios->c_cc[] */
38 # define CREPRINT ('r' & 037)
41 # define CDISCARD ('o' & 037)
44 /* Default termios->iflag */
46 # define TTYDEF_IFLAG (BRKINT | ICRNL | IMAXBEL | IXON | IXANY)
49 /* Default termios->oflag */
51 # define TTYDEF_OFLAG (OPOST | ONLCR /*| OXTABS*/)
54 /* Default termios->lflag */
56 # define TTYDEF_LFLAG (ECHO | ICANON | ISIG | IEXTEN | ECHOE|ECHOKE|ECHOCTL)
59 /* Default termios->cflag */
61 # define TTYDEF_CFLAG (CREAD | CS8 | HUPCL)
64 /* Storage for things detected while the login name was read. */
66 int erase
; /* erase character */
67 int kill
; /* kill character */
68 int eol
; /* end-of-line character */
69 int parity
; /* what parity did we see */
70 int capslock
; /* upper case without lower case */
73 #define INIT_CHARDATA(ptr) do { \
74 (ptr)->erase = DEF_ERASE; \
75 (ptr)->kill = DEF_KILL; \
76 (ptr)->eol = CTRL('r'); \
78 (ptr)->capslock = 0; \
81 extern int get_terminal_dimension(int *cols
, int *lines
);
82 extern int get_terminal_width(int default_width
);
83 extern int get_terminal_type(const char **type
);
84 extern int get_terminal_name(const char **path
, const char **name
,
87 #define UL_TTY_KEEPCFLAGS (1 << 1)
88 #define UL_TTY_UTF8 (1 << 2)
90 static inline void reset_virtual_console(struct termios
*tp
, int flags
)
92 /* Use defaults of <sys/ttydefaults.h> for base settings */
93 tp
->c_iflag
|= TTYDEF_IFLAG
;
94 tp
->c_oflag
|= TTYDEF_OFLAG
;
95 tp
->c_lflag
|= TTYDEF_LFLAG
;
97 if ((flags
& UL_TTY_KEEPCFLAGS
) == 0) {
99 tp
->c_lflag
&= ~CBAUD
;
101 tp
->c_cflag
|= (B38400
| TTYDEF_CFLAG
);
104 /* Sane setting, allow eight bit characters, no carriage return delay
105 * the same result as `stty sane cr0 pass8'
153 tp
->c_iflag
|= (BRKINT
| ICRNL
| IMAXBEL
);
154 tp
->c_iflag
&= ~(IGNBRK
| INLCR
| IGNCR
| IXOFF
| IUCLC
| IXANY
| ISTRIP
);
155 tp
->c_oflag
|= (OPOST
| ONLCR
| NL0
| CR0
| TAB0
| BS0
| VT0
| FF0
);
156 tp
->c_oflag
&= ~(OLCUC
| OCRNL
| ONOCR
| ONLRET
| OFILL
| \
157 NLDLY
|CRDLY
|TABDLY
|BSDLY
|VTDLY
|FFDLY
);
158 tp
->c_lflag
|= (ISIG
| ICANON
| IEXTEN
| ECHO
|ECHOE
|ECHOK
|ECHOKE
|ECHOCTL
);
159 tp
->c_lflag
&= ~(ECHONL
|ECHOPRT
| NOFLSH
| TOSTOP
);
161 if ((flags
& UL_TTY_KEEPCFLAGS
) == 0) {
162 tp
->c_cflag
|= (CREAD
| CS8
| HUPCL
);
163 tp
->c_cflag
&= ~(PARODD
| PARENB
);
166 tp
->c_oflag
&= ~OFDEL
;
169 tp
->c_lflag
&= ~XCASE
;
172 if (flags
& UL_TTY_UTF8
)
173 tp
->c_iflag
|= IUTF8
; /* Set UTF-8 input flag */
175 tp
->c_iflag
&= ~IUTF8
;
177 /* VTIME and VMIN can overlap with VEOF and VEOL since they are
178 * only used for non-canonical mode. We just set the at the
179 * beginning, so nothing bad should happen.
183 tp
->c_cc
[VINTR
] = CINTR
;
184 tp
->c_cc
[VQUIT
] = CQUIT
;
185 tp
->c_cc
[VERASE
] = CERASE
; /* ASCII DEL (0177) */
186 tp
->c_cc
[VKILL
] = CKILL
;
187 tp
->c_cc
[VEOF
] = CEOF
;
189 tp
->c_cc
[VSWTC
] = _POSIX_VDISABLE
;
190 #elif defined(VSWTCH)
191 tp
->c_cc
[VSWTCH
] = _POSIX_VDISABLE
;
193 tp
->c_cc
[VSTART
] = CSTART
;
194 tp
->c_cc
[VSTOP
] = CSTOP
;
195 tp
->c_cc
[VSUSP
] = CSUSP
;
196 tp
->c_cc
[VEOL
] = _POSIX_VDISABLE
;
197 tp
->c_cc
[VREPRINT
] = CREPRINT
;
198 tp
->c_cc
[VDISCARD
] = CDISCARD
;
199 tp
->c_cc
[VWERASE
] = CWERASE
;
200 tp
->c_cc
[VLNEXT
] = CLNEXT
;
201 tp
->c_cc
[VEOL2
] = _POSIX_VDISABLE
;
204 #endif /* UTIL_LINUX_TTYUTILS_H */