00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "aa_config.h"
00029 #include "rConsole.h"
00030 #include "rFont.h"
00031 #include "tConfiguration.h"
00032
00033 #include <stdio.h>
00034 #include <fcntl.h>
00035 #include <sstream>
00036
00037 #if HAVE_UNISTD_H
00038 #include <unistd.h>
00039 #endif
00040 #ifdef WIN32
00041 #include <io.h>
00042 #include <windows.h>
00043
00044
00045 #else
00046 #include <signal.h>
00047 #endif
00048
00049 void rConsole::DoCenterDisplay(const tString &s,REAL timeout,REAL r,REAL g,REAL b){
00050 std::cout << tColoredString::RemoveColors(s) << '\n';
00051 DisplayAtNewline();
00052 }
00053
00054 static int stdin_descriptor;
00055 static bool unblocked = false;
00056
00057 static void sr_HandleSigCont( int signal )
00058 {
00059
00060
00061
00062 sr_Unblock_stdin();
00063 }
00064
00065 void sr_Unblock_stdin(){
00066 #ifndef WIN32
00067 if ( !unblocked )
00068 {
00069 signal( SIGCONT, &sr_HandleSigCont );
00070 }
00071 #endif
00072
00073 unblocked = true;
00074 stdin_descriptor=fileno(stdin);
00075 #ifndef WIN32
00076
00077 {
00078 int flag=fcntl(stdin_descriptor,F_GETFL);
00079 fcntl(stdin_descriptor,F_SETFL,flag | O_NONBLOCK);
00080 }
00081 #endif
00082 }
00083
00084
00085
00086 #define MAXLINE 1000
00087 static char line_in[MAXLINE+2];
00088 static int currentIn=0;
00089
00090 void sr_Read_stdin(){
00091 tConfItemBase::LoadPlayback( true );
00092
00093 if ( !unblocked )
00094 {
00095 return;
00096 }
00097 #ifdef WIN32
00098
00099
00100 HANDLE stdinhandle = GetStdHandle(STD_INPUT_HANDLE);
00101 HANDLE stdouthandle = GetStdHandle(STD_OUTPUT_HANDLE);
00102 bool goon = true;
00103 while (goon)
00104 {
00105 unsigned long reallyread;
00106 INPUT_RECORD input;
00107 PeekConsoleInput(stdinhandle, &input, 1, &reallyread);
00108 if (reallyread > 0)
00109 {
00110 ReadConsoleInput(stdinhandle, &input, 1, &reallyread);
00111 if (input.EventType == KEY_EVENT)
00112 {
00113 char key = input.Event.KeyEvent.uChar.AsciiChar;
00114 DWORD written=0;
00115
00116 if (key && input.Event.KeyEvent.bKeyDown)
00117 {
00118 WriteConsole(stdouthandle, &key, 1, &written, NULL);
00119 line_in[currentIn] = key;
00120
00121 if (key == 13 || currentIn>=MAXLINE-1){
00122 line_in[currentIn]='\n';
00123 line_in[currentIn+1]='\0';
00124 std::stringstream s(line_in);
00125 WriteConsole(stdouthandle, "\n", 1, &written, NULL);
00126 tConfItemBase::LoadAll(s);
00127 currentIn=0;
00128 }
00129 else
00130 currentIn++;
00131 }
00132 }
00133
00134 }
00135 else
00136 goon = false;
00137 }
00138
00139
00140 #else
00141 while ( read(stdin_descriptor,&line_in[currentIn],1)>0){
00142 if (line_in[currentIn]=='\n' || currentIn>=MAXLINE-1)
00143 {
00144 line_in[currentIn+1]='\0';
00145 std::stringstream s(line_in);
00146 tConfItemBase::LoadAll(s);
00147 currentIn=0;
00148 }
00149 else
00150 currentIn++;
00151 }
00152 #endif
00153 }
00154
00155
00156 void rConsole::DisplayAtNewline(){
00157 }
00158