//: Take raw control of the text-mode display and console, putting it in //: 'console' mode rather than the usual automatically-scrolling 'typewriter' //: mode. //:: Display management :(before "End Globals") int Display_row = 0; int Display_column = 0; bool Autodisplay = true; :(before "End Primitive Recipe Declarations") OPEN_CONSOLE, :(before "End Primitive Recipe Numbers") put(Recipe_ordinal, "open-console", OPEN_CONSOLE); :(before "End Primitive Recipe Checks") case OPEN_CONSOLE: { break; } :(before "End Primitive Recipe Implementations") case OPEN_CONSOLE: { tb_init(); Display_row = Display_column = 0; int width = tb_width(); int height = tb_height(); if (width > 222 || height > 222) tb_shutdown(); if (width > 222) raise << "sorry, mu doesn't support windows wider than 222 characters in console mode. Please resize your window.\n" << end(); if (height > 222) raise << "sorry, mu doesn't support windows taller than 222 characters in console mode. Please resize your window.\n" << end(); break; } :(before "End Primitive Recipe Declarations") CLOSE_CONSOLE, :(before "End Primitive Recipe Numbers") put(Recipe_ordinal, "close-console", CLOSE_CONSOLE); :(before "End Primitive Recipe Checks") case CLOSE_CONSOLE: { break; } :(before "End Primitive Recipe Implementations") case CLOSE_CONSOLE: { tb_shutdown(); break; } :(before "End Teardown") tb_shutdown(); :(before "End Primitive Recipe Declarations") CLEAR_DISPLAY, :(before "End Primitive Recipe Numbers") put(Recipe_ordinal, "clear-display", CLEAR_DISPLAY); :(before "End Primitive Recipe Checks") case CLEAR_DISPLAY: { break; } :(before "End Primitive Recipe Implementations") case CLEAR_DISPLAY: { tb_clear(); Display_row = Display_column = 0; break; } :(before "End Primitive Recipe Declarations") SYNC_DISPLAY, :(before "End Primitive Recipe Numbers") put(Recipe_ordinal, "sync-display", SYNC_DISPLAY); :(before "End Primitive Recipe Checks") case SYNC_DISPLAY: { break; } :(before "End Primitive Recipe Implementations") case SYNC_DISPLAY: { tb_sync(); break; } :(before "End Primitive Recipe Declarations") CLEAR_LINE_ON_DISPLAY, :(before "End Primitive Recipe Numbers") put(Recipe_ordinal, "clear-line-on-display", CLEAR_LINE_ON_DISPLAY); :(before "End Primitive Recipe Checks") case CLEAR_LINE_ON_DISPLAY: { break; } :(before "End Primitive Recipe Implementations") case CLEAR_LINE_ON_DISPLAY: { int width = tb_width(); for (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(); break; } :(before "End Primitive Recipe Declarations") PRINT_CHARACTER_TO_DISPLAY, :(before "End Primitive Recipe Numbers") put(Recipe_ordinal, "print-character-to-display", PRINT_CHARACTER_TO_DISPLAY); :(before "End Primitive Recipe Checks") case PRINT_CHARACTER_TO_DISPLAY: { if (inst.ingredients.empty()) { raise << maybe(get(Recipe, r).name) << "'print-character-to-display' requires at least one ingredient, but got '" << inst.original_string << "'\n" << end(); break; } if (!is_mu_number(inst.ingredients.at(0))) { raise << maybe(get(Recipe, r).name) << "first ingredient of 'print-character-to-display' should be a character, but got '" << inst.ingredients.at(0).original_string << "'\n" << end(); break; } if (SIZE(inst.ingredients) > 1) { if (!is_mu_number(inst.ingredients.at(1))) { raise << maybe(get(Recipe, r).name) << "second ingredient of 'print-character-to-display' should be a foreground color number, but got '" << inst.ingredients.at(1).original_string << "'\n" << end(); break; } } if (SIZE(inst.ingredients) > 2) { if (!is_mu_number(inst.ingredients.at(2))) { raise << maybe(get(Recipe, r).name) << "third ingredient of 'print-character-to-display' should be a background color number, but got '" << inst.ingredients.at(2).original_string << "'\n" << end(); break; } } break; } :(before "End Primitive Recip
# Test the new parseopt module

import
  parseopt

proc writeHelp() =
  writeLine(stdout, "Usage: tparsopt [options] filename [options]")

proc writeVersion() =
  writeLine(stdout, "Version: 1.0.0")

var
  filename = ""
for kind, key, val in getopt():
  case kind
  of cmdArgument:
    filename = key
  of cmdLongOption, cmdShortOption:
    case key
    of "help", "h": writeHelp()
    of "version", "v": writeVersion()
    else:
      writeLine(stdout, "Unknown command line option: ", key, ": ", val)
  of cmdEnd: assert(false) # cannot happen
if filename == "":
  # no filename has been given, so we show the help:
  writeHelp()
(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; } if (event_type == TB_EVENT_RESIZE) { products.at(0).push_back(/*resize event*/3); products.at(0).push_back(event.w); // width products.at(0).push_back(event.h); // height products.at(0).push_back(0); products.at(1).push_back(/*found*/true); break; } assert(event_type == 0); 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 Primitive Recipe Declarations") INTERACTIONS_LEFT, :(before "End Primitive Recipe Numbers") put(Recipe_ordinal, "interactions-left?", INTERACTIONS_LEFT); :(before "End Primitive Recipe Checks") case INTERACTIONS_LEFT: { break; } :(before "End Primitive Recipe Implementations") case INTERACTIONS_LEFT: { products.resize(1); products.at(0).push_back(tb_event_ready()); break; } //: a hack to make edit.mu more responsive :(before "End Primitive Recipe Declarations") CLEAR_DISPLAY_FROM, :(before "End Primitive Recipe Numbers") put(Recipe_ordinal, "clear-display-from", CLEAR_DISPLAY_FROM); :(before "End Primitive Recipe Checks") case CLEAR_DISPLAY_FROM: { break; } :(before "End Primitive Recipe Implementations") case CLEAR_DISPLAY_FROM: { // todo: error checking int row = ingredients.at(0).at(0); int column = ingredients.at(1).at(0); int left = ingredients.at(2).at(0); int right = ingredients.at(3).at(0); int height=tb_height(); for (; row < height; ++row, column=left) { // start column from left in every inner loop except first for (; column <= right; ++column) { tb_change_cell(column, row, ' ', TB_WHITE, TB_BLACK); } } if (Autodisplay) tb_present(); break; }