1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "nel/misc/types_nl.h"
25 #include <unistd.h> // for read()
28 static struct termios initial_settings
, new_settings
;
29 static int peek_character
= -1;
33 tcgetattr(STDIN_FILENO
,&initial_settings
);
34 new_settings
= initial_settings
;
35 new_settings
.c_lflag
&= ~ICANON
;
36 new_settings
.c_lflag
&= ~ECHO
;
37 new_settings
.c_lflag
&= ~ISIG
;
38 new_settings
.c_cc
[VMIN
] = 1;
39 new_settings
.c_cc
[VTIME
] = 0;
40 tcsetattr(STDIN_FILENO
, TCSANOW
, &new_settings
);
45 tcsetattr(STDIN_FILENO
, TCSANOW
, &initial_settings
);
53 if (peek_character
!= -1) return 1;
55 new_settings
.c_cc
[VMIN
]=0;
56 tcsetattr(STDIN_FILENO
, TCSANOW
, &new_settings
);
57 nread
= read(STDIN_FILENO
,&ch
,1);
58 new_settings
.c_cc
[VMIN
]=1;
59 tcsetattr(STDIN_FILENO
, TCSANOW
, &new_settings
);
73 if(peek_character
!= -1)
79 if (read(STDIN_FILENO
,&ch
,1) != 1) return ' ';