From dbe124108b7a3529feeeba91339928c4ac737072 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 23 Jun 2015 14:02:12 -0700 Subject: 1631 - update html versions Html is a little more readable thanks to feedback from J David Eisenberg (https://news.ycombinator.com/item?id=9766330), in particular the suggestion to use https://addons.mozilla.org/En-us/firefox/addon/wcag-contrast-checker. --- html/070display.cc.html | 109 ++++++++++++++++++++++++++++-------------------- 1 file changed, 64 insertions(+), 45 deletions(-) (limited to 'html/070display.cc.html') diff --git a/html/070display.cc.html b/html/070display.cc.html index 9b31520f..24b460f0 100644 --- a/html/070display.cc.html +++ b/html/070display.cc.html @@ -12,14 +12,13 @@ @@ -32,10 +31,10 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; }
-//: Take charge of the text-mode display and keyboard.
+//: Take charge of the text-mode display and console.
 
-// uncomment to debug console programs
 :(before "End Globals")
+// uncomment to debug console programs
 //? ofstream LOG("log.txt");
 
 //:: Display management
@@ -44,23 +43,23 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; }
 long long int Display_row = 0, Display_column = 0;
 
 :(before "End Primitive Recipe Declarations")
-SWITCH_TO_DISPLAY,
+OPEN_CONSOLE,
 :(before "End Primitive Recipe Numbers")
-Recipe_number["switch-to-display"] = SWITCH_TO_DISPLAY;
-//? cerr << "switch-to-display: " << SWITCH_TO_DISPLAY << '\n'; //? 1
+Recipe_number["open-console"] = OPEN_CONSOLE;
+//? cerr << "open-console: " << OPEN_CONSOLE << '\n'; //? 1
 :(before "End Primitive Recipe Implementations")
-case SWITCH_TO_DISPLAY: {
+case OPEN_CONSOLE: {
   tb_init();
   Display_row = Display_column = 0;
   break;
 }
 
 :(before "End Primitive Recipe Declarations")
-RETURN_TO_CONSOLE,
+CLOSE_CONSOLE,
 :(before "End Primitive Recipe Numbers")
-Recipe_number["return-to-console"] = RETURN_TO_CONSOLE;
+Recipe_number["close-console"] = CLOSE_CONSOLE;
 :(before "End Primitive Recipe Implementations")
-case RETURN_TO_CONSOLE: {
+case CLOSE_CONSOLE: {
   tb_shutdown();
 //?   Trace_stream->dump_layer = "all"; //? 1
   break;
@@ -253,53 +252,73 @@ case DISPLAY_HEIGHT: {
   break;
 }
 
-//:: Keyboard management
+//:: Keyboard/mouse management
 
 :(before "End Primitive Recipe Declarations")
-WAIT_FOR_KEY_FROM_KEYBOARD,
+WAIT_FOR_SOME_INTERACTION,
 :(before "End Primitive Recipe Numbers")
-Recipe_number["wait-for-key-from-keyboard"] = WAIT_FOR_KEY_FROM_KEYBOARD;
+Recipe_number["wait-for-some-interaction"] = WAIT_FOR_SOME_INTERACTION;
 :(before "End Primitive Recipe Implementations")
-case WAIT_FOR_KEY_FROM_KEYBOARD: {
+case WAIT_FOR_SOME_INTERACTION: {
   tb_event event;
-  do {
-    tb_poll_event(&event);
-  } while (event.type != TB_EVENT_KEY);
-  long long int result = event.key ? event.key : event.ch;
-  if (result == TB_KEY_CTRL_C) tb_shutdown(), exit(1);
-  if (result == TB_KEY_BACKSPACE2) result = TB_KEY_BACKSPACE;
-  if (result == TB_KEY_CARRIAGE_RETURN) result = TB_KEY_NEWLINE;
-  products.resize(1);
-  products.at(0).push_back(result);
+  tb_poll_event(&event);
   break;
 }
 
 :(before "End Primitive Recipe Declarations")
-READ_KEY_FROM_KEYBOARD,
+CHECK_FOR_INTERACTION,
 :(before "End Primitive Recipe Numbers")
-Recipe_number["read-key-from-keyboard"] = READ_KEY_FROM_KEYBOARD;
+Recipe_number["check-for-interaction"] = CHECK_FOR_INTERACTION;
 :(before "End Primitive Recipe Implementations")
-case READ_KEY_FROM_KEYBOARD: {
+case CHECK_FOR_INTERACTION: {
+  products.resize(2);  // result and status
   tb_event event;
   int event_type = tb_peek_event(&event, 5/*ms*/);
-  long long int result = 0;
-  long long int found = false;
-//?   cerr << event_type << '\n'; //? 1
+  if (event_type == TB_EVENT_KEY && event.ch) {
+    products.at(0).push_back(/*text event*/0);
+    products.at(0).push_back(event.ch);
+    products.at(0).push_back(0);
+    products.at(0).push_back(0);
+    products.at(1).push_back(/*found*/true);
+    break;
+  }
+  // treat keys within ascii as unicode characters
+  if (event_type == TB_EVENT_KEY && event.key < 0xff) {
+    products.at(0).push_back(/*text event*/0);
+    if (event.key == TB_KEY_CTRL_C) tb_shutdown(), exit(1);
+    if (event.key == TB_KEY_BACKSPACE2) event.key = TB_KEY_BACKSPACE;
+    if (event.key == TB_KEY_CARRIAGE_RETURN) event.key = TB_KEY_NEWLINE;
+    products.at(0).push_back(event.key);
+    products.at(0).push_back(0);
+    products.at(0).push_back(0);
+    products.at(1).push_back(/*found*/true);
+    break;
+  }
+  // keys outside ascii aren't unicode characters but arbitrary termbox inventions
   if (event_type == TB_EVENT_KEY) {
-    result = event.key ? event.key : event.ch;
-    if (result == TB_KEY_CTRL_C) tb_shutdown(), exit(1);
-    if (result == TB_KEY_BACKSPACE2) result = TB_KEY_BACKSPACE;
-    if (result == TB_KEY_CARRIAGE_RETURN) result = TB_KEY_NEWLINE;
-    found = true;
+    products.at(0).push_back(/*keycode event*/1);
+    products.at(0).push_back(event.key);
+    products.at(0).push_back(0);
+    products.at(0).push_back(0);
+    products.at(1).push_back(/*found*/true);
+    break;
   }
-  products.resize(2);
-  products.at(0).push_back(result);
-  products.at(1).push_back(found);
+  if (event_type == TB_EVENT_MOUSE) {
+    products.at(0).push_back(/*mouse event*/1);
+    products.at(0).push_back(event.key);  // which button, etc.
+    products.at(0).push_back(event.y);  // row
+    products.at(0).push_back(event.x);  // column
+    products.at(1).push_back(/*found*/true);
+    break;
+  }
+  // ignore TB_EVENT_RESIZE events for now
+  products.at(0).push_back(0);
+  products.at(0).push_back(0);
+  products.at(0).push_back(0);
+  products.at(0).push_back(0);
+  products.at(1).push_back(/*found*/false);
   break;
 }
-
-:(before "End Includes")
-#include"termbox/termbox.h"
 
-- cgit 1.4.1-2-gfad0