From 9542bb112419d575190a72baf7f964c3e32df223 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 25 Jul 2015 22:15:51 -0700 Subject: 1853 --- html/070display.cc.html | 169 ++++++++++++++++++++++++++---------------------- 1 file changed, 93 insertions(+), 76 deletions(-) (limited to 'html/070display.cc.html') diff --git a/html/070display.cc.html b/html/070display.cc.html index 5ac50f18..e09146cb 100644 --- a/html/070display.cc.html +++ b/html/070display.cc.html @@ -14,10 +14,11 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background- body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } .cSpecial { color: #008000; } +.SalientComment { color: #00ffff; } .Constant { color: #00a0a0; } +.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } -.SalientComment { color: #00ffff; } .CommentedCode { color: #6c6c6c; } .Identifier { color: #804000; } --> @@ -40,16 +41,15 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } //:: Display management :(before "End Globals") -long long int Display_row = 0, Display_column = 0; -bool Autodisplay = true; +long long int Display_row = 0, Display_column = 0; +bool Autodisplay = true; :(before "End Primitive Recipe Declarations") OPEN_CONSOLE, :(before "End Primitive Recipe Numbers") Recipe_ordinal["open-console"] = OPEN_CONSOLE; -//? cerr << "open-console: " << OPEN_CONSOLE << '\n'; //? 1 :(before "End Primitive Recipe Implementations") -case OPEN_CONSOLE: { +case OPEN_CONSOLE: { tb_init(); Display_row = Display_column = 0; break; @@ -60,7 +60,7 @@ CLOSE_CONSOLE, :(before "End Primitive Recipe Numbers") Recipe_ordinal["close-console"] = CLOSE_CONSOLE; :(before "End Primitive Recipe Implementations") -case CLOSE_CONSOLE: { +case CLOSE_CONSOLE: { tb_shutdown(); //? Trace_stream->dump_layer = "all"; //? 1 break; @@ -74,7 +74,7 @@ CLEAR_DISPLAY, :(before "End Primitive Recipe Numbers") Recipe_ordinal["clear-display"] = CLEAR_DISPLAY; :(before "End Primitive Recipe Implementations") -case CLEAR_DISPLAY: { +case CLEAR_DISPLAY: { tb_clear(); Display_row = Display_column = 0; break; @@ -85,13 +85,13 @@ CLEAR_LINE_ON_DISPLAY, :(before "End Primitive Recipe Numbers") Recipe_ordinal["clear-line-on-display"] = CLEAR_LINE_ON_DISPLAY; :(before "End Primitive Recipe Implementations") -case CLEAR_LINE_ON_DISPLAY: { - long long int width = tb_width(); - for (long long int x = Display_column; x < width; ++x) { +case CLEAR_LINE_ON_DISPLAY: { + long long int width = tb_width(); + for (long long int x = Display_column; x < width; ++x) { tb_change_cell(x, Display_row, ' ', TB_WHITE, TB_BLACK); } tb_set_cursor(Display_column, Display_row); - if (Autodisplay) tb_present(); + if (Autodisplay) tb_present(); break; } @@ -100,53 +100,60 @@ PRINT_CHARACTER_TO_DISPLAY, :(before "End Primitive Recipe Numbers") Recipe_ordinal["print-character-to-display"] = PRINT_CHARACTER_TO_DISPLAY; :(before "End Primitive Recipe Implementations") -case PRINT_CHARACTER_TO_DISPLAY: { - int h=tb_height(), w=tb_width(); - long long int height = (h >= 0) ? h : 0; - long long int width = (w >= 0) ? w : 0; - assert(scalar(ingredients.at(0))); - long long int c = ingredients.at(0).at(0); -//? tb_shutdown(); //? 1 -//? cerr << "AAA " << c << ' ' << (int)'\n' << ' ' << (int)'\r' << '\n'; //? 1 -//? exit(1); //? 1 - int color = TB_BLACK; - if (SIZE(ingredients) > 1) { - assert(scalar(ingredients.at(1))); +case PRINT_CHARACTER_TO_DISPLAY: { + int h=tb_height(), w=tb_width(); + long long int height = (h >= 0) ? h : 0; + long long int width = (w >= 0) ? w : 0; + if (ingredients.empty()) { + raise << current_recipe_name() << ": 'print-character-to-display' requires at least one ingredient, but got " << current_instruction().to_string() << '\n' << end(); + break; + } + if (!scalar(ingredients.at(0))) { + raise << current_recipe_name() << ": first ingredient of 'print-character-to-display' should be a character, but got " << current_instruction().ingredients.at(0).original_string << '\n' << end(); + break; + } + long long int c = ingredients.at(0).at(0); + int color = TB_BLACK; + if (SIZE(ingredients) > 1) { + if (!scalar(ingredients.at(1))) { + raise << current_recipe_name() << ": second ingredient of 'print-character-to-display' should be a foreground color number, but got " << current_instruction().ingredients.at(1).original_string << '\n' << end(); + break; + } color = ingredients.at(1).at(0); -//? tb_shutdown(); //? 1 -//? cerr << "AAA " << color << '\n'; //? 1 -//? exit(1); //? 1 } - int bg_color = TB_BLACK; - if (SIZE(ingredients) > 2) { - assert(scalar(ingredients.at(2))); + int bg_color = TB_BLACK; + if (SIZE(ingredients) > 2) { + if (!scalar(ingredients.at(2))) { + raise << current_recipe_name() << ": third ingredient of 'print-character-to-display' should be a background color number, but got " << current_instruction().ingredients.at(2).original_string << '\n' << end(); + break; + } bg_color = ingredients.at(2).at(0); - if (bg_color == 0) bg_color = TB_BLACK; + if (bg_color == 0) bg_color = TB_BLACK; } tb_change_cell(Display_column, Display_row, c, color, bg_color); - if (c == '\n' || c == '\r') { - if (Display_row < height-1) { + if (c == '\n' || c == '\r') { + if (Display_row < height-1) { Display_column = 0; ++Display_row; tb_set_cursor(Display_column, Display_row); - if (Autodisplay) tb_present(); + if (Autodisplay) tb_present(); } break; } - if (c == '\b') { - if (Display_column > 0) { + if (c == '\b') { + if (Display_column > 0) { tb_change_cell(Display_column-1, Display_row, ' ', color, bg_color); --Display_column; tb_set_cursor(Display_column, Display_row); - if (Autodisplay) tb_present(); + if (Autodisplay) tb_present(); } break; } - if (Display_column < width-1) { + if (Display_column < width-1) { ++Display_column; tb_set_cursor(Display_column, Display_row); } - if (Autodisplay) tb_present(); + if (Autodisplay) tb_present(); break; } @@ -155,7 +162,7 @@ CURSOR_POSITION_ON_DISPLAY, :(before "End Primitive Recipe Numbers") Recipe_ordinal["cursor-position-on-display"] = CURSOR_POSITION_ON_DISPLAY; :(before "End Primitive Recipe Implementations") -case CURSOR_POSITION_ON_DISPLAY: { +case CURSOR_POSITION_ON_DISPLAY: { products.resize(2); products.at(0).push_back(Display_row); products.at(1).push_back(Display_column); @@ -167,13 +174,23 @@ MOVE_CURSOR_ON_DISPLAY, :(before "End Primitive Recipe Numbers") Recipe_ordinal["move-cursor-on-display"] = MOVE_CURSOR_ON_DISPLAY; :(before "End Primitive Recipe Implementations") -case MOVE_CURSOR_ON_DISPLAY: { - assert(scalar(ingredients.at(0))); +case MOVE_CURSOR_ON_DISPLAY: { + if (SIZE(ingredients) != 2) { + raise << current_recipe_name() << ": 'move-cursor-on-display' requires two ingredients, but got " << current_instruction().to_string() << '\n' << end(); + break; + } + if (!scalar(ingredients.at(0))) { + raise << current_recipe_name() << ": first ingredient of 'move-cursor-on-display' should be a row number, but got " << current_instruction().ingredients.at(0).original_string << '\n' << end(); + break; + } Display_row = ingredients.at(0).at(0); - assert(scalar(ingredients.at(1))); + if (!scalar(ingredients.at(1))) { + raise << current_recipe_name() << ": second ingredient of 'move-cursor-on-display' should be a column number, but got " << current_instruction().ingredients.at(1).original_string << '\n' << end(); + break; + } Display_column = ingredients.at(1).at(0); tb_set_cursor(Display_column, Display_row); - if (Autodisplay) tb_present(); + if (Autodisplay) tb_present(); break; } @@ -182,13 +199,13 @@ MOVE_CURSOR_DOWN_ON_DISPLAY, :(before "End Primitive Recipe Numbers") Recipe_ordinal["move-cursor-down-on-display"] = MOVE_CURSOR_DOWN_ON_DISPLAY; :(before "End Primitive Recipe Implementations") -case MOVE_CURSOR_DOWN_ON_DISPLAY: { - int h=tb_height(); - long long int height = (h >= 0) ? h : 0; - if (Display_row < height-1) { +case MOVE_CURSOR_DOWN_ON_DISPLAY: { + int h=tb_height(); + long long int height = (h >= 0) ? h : 0; + if (Display_row < height-1) { Display_row++; tb_set_cursor(Display_column, Display_row); - if (Autodisplay) tb_present(); + if (Autodisplay) tb_present(); } break; } @@ -198,11 +215,11 @@ MOVE_CURSOR_UP_ON_DISPLAY, :(before "End Primitive Recipe Numbers") Recipe_ordinal["move-cursor-up-on-display"] = MOVE_CURSOR_UP_ON_DISPLAY; :(before "End Primitive Recipe Implementations") -case MOVE_CURSOR_UP_ON_DISPLAY: { - if (Display_row > 0) { +case MOVE_CURSOR_UP_ON_DISPLAY: { + if (Display_row > 0) { Display_row--; tb_set_cursor(Display_column, Display_row); - if (Autodisplay) tb_present(); + if (Autodisplay) tb_present(); } break; } @@ -212,13 +229,13 @@ MOVE_CURSOR_RIGHT_ON_DISPLAY, :(before "End Primitive Recipe Numbers") Recipe_ordinal["move-cursor-right-on-display"] = MOVE_CURSOR_RIGHT_ON_DISPLAY; :(before "End Primitive Recipe Implementations") -case MOVE_CURSOR_RIGHT_ON_DISPLAY: { - int w=tb_width(); - long long int width = (w >= 0) ? w : 0; - if (Display_column < width-1) { +case MOVE_CURSOR_RIGHT_ON_DISPLAY: { + int w=tb_width(); + long long int width = (w >= 0) ? w : 0; + if (Display_column < width-1) { Display_column++; tb_set_cursor(Display_column, Display_row); - if (Autodisplay) tb_present(); + if (Autodisplay) tb_present(); } break; } @@ -228,11 +245,11 @@ MOVE_CURSOR_LEFT_ON_DISPLAY, :(before "End Primitive Recipe Numbers") Recipe_ordinal["move-cursor-left-on-display"] = MOVE_CURSOR_LEFT_ON_DISPLAY; :(before "End Primitive Recipe Implementations") -case MOVE_CURSOR_LEFT_ON_DISPLAY: { - if (Display_column > 0) { +case MOVE_CURSOR_LEFT_ON_DISPLAY: { + if (Display_column > 0) { Display_column--; tb_set_cursor(Display_column, Display_row); - if (Autodisplay) tb_present(); + if (Autodisplay) tb_present(); } break; } @@ -242,7 +259,7 @@ DISPLAY_WIDTH, :(before "End Primitive Recipe Numbers") Recipe_ordinal["display-width"] = DISPLAY_WIDTH; :(before "End Primitive Recipe Implementations") -case DISPLAY_WIDTH: { +case DISPLAY_WIDTH: { products.resize(1); products.at(0).push_back(tb_width()); break; @@ -253,7 +270,7 @@ DISPLAY_HEIGHT, :(before "End Primitive Recipe Numbers") Recipe_ordinal["display-height"] = DISPLAY_HEIGHT; :(before "End Primitive Recipe Implementations") -case DISPLAY_HEIGHT: { +case DISPLAY_HEIGHT: { products.resize(1); products.at(0).push_back(tb_height()); break; @@ -264,7 +281,7 @@ HIDE_CURSOR_ON_DISPLAY, :(before "End Primitive Recipe Numbers") Recipe_ordinal["hide-cursor-on-display"] = HIDE_CURSOR_ON_DISPLAY; :(before "End Primitive Recipe Implementations") -case HIDE_CURSOR_ON_DISPLAY: { +case HIDE_CURSOR_ON_DISPLAY: { tb_set_cursor(TB_HIDE_CURSOR, TB_HIDE_CURSOR); break; } @@ -274,7 +291,7 @@ SHOW_CURSOR_ON_DISPLAY, :(before "End Primitive Recipe Numbers") Recipe_ordinal["show-cursor-on-display"] = SHOW_CURSOR_ON_DISPLAY; :(before "End Primitive Recipe Implementations") -case SHOW_CURSOR_ON_DISPLAY: { +case SHOW_CURSOR_ON_DISPLAY: { tb_set_cursor(Display_row, Display_column); break; } @@ -284,7 +301,7 @@ HIDE_DISPLAY, :(before "End Primitive Recipe Numbers") Recipe_ordinal["hide-display"] = HIDE_DISPLAY; :(before "End Primitive Recipe Implementations") -case HIDE_DISPLAY: { +case HIDE_DISPLAY: { Autodisplay = false; break; } @@ -294,7 +311,7 @@ SHOW_DISPLAY, :(before "End Primitive Recipe Numbers") Recipe_ordinal["show-display"] = SHOW_DISPLAY; :(before "End Primitive Recipe Implementations") -case SHOW_DISPLAY: { +case SHOW_DISPLAY: { Autodisplay = true; tb_present(); break; @@ -307,7 +324,7 @@ WAIT_FOR_SOME_INTERACTION, :(before "End Primitive Recipe Numbers") Recipe_ordinal["wait-for-some-interaction"] = WAIT_FOR_SOME_INTERACTION; :(before "End Primitive Recipe Implementations") -case WAIT_FOR_SOME_INTERACTION: { +case WAIT_FOR_SOME_INTERACTION: { tb_event event; tb_poll_event(&event); break; @@ -318,11 +335,11 @@ CHECK_FOR_INTERACTION, :(before "End Primitive Recipe Numbers") Recipe_ordinal["check-for-interaction"] = CHECK_FOR_INTERACTION; :(before "End Primitive Recipe Implementations") -case CHECK_FOR_INTERACTION: { +case CHECK_FOR_INTERACTION: { products.resize(2); // result and status tb_event event; - int event_type = tb_peek_event(&event, 5/*ms*/); - if (event_type == TB_EVENT_KEY && event.ch) { + int event_type = tb_peek_event(&event, 5/*ms*/); + 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); @@ -331,11 +348,11 @@ case CHECK_FOR_INTERACTION: { break; } // treat keys within ascii as unicode characters - if (event_type == TB_EVENT_KEY && event.key < 0xff) { + 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; + 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); @@ -343,7 +360,7 @@ case CHECK_FOR_INTERACTION: { break; } // keys outside ascii aren't unicode characters but arbitrary termbox inventions - if (event_type == TB_EVENT_KEY) { + if (event_type == TB_EVENT_KEY) { products.at(0).push_back(/*keycode event*/1); products.at(0).push_back(event.key); products.at(0).push_back(0); @@ -351,7 +368,7 @@ case CHECK_FOR_INTERACTION: { products.at(1).push_back(/*found*/true); break; } - if (event_type == TB_EVENT_MOUSE) { + if (event_type == TB_EVENT_MOUSE) { //? tb_shutdown(); //? 1 //? cerr << "AAA\n"; //? 1 products.at(0).push_back(/*touch event*/2); @@ -375,7 +392,7 @@ INTERACTIONS_LEFT, :(before "End Primitive Recipe Numbers") Recipe_ordinal["interactions-left?"] = INTERACTIONS_LEFT; :(before "End Primitive Recipe Implementations") -case INTERACTIONS_LEFT: { +case INTERACTIONS_LEFT: { products.resize(1); products.at(0).push_back(tb_event_ready()); break; -- cgit 1.4.1-2-gfad0