r3300 - in trunk/libmutil: include/libmutil source

erik at minisip.org erik at minisip.org
Mon Jun 11 15:36:36 CEST 2007


Author: erik
Date: 2007-06-11 15:36:36 +0200 (Mon, 11 Jun 2007)
New Revision: 3300

Modified:
   trunk/libmutil/include/libmutil/TextUI.h
   trunk/libmutil/source/TextUI.cxx
Log:

 * TextUI: Experimental support for the up/down/left/right keys.



Modified: trunk/libmutil/include/libmutil/TextUI.h
===================================================================
--- trunk/libmutil/include/libmutil/TextUI.h	2007-06-11 13:34:49 UTC (rev 3299)
+++ trunk/libmutil/include/libmutil/TextUI.h	2007-06-11 13:36:36 UTC (rev 3300)
@@ -84,7 +84,12 @@
 	static const int blue;
 	static const int green;
 
+	static const int KEY_LEFT;
+	static const int KEY_RIGHT;
+	static const int KEY_UP;
+	static const int KEY_DOWN;
 
+
 	TextUI();
 	virtual ~TextUI();
 

Modified: trunk/libmutil/source/TextUI.cxx
===================================================================
--- trunk/libmutil/source/TextUI.cxx	2007-06-11 13:34:49 UTC (rev 3299)
+++ trunk/libmutil/source/TextUI.cxx	2007-06-11 13:36:36 UTC (rev 3300)
@@ -63,6 +63,10 @@
 const int TextUI::blue=3;
 const int TextUI::green=4;
 
+const int TextUI::KEY_UP=0x5b41;
+const int TextUI::KEY_DOWN=0x5b42;
+const int TextUI::KEY_RIGHT=0x5b43;
+const int TextUI::KEY_LEFT=0x5b44;
 
 #if defined(_MSC_VER) || defined(WIN32)
 const char *termCodes[]= { "", "", "", "", "" };
@@ -237,18 +241,45 @@
     cout << termCodes[bold]<< input << termCodes[plain] << flush;
 }
 
-void TextUI::guimain(){
-	cout << promptText << "$ "<< flush;
-	while (running){
-		char c = ' ';
-		int err;
+int readChar(){
+	int err;
+	int ret;
+	char tmpc;
 #if defined WIN32 || defined _MSC_VER
-		c= getchar();
+	tmpc = getchar();
+	err=1;
+#else
+	err = read(STDIN_FILENO, &tmpc, 1);
+#endif
+	ret = tmpc;
+
+	if (err!=1)
+		return -1;
+
+	//handle special keys prefixed with escape
+	if (tmpc==27){
+		char c1,c2;
+#if defined WIN32 || defined _MSC_VER
+		c1 = getchar();
+		c2 = getchar();
 		err=1;
 #else
-		err = read(STDIN_FILENO, &c, 1);
+		read(STDIN_FILENO, &c1, 1);
+		err = read(STDIN_FILENO, &c2, 1);
+		if (err!=1)
+			return -1;
 #endif
-		if(err > 0){
+		ret = c1<<8 | c2;
+	}
+
+	return ret;
+}
+
+void TextUI::guimain(){
+	cout << promptText << "$ "<< flush;
+	while (running){
+		int c = readChar();
+		if(c >= 0){
 			keyPressed(c);
 
 
@@ -297,8 +328,8 @@
 				default:
 					//     @A-Z               a-z                  . / 0-9 :           space     .
 					if ( (c>=64 && c<=90) || (c>=97 && c<=122) || (c>=46 && c<=58) || c==32  || c=='-' || c=='_' || c=='.' ){
-						input+=c;
-						cout << termCodes[bold]<< c << termCodes[plain] << flush;
+						input+=(char)c;
+						cout << termCodes[bold]<< (char)c << termCodes[plain] << flush;
 					}
 			}
 		}



More information about the Minisip-devel mailing list