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
104
105
106
107
|
/*************************************************************************
*
* HTCd - Copyright (C) 1998-2006 Henrik Rydberg
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <hed/input.h>
#include <mt/mstring.h>
#include <unistd.h>
#include <poll.h>
#include <curses.h>
int Lines() { return LINES-1; }
int Columns() { return COLS-1; }
void ClearScreen() { erase(); }
void MoveCursor(int i,int j) { move(i,j); }
void InitCurses()
{
initscr();
nodelay(stdscr,1);
raw();
noecho();
nonl();
keypad(stdscr,1);
intrflush(stdscr,FALSE);
}
void EndCurses()
{
endwin();
}
void OutputField(int row,int col,int field,const sref& in)
{
mstring tmp=in.left_first_of(cset_newl);
int cut=tmp.size()!=in.size();
if(tmp.size()<field) tmp.append(field-tmp.size(),' ');
if(cut||in.size()>field) { tmp.resize(field-1); tmp.append(1,'\\'); }
mvaddstr(row,col,(char*)tmp.c_str());
}
void Reverse(int n)
{
if(n) attron(A_REVERSE); else attroff(A_REVERSE);
}
void Bold(int n)
{
if(n) attron(A_BOLD); else attroff(A_BOLD);
}
void Refresh()
{
refresh();
}
int RawInput() {
int c=getch();
if(c>0) return c;
struct pollfd ps={fileno(stdin),POLLIN,0};
poll(&ps,1,1000);
return getch();
}
int Input() {
int c=RawInput();
#if 0
if(c==27) {
napms(1);
int c2=getch();
if(c2!=-1) {
switch(c2) {
default: return 0;
case 91:
switch(RawInput()) {
default: return 0;
case '2':
RawInput();
switch(RawInput()) {
default: return 0;
case 52: return RawInput()==122?KEY_HOME:0;
case 54: return RawInput()==122?KEY_PPAGE:0;
case 48: return RawInput()==122?KEY_END:0;
case 50: return RawInput()==122?KEY_NPAGE:0;
}
}
}
}
}
#endif
return c;
}
|