From 5df79c53745fde5d6c3340a2979b1429cd5892c1 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Sat, 8 Oct 2011 20:30:28 +0200 Subject: Initial import of htcd system 1.0 Signed-off-by: Henrik Rydberg --- src/hed/input.cc | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 src/hed/input.cc (limited to 'src/hed/input.cc') 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 @@ +/************************************************************************* + * + * 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 +#include +#include +#include +#include + +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.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; +} + -- cgit v1.2.3