diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-08-09 16:42:11 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-08-09 16:48:49 -0700 |
commit | cf3ac87f17aa866d96c8f66735127809431b2cb3 (patch) | |
tree | 9bdf7784ec83e70683a6e86291869514be2a7c5a | |
parent | a97df2ad5dc504fb090b54302fdc41f010d887bf (diff) | |
download | mu-cf3ac87f17aa866d96c8f66735127809431b2cb3.tar.gz |
3163
Experimental: kinda support $print in console mode. It's not perfect and probably will never be, because 'cout' buffers differently from termbox primitives, which can cause console-aware newlines to show up before other (console-oblivious) prints, like in this example program: def main [ open-console $print [abc], 10/newline $print [def], 10/newline wait-for-some-interaction close-console ] And then there's the problem that there's no way for cout to update Display_column. So mixing $print and print will be confusing. Perhaps we should just not mess with Display_* variables inside $print? But then we'll only ever be able to see a single line of $print at a time.
-rw-r--r-- | 029tools.cc | 10 | ||||
-rw-r--r-- | 080display.cc | 13 |
2 files changed, 20 insertions, 3 deletions
diff --git a/029tools.cc b/029tools.cc index 1639ebba..706416a4 100644 --- a/029tools.cc +++ b/029tools.cc @@ -239,10 +239,14 @@ case _PRINT: { for (int i = 0; i < SIZE(ingredients); ++i) { if (is_literal(current_instruction().ingredients.at(i))) { trace(9998, "run") << "$print: " << current_instruction().ingredients.at(i).name << end(); - if (has_property(current_instruction().ingredients.at(i), "newline")) - cout << '\n'; - else + if (!has_property(current_instruction().ingredients.at(i), "newline")) { cout << current_instruction().ingredients.at(i).name; + } + // hack: '$print 10' prints '10', but '$print 10/newline' prints '\n' + // End $print 10/newline Special-cases + else { + cout << '\n'; + } } else { for (int j = 0; j < SIZE(ingredients.at(i)); ++j) { diff --git a/080display.cc b/080display.cc index c05a4f99..2fcdfbf1 100644 --- a/080display.cc +++ b/080display.cc @@ -286,6 +286,19 @@ case MOVE_CURSOR_LEFT_ON_DISPLAY: { break; } +//: as a convenience, make $print mostly work in console mode +:(before "End $print 10/newline Special-cases") +else if (tb_is_active()) { + move_cursor_to_start_of_next_line_on_display(); +} +:(code) +void move_cursor_to_start_of_next_line_on_display() { + if (Display_row < tb_height()-1) Display_row++; + Display_column = 0; + tb_set_cursor(Display_column, Display_row); + if (Autodisplay) tb_present(); +} + :(before "End Primitive Recipe Declarations") DISPLAY_WIDTH, :(before "End Primitive Recipe Numbers") |