summaryrefslogtreecommitdiff
path: root/src/hed/input.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/hed/input.cc')
-rw-r--r--src/hed/input.cc107
1 files changed, 107 insertions, 0 deletions
diff --git a/src/hed/input.cc b/src/hed/input.cc
new file mode 100644
index 0000000..4f2b008
--- /dev/null
+++ b/src/hed/input.cc
@@ -0,0 +1,107 @@
1/*************************************************************************
2 *
3 * HTCd - Copyright (C) 1998-2006 Henrik Rydberg
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <hed/input.h>
21#include <mt/mstring.h>
22#include <unistd.h>
23#include <poll.h>
24#include <curses.h>
25
26int Lines() { return LINES-1; }
27int Columns() { return COLS-1; }
28
29void ClearScreen() { erase(); }
30void MoveCursor(int i,int j) { move(i,j); }
31
32void InitCurses()
33{
34 initscr();
35 nodelay(stdscr,1);
36 raw();
37 noecho();
38 nonl();
39 keypad(stdscr,1);
40 intrflush(stdscr,FALSE);
41}
42
43void EndCurses()
44{
45 endwin();
46}
47
48void OutputField(int row,int col,int field,const sref& in)
49{
50 mstring tmp=in.left_first_of(cset_newl);
51 int cut=tmp.size()!=in.size();
52 if(tmp.size()<field) tmp.append(field-tmp.size(),' ');
53 if(cut||in.size()>field) { tmp.resize(field-1); tmp.append(1,'\\'); }
54 mvaddstr(row,col,(char*)tmp.c_str());
55}
56
57void Reverse(int n)
58{
59 if(n) attron(A_REVERSE); else attroff(A_REVERSE);
60}
61void Bold(int n)
62{
63 if(n) attron(A_BOLD); else attroff(A_BOLD);
64}
65
66void Refresh()
67{
68 refresh();
69}
70
71int RawInput() {
72 int c=getch();
73 if(c>0) return c;
74 struct pollfd ps={fileno(stdin),POLLIN,0};
75 poll(&ps,1,1000);
76 return getch();
77}
78
79int Input() {
80 int c=RawInput();
81#if 0
82 if(c==27) {
83 napms(1);
84 int c2=getch();
85 if(c2!=-1) {
86 switch(c2) {
87 default: return 0;
88 case 91:
89 switch(RawInput()) {
90 default: return 0;
91 case '2':
92 RawInput();
93 switch(RawInput()) {
94 default: return 0;
95 case 52: return RawInput()==122?KEY_HOME:0;
96 case 54: return RawInput()==122?KEY_PPAGE:0;
97 case 48: return RawInput()==122?KEY_END:0;
98 case 50: return RawInput()==122?KEY_NPAGE:0;
99 }
100 }
101 }
102 }
103 }
104#endif
105 return c;
106}
107