File: terminal.cpp

package info (click to toggle)
cgdb 0.8.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,468 kB
  • sloc: cpp: 12,169; ansic: 10,042; sh: 4,383; exp: 640; makefile: 197
file content (103 lines) | stat: -rw-r--r-- 1,876 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "terminal.h"

#if HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif /* HAVE_SYS_IOCTL_H */

int tty_cbreak(int fd, struct termios *orig)
{
    struct termios buf;

    if (tcgetattr(fd, &buf) < 0)
        return -1;

    /* Save the original state, for resetting later */
    *orig = buf;

    buf.c_lflag &= ~(ECHO | ICANON);
    buf.c_iflag &= ~(ICRNL | INLCR);
    buf.c_cc[VMIN] = 1;
    buf.c_cc[VTIME] = 0;

#if defined (VLNEXT) && defined (_POSIX_VDISABLE)
    buf.c_cc[VLNEXT] = _POSIX_VDISABLE;
#endif

#if defined (VDSUSP) && defined (_POSIX_VDISABLE)
    buf.c_cc[VDSUSP] = _POSIX_VDISABLE;
#endif

    if (tcsetattr(fd, TCSAFLUSH, &buf) < 0)
        return -1;

    return 0;
}

int tty_output_nl(int fd)
{
    struct termios buf;

    /* get attributes */
    if (tcgetattr(fd, &buf) < 0)
        return -1;

    buf.c_oflag &= ~ONLCR;      /* turn off NL -> CR NL mapping */

    if (tcsetattr(fd, TCSAFLUSH, &buf) < 0)
        return -1;

    return 0;
}

int tty_off_xon_xoff(int fd)
{
    struct termios buf;

    if (tcgetattr(fd, &buf) < 0)
        return -1;

    /* disable flow control; let ^S and ^Q through to pty */
    buf.c_iflag &= ~(IXON | IXOFF);
#ifdef IXANY
    buf.c_iflag &= ~IXANY;
#endif

    if (tcsetattr(fd, TCSAFLUSH, &buf) < 0)
        return -1;

    return 0;
}

int tty_set_echo(int fd, int echo_on)
{
    struct termios buf;

    if (tcgetattr(fd, &buf) < 0)
        return -1;

    if (echo_on == 1)
        buf.c_lflag |= ECHO;
    else if (echo_on == 0)
        buf.c_lflag &= ~ECHO;

    if (tcsetattr(fd, TCSAFLUSH, &buf) < 0)
        return -1;

    return 0;
}

int tty_get_attributes(int fd, struct termios *buf)
{
    if (tcgetattr(fd, buf) < 0)
        return -1;

    return 0;
}

int tty_set_attributes(int fd, struct termios *buf)
{
    if (tcsetattr(fd, TCSAFLUSH, buf) < 0)
        return -1;

    return 0;
}