Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Enhancements to text mode console clients
[palacios.git] / linux_usr / v3_cons_sc.c
index 0986a92..9419804 100644 (file)
@@ -117,7 +117,9 @@ static int handle_char_set(struct character_msg * msg) {
            return -1;
        }
 
+        wattron(console.win, COLOR_PAIR(msg->style));
        mvwaddch(console.win, msg->y, msg->x, c);
+        wattroff(console.win, COLOR_PAIR(msg->style));
 
     } else {
        //stdout text display
@@ -285,8 +287,8 @@ struct key_code {
 };
 
 static const struct key_code ascii_to_key_code[] = {             // ASCII Value Serves as Index
-    NO_KEY,         NO_KEY,         NO_KEY,         NO_KEY,      // 0x00 - 0x03
-    NO_KEY,         NO_KEY,         NO_KEY,         { 0x0E, 0 }, // 0x04 - 0x07
+    NO_KEY,         NO_KEY,         {0x50, 0},         {0x48, 0},      // 0x00 - 0x03
+    {0x4B, 0},         {0x4D, 0},         NO_KEY,         { 0x0E, 0 }, // 0x04 - 0x07
     { 0x0E, 0 },    { 0x0F, 0 },    { 0x1C, 0 },    NO_KEY,      // 0x08 - 0x0B
     NO_KEY,         { 0x1C, 0 },    NO_KEY,         NO_KEY,      // 0x0C - 0x0F
     NO_KEY,         NO_KEY,         NO_KEY,         NO_KEY,      // 0x10 - 0x13
@@ -371,7 +373,44 @@ int send_char_to_palacios_as_scancodes(int fd, unsigned char c)
     }
     return 0;
 }
-    
+
+
+#define MIN_TTY_COLS  80
+#define MIN_TTY_ROWS  25
+int check_terminal_size (void)
+{
+    unsigned short n_cols = 0;
+    unsigned short n_rows = 0;
+    struct winsize winsz; 
+
+    ioctl (fileno(stdin), TIOCGWINSZ, &winsz);
+    n_cols = winsz.ws_col;
+    n_rows = winsz.ws_row;
+
+    if (n_cols < MIN_TTY_COLS || n_rows < MIN_TTY_ROWS) {
+        printf ("Your window is not large enough.\n");
+        printf ("It must be at least %dx%d, but yours is %dx%d\n",
+                MIN_TTY_COLS, MIN_TTY_ROWS, n_cols, n_rows);
+    return (-1);
+    }
+
+    /* SUCCESS */
+    return (0);
+}
+
+
+
+static void
+init_colors (void)
+{
+    start_color();
+    int i;
+    for (i = 0; i < 0x100; i++) {
+        init_pair(i, i & 0xf, (i >> 4) & 0xf);
+    }
+}
+
+
 int main(int argc, char* argv[]) {
     int vm_fd;
     int cons_fd;
@@ -381,10 +420,16 @@ int main(int argc, char* argv[]) {
     use_curses = 1;
 
     if (argc < 2) {
-       printf("Usage: ./v3_cons_sc <vm_device>\n");
+       printf("usage: v3_cons_sc <vm_device>\n");
        return -1;
     }
 
+    /* Check for minimum Terminal size at start */
+    if (0 != check_terminal_size()) {
+        printf ("Error: terminal too small!\n");
+        return -1;
+    }
+
     vm_dev = argv[1];
 
     vm_fd = open(vm_dev, O_RDONLY);
@@ -423,6 +468,7 @@ int main(int argc, char* argv[]) {
        scrollok(console.win, 1);
 
        erase();
+    init_colors();
     }
 
     /*
@@ -450,13 +496,6 @@ int main(int argc, char* argv[]) {
 
     //ioctl(STDIN_FILENO, KDSKBMODE, K_RAW);
 
-    if (LINES<25 || COLS<80) { 
-       printf("Your window is not large enough.\nIt must be at least 80x25, but yours is %dx%d\n",COLS,LINES);
-       close(cons_fd);
-       exit(-1);
-    }
-    
-
     while (1) {
        int ret; 
        int bytes_read = 0;
@@ -484,32 +523,32 @@ int main(int argc, char* argv[]) {
            }
        }
 
-       if (FD_ISSET(STDIN_FILENO, &rset)) {
-           unsigned char key = getch();
-
-           if (key == '\\') { // ESC
-               break;
-           } else if (key == '`') {
-               unsigned char sc = 0x44; // F10
-               writeit(cons_fd,sc);
-               sc |= 0x80;
-               writeit(cons_fd,sc);
-            } else if (key == '~') {  // CTRL-C 
-                unsigned char sc;
-                sc = 0x1d;  // left ctrl down
-                writeit(cons_fd,sc);
-                sc = 0x2e; // c down
-               writeit(cons_fd,sc);
-               sc = 0x2e | 0x80;   // c up
-                writeit(cons_fd,sc);
-                sc = 0x1d | 0x80;   // left ctrl up
-                writeit(cons_fd,sc);
-            } else {
-               if (send_char_to_palacios_as_scancodes(cons_fd,key)) {
-                   printf("Error sending key to console\n");
-                   return -1;
-               }
-           }
+    if (FD_ISSET(STDIN_FILENO, &rset)) {
+        unsigned char key = getch();
+
+        if (key == '\\') { // ESC
+            break;
+        } else if (key == '`') {
+            unsigned char sc = 0x44; // F10
+            writeit(cons_fd,sc);
+            sc |= 0x80;
+            writeit(cons_fd,sc);
+        } else if (key == '~') {  // CTRL-C 
+            unsigned char sc;
+            sc = 0x1d;  // left ctrl down
+            writeit(cons_fd,sc);
+            sc = 0x2e; // c down
+            writeit(cons_fd,sc);
+            sc = 0x2e | 0x80;   // c up
+            writeit(cons_fd,sc);
+            sc = 0x1d | 0x80;   // left ctrl up
+            writeit(cons_fd,sc);
+        } else {
+            if (send_char_to_palacios_as_scancodes(cons_fd,key)) {
+                printf("Error sending key to console\n");
+                return -1;
+            }
+        }
            
        }
     }