Skip to content

Commit

Permalink
3854
Browse files Browse the repository at this point in the history
Revert commits 3824, 3850 and 3852. We'll redo them more carefully.
  • Loading branch information
akkartik committed May 13, 2017
1 parent 8195ed4 commit 0c0d1ea
Show file tree
Hide file tree
Showing 24 changed files with 402 additions and 115 deletions.
91 changes: 89 additions & 2 deletions 080display.cc
Expand Up @@ -7,6 +7,7 @@
:(before "End Globals") :(before "End Globals")
int Display_row = 0; int Display_row = 0;
int Display_column = 0; int Display_column = 0;
bool Autodisplay = true;


:(before "End Includes") :(before "End Includes")
#define CHECK_SCREEN \ #define CHECK_SCREEN \
Expand Down Expand Up @@ -37,7 +38,6 @@ case OPEN_CONSOLE: {
:(before "End Primitive Recipe Implementations") :(before "End Primitive Recipe Implementations")
case OPEN_CONSOLE: { case OPEN_CONSOLE: {
tb_init(); tb_init();
tb_clear();
Display_row = Display_column = 0; Display_row = Display_column = 0;
int width = tb_width(); int width = tb_width();
int height = tb_height(); int height = tb_height();
Expand Down Expand Up @@ -83,6 +83,21 @@ case CLEAR_DISPLAY: {
break; 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: {
CHECK_SCREEN;
tb_sync();
break;
}

:(before "End Primitive Recipe Declarations") :(before "End Primitive Recipe Declarations")
PRINT_CHARACTER_TO_DISPLAY, PRINT_CHARACTER_TO_DISPLAY,
:(before "End Primitive Recipe Numbers") :(before "End Primitive Recipe Numbers")
Expand Down Expand Up @@ -118,7 +133,7 @@ case PRINT_CHARACTER_TO_DISPLAY: {
int height = (h >= 0) ? h : 0; int height = (h >= 0) ? h : 0;
int width = (w >= 0) ? w : 0; int width = (w >= 0) ? w : 0;
int c = ingredients.at(0).at(0); int c = ingredients.at(0).at(0);
int color = TB_WHITE; int color = TB_BLACK;
if (SIZE(ingredients) > 1) { if (SIZE(ingredients) > 1) {
color = ingredients.at(1).at(0); color = ingredients.at(1).at(0);
} }
Expand All @@ -133,6 +148,7 @@ case PRINT_CHARACTER_TO_DISPLAY: {
Display_column = 0; Display_column = 0;
++Display_row; ++Display_row;
tb_set_cursor(Display_column, Display_row); tb_set_cursor(Display_column, Display_row);
if (Autodisplay) tb_present();
} }
break; break;
} }
Expand All @@ -141,13 +157,15 @@ case PRINT_CHARACTER_TO_DISPLAY: {
tb_change_cell(Display_column-1, Display_row, ' ', color, bg_color); tb_change_cell(Display_column-1, Display_row, ' ', color, bg_color);
--Display_column; --Display_column;
tb_set_cursor(Display_column, Display_row); tb_set_cursor(Display_column, Display_row);
if (Autodisplay) tb_present();
} }
break; break;
} }
if (Display_column < width-1) { if (Display_column < width-1) {
++Display_column; ++Display_column;
tb_set_cursor(Display_column, Display_row); tb_set_cursor(Display_column, Display_row);
} }
if (Autodisplay) tb_present();
break; break;
} }


Expand Down Expand Up @@ -194,6 +212,7 @@ case MOVE_CURSOR_ON_DISPLAY: {
Display_row = ingredients.at(0).at(0); Display_row = ingredients.at(0).at(0);
Display_column = ingredients.at(1).at(0); Display_column = ingredients.at(1).at(0);
tb_set_cursor(Display_column, Display_row); tb_set_cursor(Display_column, Display_row);
if (Autodisplay) tb_present();
break; break;
} }


Expand All @@ -213,6 +232,7 @@ case MOVE_CURSOR_DOWN_ON_DISPLAY: {
if (Display_row < height-1) { if (Display_row < height-1) {
++Display_row; ++Display_row;
tb_set_cursor(Display_column, Display_row); tb_set_cursor(Display_column, Display_row);
if (Autodisplay) tb_present();
} }
break; break;
} }
Expand All @@ -231,6 +251,7 @@ case MOVE_CURSOR_UP_ON_DISPLAY: {
if (Display_row > 0) { if (Display_row > 0) {
--Display_row; --Display_row;
tb_set_cursor(Display_column, Display_row); tb_set_cursor(Display_column, Display_row);
if (Autodisplay) tb_present();
} }
break; break;
} }
Expand All @@ -251,6 +272,7 @@ case MOVE_CURSOR_RIGHT_ON_DISPLAY: {
if (Display_column < width-1) { if (Display_column < width-1) {
++Display_column; ++Display_column;
tb_set_cursor(Display_column, Display_row); tb_set_cursor(Display_column, Display_row);
if (Autodisplay) tb_present();
} }
break; break;
} }
Expand All @@ -269,6 +291,7 @@ case MOVE_CURSOR_LEFT_ON_DISPLAY: {
if (Display_column > 0) { if (Display_column > 0) {
--Display_column; --Display_column;
tb_set_cursor(Display_column, Display_row); tb_set_cursor(Display_column, Display_row);
if (Autodisplay) tb_present();
} }
break; break;
} }
Expand All @@ -284,6 +307,7 @@ void move_cursor_to_start_of_next_line_on_display() {
else Display_row = 0; else Display_row = 0;
Display_column = 0; Display_column = 0;
tb_set_cursor(Display_column, Display_row); tb_set_cursor(Display_column, Display_row);
if (Autodisplay) tb_present();
} }


:(before "End Primitive Recipe Declarations") :(before "End Primitive Recipe Declarations")
Expand Down Expand Up @@ -318,6 +342,67 @@ case DISPLAY_HEIGHT: {
break; break;
} }


:(before "End Primitive Recipe Declarations")
HIDE_CURSOR_ON_DISPLAY,
:(before "End Primitive Recipe Numbers")
put(Recipe_ordinal, "hide-cursor-on-display", HIDE_CURSOR_ON_DISPLAY);
:(before "End Primitive Recipe Checks")
case HIDE_CURSOR_ON_DISPLAY: {
break;
}
:(before "End Primitive Recipe Implementations")
case HIDE_CURSOR_ON_DISPLAY: {
CHECK_SCREEN;
tb_set_cursor(TB_HIDE_CURSOR, TB_HIDE_CURSOR);
break;
}

:(before "End Primitive Recipe Declarations")
SHOW_CURSOR_ON_DISPLAY,
:(before "End Primitive Recipe Numbers")
put(Recipe_ordinal, "show-cursor-on-display", SHOW_CURSOR_ON_DISPLAY);
:(before "End Primitive Recipe Checks")
case SHOW_CURSOR_ON_DISPLAY: {
break;
}
:(before "End Primitive Recipe Implementations")
case SHOW_CURSOR_ON_DISPLAY: {
CHECK_SCREEN;
tb_set_cursor(Display_row, Display_column);
break;
}

:(before "End Primitive Recipe Declarations")
HIDE_DISPLAY,
:(before "End Primitive Recipe Numbers")
put(Recipe_ordinal, "hide-display", HIDE_DISPLAY);
:(before "End Primitive Recipe Checks")
case HIDE_DISPLAY: {
break;
}
:(before "End Primitive Recipe Implementations")
case HIDE_DISPLAY: {
CHECK_SCREEN;
Autodisplay = false;
break;
}

:(before "End Primitive Recipe Declarations")
SHOW_DISPLAY,
:(before "End Primitive Recipe Numbers")
put(Recipe_ordinal, "show-display", SHOW_DISPLAY);
:(before "End Primitive Recipe Checks")
case SHOW_DISPLAY: {
break;
}
:(before "End Primitive Recipe Implementations")
case SHOW_DISPLAY: {
CHECK_SCREEN;
Autodisplay = true;
tb_present();
break;
}

//:: Keyboard/mouse management //:: Keyboard/mouse management


:(before "End Primitive Recipe Declarations") :(before "End Primitive Recipe Declarations")
Expand Down Expand Up @@ -441,6 +526,7 @@ case CLEAR_LINE_ON_DISPLAY: {
tb_change_cell(x, Display_row, ' ', TB_WHITE, TB_BLACK); tb_change_cell(x, Display_row, ' ', TB_WHITE, TB_BLACK);
} }
tb_set_cursor(Display_column, Display_row); tb_set_cursor(Display_column, Display_row);
if (Autodisplay) tb_present();
break; break;
} }


Expand All @@ -466,5 +552,6 @@ case CLEAR_DISPLAY_FROM: {
tb_change_cell(column, row, ' ', TB_WHITE, TB_BLACK); tb_change_cell(column, row, ' ', TB_WHITE, TB_BLACK);
} }
} }
if (Autodisplay) tb_present();
break; break;
} }
59 changes: 43 additions & 16 deletions 081print.mu
Expand Up @@ -50,6 +50,13 @@ def clear-screen screen:&:screen -> screen:&:screen [
*screen <- put *screen, cursor-column:offset, 0 *screen <- put *screen, cursor-column:offset, 0
] ]


def sync-screen screen:&:screen -> screen:&:screen [
local-scope
load-ingredients
return-if screen # do nothing for fake screens
sync-display
]

def fake-screen-is-empty? screen:&:screen -> result:bool [ def fake-screen-is-empty? screen:&:screen -> result:bool [
local-scope local-scope
load-ingredients load-ingredients
Expand Down Expand Up @@ -101,27 +108,15 @@ def print screen:&:screen, c:char -> screen:&:screen [
row:num <- get *screen, cursor-row:offset row:num <- get *screen, cursor-row:offset
row <- round row row <- round row
legal?:bool <- greater-or-equal row, 0 legal?:bool <- greater-or-equal row, 0
{ return-unless legal?
break-if legal?
row <- copy 0
}
legal? <- lesser-than row, height legal? <- lesser-than row, height
{ return-unless legal?
break-if legal?
row <- subtract height, 1
}
column:num <- get *screen, cursor-column:offset column:num <- get *screen, cursor-column:offset
column <- round column column <- round column
legal? <- greater-or-equal column, 0 legal? <- greater-or-equal column, 0
{ return-unless legal?
break-if legal?
column <- copy 0
}
legal? <- lesser-than column, width legal? <- lesser-than column, width
{ return-unless legal?
break-if legal?
column <- subtract width, 1
}
#? $print [print-character (], row, [, ], column, [): ], c, 10/newline #? $print [print-character (], row, [, ], column, [): ], c, 10/newline
# special-case: newline # special-case: newline
{ {
Expand Down Expand Up @@ -609,6 +604,38 @@ def screen-height screen:&:screen -> height:num [
height <- display-height height <- display-height
] ]


def hide-cursor screen:&:screen -> screen:&:screen [
local-scope
load-ingredients
return-if screen # fake screen; do nothing
# real screen
hide-cursor-on-display
]

def show-cursor screen:&:screen -> screen:&:screen [
local-scope
load-ingredients
return-if screen # fake screen; do nothing
# real screen
show-cursor-on-display
]

def hide-screen screen:&:screen -> screen:&:screen [
local-scope
load-ingredients
return-if screen # fake screen; do nothing
# real screen
hide-display
]

def show-screen screen:&:screen -> screen:&:screen [
local-scope
load-ingredients
return-if screen # fake screen; do nothing
# real screen
show-display
]

def print screen:&:screen, s:text -> screen:&:screen [ def print screen:&:screen, s:text -> screen:&:screen [
local-scope local-scope
load-ingredients load-ingredients
Expand Down
10 changes: 10 additions & 0 deletions 100trace_browser.cc
Expand Up @@ -276,6 +276,7 @@ bool start_search_editor(search_direction dir) {
tb_change_cell(col, bottom_screen_line, '/', TB_WHITE, TB_BLACK); tb_change_cell(col, bottom_screen_line, '/', TB_WHITE, TB_BLACK);
++col; ++col;
tb_set_cursor(col, bottom_screen_line); tb_set_cursor(col, bottom_screen_line);
tb_present();
string pattern; string pattern;
while (true) { while (true) {
int key = read_key(); int key = read_key();
Expand All @@ -293,21 +294,25 @@ bool start_search_editor(search_direction dir) {
if (col > /*slash*/1) { if (col > /*slash*/1) {
--col; --col;
tb_set_cursor(col, bottom_screen_line); tb_set_cursor(col, bottom_screen_line);
tb_present();
} }
} }
else if (key == TB_KEY_ARROW_RIGHT) { else if (key == TB_KEY_ARROW_RIGHT) {
if (col-/*slash*/1 < SIZE(pattern)) { if (col-/*slash*/1 < SIZE(pattern)) {
++col; ++col;
tb_set_cursor(col, bottom_screen_line); tb_set_cursor(col, bottom_screen_line);
tb_present();
} }
} }
else if (key == TB_KEY_HOME || key == TB_KEY_CTRL_A) { else if (key == TB_KEY_HOME || key == TB_KEY_CTRL_A) {
col = /*skip slash*/1; col = /*skip slash*/1;
tb_set_cursor(col, bottom_screen_line); tb_set_cursor(col, bottom_screen_line);
tb_present();
} }
else if (key == TB_KEY_END || key == TB_KEY_CTRL_E) { else if (key == TB_KEY_END || key == TB_KEY_CTRL_E) {
col = SIZE(pattern)+/*skip slash*/1; col = SIZE(pattern)+/*skip slash*/1;
tb_set_cursor(col, bottom_screen_line); tb_set_cursor(col, bottom_screen_line);
tb_present();
} }
else if (key == TB_KEY_BACKSPACE || key == TB_KEY_BACKSPACE2) { else if (key == TB_KEY_BACKSPACE || key == TB_KEY_BACKSPACE2) {
if (col > /*slash*/1) { if (col > /*slash*/1) {
Expand All @@ -325,6 +330,7 @@ bool start_search_editor(search_direction dir) {
tb_change_cell(SIZE(pattern)+/*skip slash*/1, bottom_screen_line, ' ', TB_WHITE, TB_BLACK); tb_change_cell(SIZE(pattern)+/*skip slash*/1, bottom_screen_line, ' ', TB_WHITE, TB_BLACK);
} }
tb_set_cursor(col, bottom_screen_line); tb_set_cursor(col, bottom_screen_line);
tb_present();
} }
} }
else if (key == TB_KEY_CTRL_K) { else if (key == TB_KEY_CTRL_K) {
Expand All @@ -333,6 +339,7 @@ bool start_search_editor(search_direction dir) {
for (int x = col; x < old_pattern_size+/*slash*/1; ++x) for (int x = col; x < old_pattern_size+/*slash*/1; ++x)
tb_change_cell(x, bottom_screen_line, ' ', TB_WHITE, TB_BLACK); tb_change_cell(x, bottom_screen_line, ' ', TB_WHITE, TB_BLACK);
tb_set_cursor(col, bottom_screen_line); tb_set_cursor(col, bottom_screen_line);
tb_present();
} }
else if (key == TB_KEY_CTRL_U) { else if (key == TB_KEY_CTRL_U) {
int old_pattern_size = SIZE(pattern); int old_pattern_size = SIZE(pattern);
Expand All @@ -342,6 +349,7 @@ bool start_search_editor(search_direction dir) {
for (int x = SIZE(pattern)+/*slash*/1; x < old_pattern_size+/*skip slash*/1; ++x) for (int x = SIZE(pattern)+/*slash*/1; x < old_pattern_size+/*skip slash*/1; ++x)
tb_change_cell(x, bottom_screen_line, ' ', TB_WHITE, TB_BLACK); tb_change_cell(x, bottom_screen_line, ' ', TB_WHITE, TB_BLACK);
tb_set_cursor(/*start of pattern skipping slash*/1, bottom_screen_line); tb_set_cursor(/*start of pattern skipping slash*/1, bottom_screen_line);
tb_present();
} }
else if (key < 128) { // ascii only else if (key < 128) { // ascii only
// update pattern // update pattern
Expand All @@ -352,6 +360,7 @@ bool start_search_editor(search_direction dir) {
tb_change_cell(x, bottom_screen_line, pattern.at(x-/*slash*/1), TB_WHITE, TB_BLACK); tb_change_cell(x, bottom_screen_line, pattern.at(x-/*slash*/1), TB_WHITE, TB_BLACK);
++col; ++col;
tb_set_cursor(col, bottom_screen_line); tb_set_cursor(col, bottom_screen_line);
tb_present();
} }
} }
} }
Expand Down Expand Up @@ -435,6 +444,7 @@ void render() {
render_line(screen_row, "~", /*cursor_line?*/false); render_line(screen_row, "~", /*cursor_line?*/false);
// move cursor back to display row at the end // move cursor back to display row at the end
tb_set_cursor(0, Display_row); tb_set_cursor(0, Display_row);
tb_present();
} }


int lines_hidden(int screen_row) { int lines_hidden(int screen_row) {
Expand Down
10 changes: 6 additions & 4 deletions cannot_write_tests_for
@@ -1,12 +1,14 @@
0. main's ingredients 0. main's ingredients
1. assertion failures or errors inside scenarios 1. assertion failures or errors inside scenarios
2. screen background color 2. screen background color
3. more touch event types 3. has-more-events?
4. sandbox isolation 4. hide/show screen
5. errors in reading/writing files (missing directory, others?) 5. more touch event types
6. has-more-events? 6. sandbox isolation
7. errors in reading/writing files (missing directory, others?)


termbox issues are implementation-specific and not worth testing: termbox issues are implementation-specific and not worth testing:
whether we clear junk from other processes
latency in interpreting low-level escape characters latency in interpreting low-level escape characters


calls to update-cursor are currently duplicated: calls to update-cursor are currently duplicated:
Expand Down
2 changes: 2 additions & 0 deletions edit/001-editor.mu
Expand Up @@ -6,8 +6,10 @@ def main text:text [
local-scope local-scope
load-ingredients load-ingredients
open-console open-console
hide-screen 0/screen
e:&:editor <- new-editor text, 0/left, 5/right e:&:editor <- new-editor text, 0/left, 5/right
render 0/screen, e render 0/screen, e
show-screen 0/screen
wait-for-event 0/console wait-for-event 0/console
close-console close-console
] ]
Expand Down

0 comments on commit 0c0d1ea

Please sign in to comment.