diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-06-06 10:38:51 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-06-06 10:48:59 -0700 |
commit | 548cd00ab03cc064e3fa06d23282627759dd9214 (patch) | |
tree | 2ce6a4ebe096dbb1f3ef566dc2ba3ac32f76811d | |
parent | 3434223916977d98cbd767dc8342b03d607dc2a2 (diff) | |
download | mu-548cd00ab03cc064e3fa06d23282627759dd9214.tar.gz |
1535 - repl: less hacky printing of results
-rw-r--r-- | 078run_interactive.cc | 28 | ||||
-rw-r--r-- | repl.mu | 3 |
2 files changed, 26 insertions, 5 deletions
diff --git a/078run_interactive.cc b/078run_interactive.cc index 910147f1..73ebcbe5 100644 --- a/078run_interactive.cc +++ b/078run_interactive.cc @@ -37,13 +37,13 @@ void run_interactive(long long int address) { if (Recipe_number.find("interactive") == Recipe_number.end()) Recipe_number["interactive"] = Next_recipe_number++; if (is_integer(tmp.str())) { - cerr << "=> " << Memory[to_integer(tmp.str())] << '\n'; + print_value_of_location_as_response(to_integer(tmp.str())); ++current_step_index(); return; } //? exit(0); //? 1 if (Name[Recipe_number["interactive"]].find(tmp.str()) != Name[Recipe_number["interactive"]].end()) { - cerr << "=> " << Memory[Name[Recipe_number["interactive"]][tmp.str()]] << '\n'; + print_value_of_location_as_response(Name[Recipe_number["interactive"]][tmp.str()]); ++current_step_index(); return; } @@ -62,6 +62,30 @@ void run_interactive(long long int address) { Current_routine->calls.push_front(call(Recipe_number["interactive"])); } +void print_value_of_location_as_response(long long int address) { + // convert to string + ostringstream out; + out << "=> " << Memory[address]; + string result = out.str(); + // handle regular I/O + if (!tb_is_active()) { + cerr << result << '\n'; + return; + } + // raw I/O; use termbox to print + long long int bound = SIZE(result); + if (bound > tb_width()) bound = tb_width(); + for (long long int i = 0; i < bound; ++i) { + tb_change_cell(i, Display_row, result.at(i), /*computer's color*/245, TB_BLACK); + } + // newline + if (Display_row < tb_height()-1) + ++Display_row; + Display_column = 0; + tb_set_cursor(Display_column, Display_row); + tb_present(); +} + //:: debugging tool :(before "End Primitive Recipe Declarations") diff --git a/repl.mu b/repl.mu index 93d4fd72..3e94b27e 100644 --- a/repl.mu +++ b/repl.mu @@ -19,9 +19,6 @@ recipe color-session [ inst:address:array:character, keyboard:address, screen:address <- read-instruction keyboard:address, screen:address break-unless inst:address:array:character run-interactive inst:address:array:character - # assume run-interactive printed on the current line - move-cursor-down-on-display -#? clear-line-on-display # just to refresh the screen loop } reply keyboard:address/same-as-ingredient:0, screen:address/same-as-ingredient:1 |