//: 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()