GNU PROLOG with UTF8 support
terminal.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------*
2  * GNU Prolog *
3  * *
4  * Part : line-edit library *
5  * File : stty.h *
6  * Descr.: basic terminal operations - header file *
7  * Author: Daniel Diaz *
8  * *
9  * Copyright (C) 1999-2015 Daniel Diaz *
10  * *
11  * This file is part of GNU Prolog *
12  * *
13  * GNU Prolog is free software: you can redistribute it and/or *
14  * modify it under the terms of either: *
15  * *
16  * - the GNU Lesser General Public License as published by the Free *
17  * Software Foundation; either version 3 of the License, or (at your *
18  * option) any later version. *
19  * *
20  * or *
21  * *
22  * - the GNU General Public License as published by the Free *
23  * Software Foundation; either version 2 of the License, or (at your *
24  * option) any later version. *
25  * *
26  * or both in parallel, as here. *
27  * *
28  * GNU Prolog is distributed in the hope that it will be useful, *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
31  * General Public License for more details. *
32  * *
33  * You should have received copies of the GNU General Public License and *
34  * the GNU Lesser General Public License along with this program. If *
35  * not, see http://www.gnu.org/licenses/. *
36  *-------------------------------------------------------------------------*/
37 
38 
39 /*---------------------------------*
40  * Constants *
41  *---------------------------------*/
42 
43 
44 #define KEY_BACKSPACE '\b'
45 #define KEY_DELETE 0x7f
46 
47 #define KEY_ID(code) KEY_ID2(KEY_MODIF_NONE, code)
48 #define KEY_ID2(modif, code) (((modif) << 9) | ((1 << 8) | ((code) & 0x7f)))
49 
50 #define GET_MODIF(x) (((x) >> 9) & 7)
51 #define GET_CODE(x) ((x) & 0x1ff)
52 
53 
54 #define KEY_CTRL(x) ((x) & 0x1f)
55 
56 #define KEY_ESC(x) KEY_ID((1 << 7) | (x) | 0x20) /* 0x20 to be case insensitive */
57 #define IS_ESC_COMB(x) ((x) & (1 << 7))
58 #define GET_ESC_COMB(x) ((x) & 0x7f)
59 
60 
61 
62 #define KEY_MODIF_NONE 0 /* modifiers (additive) */
63 #define KEY_MODIF_SHIFT 1
64 #define KEY_MODIF_ALT 2
65 #define KEY_MODIF_CTRL 4
66 
67 #if defined(__unix__) || defined(__CYGWIN__) /* Unix */
68 #define KEY_EXT_FCT_1 KEY_ID(11)
69 #define KEY_EXT_FCT_2 KEY_ID(12)
70 #define KEY_EXT_FCT_3 KEY_ID(13)
71 #define KEY_EXT_FCT_4 KEY_ID(14)
72 #define KEY_EXT_FCT_5 KEY_ID(15)
73 
74 #define KEY_EXT_FCT_6 KEY_ID(17)
75 #define KEY_EXT_FCT_7 KEY_ID(18)
76 #define KEY_EXT_FCT_8 KEY_ID(19)
77 #define KEY_EXT_FCT_9 KEY_ID(20)
78 #define KEY_EXT_FCT_10 KEY_ID(21)
79 
80 #define KEY_EXT_FCT_11 KEY_ID(23)
81 #define KEY_EXT_FCT_12 KEY_ID(24)
82 
83 #define KEY_EXT_UP KEY_ID('A')
84 #define KEY_EXT_DOWN KEY_ID('B')
85 #define KEY_EXT_RIGHT KEY_ID('C')
86 #define KEY_EXT_LEFT KEY_ID('D')
87 
88 #define KEY_EXT_HOME KEY_ID('H')
89 #define KEY_EXT_END KEY_ID('F')
90 #define KEY_EXT_PAGE_UP KEY_ID(5)
91 #define KEY_EXT_PAGE_DOWN KEY_ID(6)
92 #define KEY_EXT_INSERT KEY_ID(2)
93 #define KEY_EXT_DELETE KEY_ID(3)
94 
95 #elif defined(_WIN32) /* Win32 */
96 
97 #include <windows.h>
98 
99 #define KEY_EXT_FCT_1 KEY_ID(VK_F1)
100 #define KEY_EXT_FCT_2 KEY_ID(VK_F2)
101 #define KEY_EXT_FCT_3 KEY_ID(VK_F3)
102 #define KEY_EXT_FCT_4 KEY_ID(VK_F4)
103 #define KEY_EXT_FCT_5 KEY_ID(VK_F5)
104 
105 #define KEY_EXT_FCT_6 KEY_ID(VK_F6)
106 #define KEY_EXT_FCT_7 KEY_ID(VK_F7)
107 #define KEY_EXT_FCT_8 KEY_ID(VK_F8)
108 #define KEY_EXT_FCT_9 KEY_ID(VK_F9)
109 #define KEY_EXT_FCT_10 KEY_ID(VK_F10)
110 
111 #define KEY_EXT_FCT_11 KEY_ID(VK_F11)
112 #define KEY_EXT_FCT_12 KEY_ID(VK_F12)
113 
114 #define KEY_EXT_UP KEY_ID(VK_UP)
115 #define KEY_EXT_DOWN KEY_ID(VK_DOWN)
116 #define KEY_EXT_RIGHT KEY_ID(VK_RIGHT)
117 #define KEY_EXT_LEFT KEY_ID(VK_LEFT)
118 
119 #define KEY_EXT_HOME KEY_ID(VK_HOME)
120 #define KEY_EXT_END KEY_ID(VK_END)
121 #define KEY_EXT_PAGE_UP KEY_ID(VK_PRIOR)
122 #define KEY_EXT_PAGE_DOWN KEY_ID(VK_NEXT)
123 #define KEY_EXT_INSERT KEY_ID(VK_INSERT)
124 #define KEY_EXT_DELETE KEY_ID(VK_DELETE)
125 
126 #endif
127 
128 
129 #if defined(_WIN32)
130 #define KEY_IS_EOF(c) ((c) == KEY_CTRL('D') || (c) == KEY_CTRL('Z'))
131 #else
132 #define KEY_IS_EOF(c) ((c) == KEY_CTRL('D'))
133 #endif
134 
135 
136 
137 
138 /*---------------------------------*
139  * Type Definitions *
140  *---------------------------------*/
141 
142 /*---------------------------------*
143  * Global Variables *
144  *---------------------------------*/
145 
146 /*---------------------------------*
147  * Function Prototypes *
148  *---------------------------------*/
149 
150 void Pl_LE_Open_Terminal(void);
151 
152 void Pl_LE_Close_Terminal(void);
153 
154 void Pl_LE_Screen_Size(int *row, int *col);
155 
156 void Pl_LE_Ins_Mode(int ins_mode);
157 
158 int Pl_LE_Kbd_Is_Not_Empty(void);
159 
160 int Pl_LE_Is_Interrupt_Key(int c);
161 
162 void Pl_LE_Emit_Beep(void);
163 
164 void Pl_LE_Put_Char(int c);
165 
166 int Pl_LE_Get_Char(void);
167 
168 
169 
void Pl_LE_Emit_Beep(void)
Definition: terminal.c:579
void Pl_LE_Screen_Size(int *row, int *col)
Definition: terminal.c:473
static int ins_mode
Definition: linedit.c:145
static CHAR32_T c
Definition: scan_supp.c:65
void Pl_LE_Close_Terminal(void)
Definition: terminal.c:420
int Pl_LE_Kbd_Is_Not_Empty(void)
Definition: terminal.c:527
void Pl_LE_Open_Terminal(void)
Definition: terminal.c:366
void Pl_LE_Ins_Mode(int ins_mode)
Definition: terminal.c:555
int Pl_LE_Is_Interrupt_Key(int c)
Definition: terminal.c:514
int Pl_LE_Get_Char(void)
Definition: terminal.c:702
void Pl_LE_Put_Char(int c)
Definition: terminal.c:606