2016-08-09 23:33:30 +00:00
//: Take raw control of the text-mode display and console, putting it in
//: 'console' mode rather than the usual automatically-scrolling 'typewriter'
//: mode.
2015-04-20 19:35:47 +00:00
2015-04-21 00:35:32 +00:00
//:: Display management
2015-04-23 00:15:19 +00:00
: ( before " End Globals " )
2016-08-29 00:06:49 +00:00
int Display_row = 0 ;
int Display_column = 0 ;
2015-04-23 00:15:19 +00:00
2016-09-08 19:12:06 +00:00
: ( before " End Includes " )
# define CHECK_SCREEN \
if ( ! tb_is_active ( ) ) { \
if ( Run_tests ) \
raise < < maybe ( current_recipe_name ( ) ) < < " tried to print to real screen in a test! \n " < < end ( ) ; \
2016-10-27 16:06:17 +00:00
else \
raise < < maybe ( current_recipe_name ( ) ) < < " tried to print to real screen before 'open-console' or after 'close-console' \n " < < end ( ) ; \
2016-09-08 19:12:06 +00:00
break ; \
}
# define CHECK_CONSOLE \
if ( ! tb_is_active ( ) ) { \
if ( Run_tests ) \
raise < < maybe ( current_recipe_name ( ) ) < < " tried to read event from real keyboard/mouse in a test! \n " < < end ( ) ; \
2016-10-27 16:06:17 +00:00
else \
raise < < maybe ( current_recipe_name ( ) ) < < " tried to read event from real keyboard/mouse before 'open-console' or after 'close-console' \n " < < end ( ) ; \
2016-09-08 19:12:06 +00:00
break ; \
}
2015-04-20 19:35:47 +00:00
: ( before " End Primitive Recipe Declarations " )
2015-06-22 06:53:17 +00:00
OPEN_CONSOLE ,
2015-04-20 19:35:47 +00:00
: ( before " End Primitive Recipe Numbers " )
2015-11-06 19:06:58 +00:00
put ( Recipe_ordinal , " open-console " , OPEN_CONSOLE ) ;
2015-10-02 00:30:14 +00:00
: ( before " End Primitive Recipe Checks " )
case OPEN_CONSOLE : {
break ;
}
2015-04-20 19:35:47 +00:00
: ( before " End Primitive Recipe Implementations " )
2015-06-22 06:53:17 +00:00
case OPEN_CONSOLE : {
2015-04-23 00:15:19 +00:00
tb_init ( ) ;
2017-05-18 16:44:37 +00:00
std : : setvbuf ( stdout , NULL , _IONBF , 0 ) ; // disable buffering in cout
2015-04-23 00:15:19 +00:00
Display_row = Display_column = 0 ;
2016-03-14 03:26:47 +00:00
int width = tb_width ( ) ;
int height = tb_height ( ) ;
2017-06-10 21:36:38 +00:00
if ( width > 222 | | height > 222 ) {
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 ( ) ;
exit ( 1 ) ;
}
2015-04-20 19:35:47 +00:00
break ;
}
: ( before " End Primitive Recipe Declarations " )
2015-06-22 06:53:17 +00:00
CLOSE_CONSOLE ,
2015-04-20 19:35:47 +00:00
: ( before " End Primitive Recipe Numbers " )
2015-11-06 19:06:58 +00:00
put ( Recipe_ordinal , " close-console " , CLOSE_CONSOLE ) ;
2015-10-02 00:30:14 +00:00
: ( before " End Primitive Recipe Checks " )
case CLOSE_CONSOLE : {
break ;
}
2015-04-20 19:35:47 +00:00
: ( before " End Primitive Recipe Implementations " )
2015-06-22 06:53:17 +00:00
case CLOSE_CONSOLE : {
2015-04-23 00:15:19 +00:00
tb_shutdown ( ) ;
2015-04-20 19:35:47 +00:00
break ;
}
2015-04-21 00:35:32 +00:00
: ( before " End Primitive Recipe Declarations " )
CLEAR_DISPLAY ,
: ( before " End Primitive Recipe Numbers " )
2015-11-06 19:06:58 +00:00
put ( Recipe_ordinal , " clear-display " , CLEAR_DISPLAY ) ;
2015-10-02 00:30:14 +00:00
: ( before " End Primitive Recipe Checks " )
case CLEAR_DISPLAY : {
break ;
}
2015-04-21 00:35:32 +00:00
: ( before " End Primitive Recipe Implementations " )
case CLEAR_DISPLAY : {
2016-09-08 19:12:06 +00:00
CHECK_SCREEN ;
2015-04-23 00:15:19 +00:00
tb_clear ( ) ;
Display_row = Display_column = 0 ;
2015-04-21 00:35:32 +00:00
break ;
}
: ( before " End Primitive Recipe Declarations " )
PRINT_CHARACTER_TO_DISPLAY ,
: ( before " End Primitive Recipe Numbers " )
2015-11-06 19:06:58 +00:00
put ( Recipe_ordinal , " print-character-to-display " , PRINT_CHARACTER_TO_DISPLAY ) ;
2015-10-02 00:30:14 +00:00
: ( before " End Primitive Recipe Checks " )
case PRINT_CHARACTER_TO_DISPLAY : {
2015-10-07 05:15:45 +00:00
if ( inst . ingredients . empty ( ) ) {
2017-05-26 23:43:18 +00:00
raise < < maybe ( get ( Recipe , r ) . name ) < < " 'print-character-to-display' requires at least one ingredient, but got ' " < < to_original_string ( inst ) < < " ' \n " < < end ( ) ;
2015-10-07 05:15:45 +00:00
break ;
}
if ( ! is_mu_number ( inst . ingredients . at ( 0 ) ) ) {
2016-05-21 05:09:06 +00:00
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 ( ) ;
2015-10-07 05:15:45 +00:00
break ;
}
if ( SIZE ( inst . ingredients ) > 1 ) {
if ( ! is_mu_number ( inst . ingredients . at ( 1 ) ) ) {
2016-05-21 05:09:06 +00:00
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 ( ) ;
2015-10-07 05:15:45 +00:00
break ;
}
}
if ( SIZE ( inst . ingredients ) > 2 ) {
if ( ! is_mu_number ( inst . ingredients . at ( 2 ) ) ) {
2016-05-21 05:09:06 +00:00
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 ( ) ;
2015-10-07 05:15:45 +00:00
break ;
}
}
2015-10-02 00:30:14 +00:00
break ;
}
2015-04-21 00:35:32 +00:00
: ( before " End Primitive Recipe Implementations " )
case PRINT_CHARACTER_TO_DISPLAY : {
2016-09-08 19:12:06 +00:00
CHECK_SCREEN ;
2015-04-23 00:15:19 +00:00
int h = tb_height ( ) , w = tb_width ( ) ;
2016-03-14 03:26:47 +00:00
int height = ( h > = 0 ) ? h : 0 ;
int width = ( w > = 0 ) ? w : 0 ;
int c = ingredients . at ( 0 ) . at ( 0 ) ;
2017-11-10 08:47:45 +00:00
int color = TB_WHITE ;
2015-07-05 03:46:50 +00:00
if ( SIZE ( ingredients ) > 1 ) {
color = ingredients . at ( 1 ) . at ( 0 ) ;
}
int bg_color = TB_BLACK ;
if ( SIZE ( ingredients ) > 2 ) {
bg_color = ingredients . at ( 2 ) . at ( 0 ) ;
if ( bg_color = = 0 ) bg_color = TB_BLACK ;
}
2017-05-19 07:09:18 +00:00
tb_print ( c , color , bg_color ) ;
2017-05-18 16:44:37 +00:00
// track row and column, mimicking what happens on screen
if ( c = = ' \n ' ) {
if ( Display_row < height - 1 ) + + Display_row ; // otherwise we scroll and Display_row remains unchanged
2015-04-23 00:15:19 +00:00
}
2017-05-18 16:44:37 +00:00
else if ( c = = ' \r ' ) {
Display_column = 0 ;
2015-05-10 15:34:12 +00:00
}
2017-05-18 16:44:37 +00:00
else if ( c = = ' \b ' ) {
if ( Display_column > 0 ) - - Display_column ;
}
else {
2015-05-10 15:34:12 +00:00
+ + Display_column ;
2017-05-18 16:44:37 +00:00
if ( Display_column > = width ) {
Display_column = 0 ;
if ( Display_row < height - 1 ) + + Display_row ;
}
2015-04-23 00:15:19 +00:00
}
2015-04-21 00:35:32 +00:00
break ;
}
: ( before " End Primitive Recipe Declarations " )
CURSOR_POSITION_ON_DISPLAY ,
: ( before " End Primitive Recipe Numbers " )
2015-11-06 19:06:58 +00:00
put ( Recipe_ordinal , " cursor-position-on-display " , CURSOR_POSITION_ON_DISPLAY ) ;
2015-10-02 00:30:14 +00:00
: ( before " End Primitive Recipe Checks " )
case CURSOR_POSITION_ON_DISPLAY : {
break ;
}
2015-04-21 00:35:32 +00:00
: ( before " End Primitive Recipe Implementations " )
case CURSOR_POSITION_ON_DISPLAY : {
2016-09-08 19:12:06 +00:00
CHECK_SCREEN ;
2015-05-07 22:06:53 +00:00
products . resize ( 2 ) ;
products . at ( 0 ) . push_back ( Display_row ) ;
products . at ( 1 ) . push_back ( Display_column ) ;
2015-04-21 00:35:32 +00:00
break ;
}
: ( before " End Primitive Recipe Declarations " )
MOVE_CURSOR_ON_DISPLAY ,
: ( before " End Primitive Recipe Numbers " )
2015-11-06 19:06:58 +00:00
put ( Recipe_ordinal , " move-cursor-on-display " , MOVE_CURSOR_ON_DISPLAY ) ;
2015-10-02 00:30:14 +00:00
: ( before " End Primitive Recipe Checks " )
2015-04-21 00:35:32 +00:00
case MOVE_CURSOR_ON_DISPLAY : {
2015-10-02 00:30:14 +00:00
if ( SIZE ( inst . ingredients ) ! = 2 ) {
2017-05-26 23:43:18 +00:00
raise < < maybe ( get ( Recipe , r ) . name ) < < " 'move-cursor-on-display' requires two ingredients, but got ' " < < to_original_string ( inst ) < < " ' \n " < < end ( ) ;
2015-07-25 21:19:28 +00:00
break ;
}
2015-10-07 05:15:45 +00:00
if ( ! is_mu_number ( inst . ingredients . at ( 0 ) ) ) {
2016-05-21 05:09:06 +00:00
raise < < maybe ( get ( Recipe , r ) . name ) < < " first ingredient of 'move-cursor-on-display' should be a row number, but got ' " < < inst . ingredients . at ( 0 ) . original_string < < " ' \n " < < end ( ) ;
2015-07-25 21:19:28 +00:00
break ;
}
2015-10-07 05:15:45 +00:00
if ( ! is_mu_number ( inst . ingredients . at ( 1 ) ) ) {
2016-05-21 05:09:06 +00:00
raise < < maybe ( get ( Recipe , r ) . name ) < < " second ingredient of 'move-cursor-on-display' should be a column number, but got ' " < < inst . ingredients . at ( 1 ) . original_string < < " ' \n " < < end ( ) ;
2015-07-25 21:19:28 +00:00
break ;
}
2015-10-02 00:30:14 +00:00
break ;
}
: ( before " End Primitive Recipe Implementations " )
case MOVE_CURSOR_ON_DISPLAY : {
2016-09-08 19:12:06 +00:00
CHECK_SCREEN ;
2015-10-02 00:30:14 +00:00
Display_row = ingredients . at ( 0 ) . at ( 0 ) ;
2015-05-13 00:00:56 +00:00
Display_column = ingredients . at ( 1 ) . at ( 0 ) ;
2015-04-23 00:15:19 +00:00
tb_set_cursor ( Display_column , Display_row ) ;
2015-04-21 00:35:32 +00:00
break ;
}
2015-04-29 04:28:34 +00:00
: ( before " End Primitive Recipe Declarations " )
MOVE_CURSOR_DOWN_ON_DISPLAY ,
: ( before " End Primitive Recipe Numbers " )
2015-11-06 19:06:58 +00:00
put ( Recipe_ordinal , " move-cursor-down-on-display " , MOVE_CURSOR_DOWN_ON_DISPLAY ) ;
2015-10-02 00:30:14 +00:00
: ( before " End Primitive Recipe Checks " )
case MOVE_CURSOR_DOWN_ON_DISPLAY : {
break ;
}
2015-04-29 04:28:34 +00:00
: ( before " End Primitive Recipe Implementations " )
case MOVE_CURSOR_DOWN_ON_DISPLAY : {
2016-09-08 19:12:06 +00:00
CHECK_SCREEN ;
2015-05-10 15:34:12 +00:00
int h = tb_height ( ) ;
2016-03-14 03:26:47 +00:00
int height = ( h > = 0 ) ? h : 0 ;
2015-05-10 15:34:12 +00:00
if ( Display_row < height - 1 ) {
2016-08-26 20:40:19 +00:00
+ + Display_row ;
2015-05-10 15:34:12 +00:00
tb_set_cursor ( Display_column , Display_row ) ;
}
2015-04-29 04:28:34 +00:00
break ;
}
: ( before " End Primitive Recipe Declarations " )
MOVE_CURSOR_UP_ON_DISPLAY ,
: ( before " End Primitive Recipe Numbers " )
2015-11-06 19:06:58 +00:00
put ( Recipe_ordinal , " move-cursor-up-on-display " , MOVE_CURSOR_UP_ON_DISPLAY ) ;
2015-10-02 00:30:14 +00:00
: ( before " End Primitive Recipe Checks " )
case MOVE_CURSOR_UP_ON_DISPLAY : {
break ;
}
2015-04-29 04:28:34 +00:00
: ( before " End Primitive Recipe Implementations " )
case MOVE_CURSOR_UP_ON_DISPLAY : {
2016-09-08 19:12:06 +00:00
CHECK_SCREEN ;
2015-05-10 15:34:12 +00:00
if ( Display_row > 0 ) {
2016-08-26 20:40:19 +00:00
- - Display_row ;
2015-05-10 15:34:12 +00:00
tb_set_cursor ( Display_column , Display_row ) ;
}
2015-04-29 04:28:34 +00:00
break ;
}
: ( before " End Primitive Recipe Declarations " )
MOVE_CURSOR_RIGHT_ON_DISPLAY ,
: ( before " End Primitive Recipe Numbers " )
2015-11-06 19:06:58 +00:00
put ( Recipe_ordinal , " move-cursor-right-on-display " , MOVE_CURSOR_RIGHT_ON_DISPLAY ) ;
2015-10-02 00:30:14 +00:00
: ( before " End Primitive Recipe Checks " )
case MOVE_CURSOR_RIGHT_ON_DISPLAY : {
break ;
}
2015-04-29 04:28:34 +00:00
: ( before " End Primitive Recipe Implementations " )
case MOVE_CURSOR_RIGHT_ON_DISPLAY : {
2016-09-08 19:12:06 +00:00
CHECK_SCREEN ;
2015-05-10 15:34:12 +00:00
int w = tb_width ( ) ;
2016-03-14 03:26:47 +00:00
int width = ( w > = 0 ) ? w : 0 ;
2015-05-10 15:34:12 +00:00
if ( Display_column < width - 1 ) {
2016-08-26 20:40:19 +00:00
+ + Display_column ;
2015-05-10 15:34:12 +00:00
tb_set_cursor ( Display_column , Display_row ) ;
}
2015-04-29 04:28:34 +00:00
break ;
}
: ( before " End Primitive Recipe Declarations " )
MOVE_CURSOR_LEFT_ON_DISPLAY ,
: ( before " End Primitive Recipe Numbers " )
2015-11-06 19:06:58 +00:00
put ( Recipe_ordinal , " move-cursor-left-on-display " , MOVE_CURSOR_LEFT_ON_DISPLAY ) ;
2015-10-02 00:30:14 +00:00
: ( before " End Primitive Recipe Checks " )
case MOVE_CURSOR_LEFT_ON_DISPLAY : {
break ;
}
2015-04-29 04:28:34 +00:00
: ( before " End Primitive Recipe Implementations " )
case MOVE_CURSOR_LEFT_ON_DISPLAY : {
2016-09-08 19:12:06 +00:00
CHECK_SCREEN ;
2015-05-10 15:34:12 +00:00
if ( Display_column > 0 ) {
2016-08-26 20:40:19 +00:00
- - Display_column ;
2015-05-10 15:34:12 +00:00
tb_set_cursor ( Display_column , Display_row ) ;
}
2015-04-29 04:28:34 +00:00
break ;
}
2016-08-09 23:42:11 +00:00
//: 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 ( ) {
2016-08-26 20:40:19 +00:00
if ( Display_row < tb_height ( ) - 1 ) + + Display_row ;
2016-08-10 03:09:58 +00:00
else Display_row = 0 ;
2016-08-09 23:42:11 +00:00
Display_column = 0 ;
tb_set_cursor ( Display_column , Display_row ) ;
}
2015-06-08 19:25:25 +00:00
: ( before " End Primitive Recipe Declarations " )
DISPLAY_WIDTH ,
: ( before " End Primitive Recipe Numbers " )
2015-11-06 19:06:58 +00:00
put ( Recipe_ordinal , " display-width " , DISPLAY_WIDTH ) ;
2015-10-02 00:30:14 +00:00
: ( before " End Primitive Recipe Checks " )
case DISPLAY_WIDTH : {
break ;
}
2015-06-08 19:25:25 +00:00
: ( before " End Primitive Recipe Implementations " )
case DISPLAY_WIDTH : {
2016-09-08 19:12:06 +00:00
CHECK_SCREEN ;
2015-06-08 19:25:25 +00:00
products . resize ( 1 ) ;
products . at ( 0 ) . push_back ( tb_width ( ) ) ;
break ;
}
: ( before " End Primitive Recipe Declarations " )
DISPLAY_HEIGHT ,
: ( before " End Primitive Recipe Numbers " )
2015-11-06 19:06:58 +00:00
put ( Recipe_ordinal , " display-height " , DISPLAY_HEIGHT ) ;
2015-10-02 00:30:14 +00:00
: ( before " End Primitive Recipe Checks " )
case DISPLAY_HEIGHT : {
break ;
}
2015-06-08 19:25:25 +00:00
: ( before " End Primitive Recipe Implementations " )
case DISPLAY_HEIGHT : {
2016-09-08 19:12:06 +00:00
CHECK_SCREEN ;
2015-06-08 19:25:25 +00:00
products . resize ( 1 ) ;
products . at ( 0 ) . push_back ( tb_height ( ) ) ;
break ;
}
2015-06-22 06:23:57 +00:00
//:: Keyboard/mouse management
2015-04-21 00:35:32 +00:00
2015-04-20 19:35:47 +00:00
: ( before " End Primitive Recipe Declarations " )
2015-06-22 06:23:57 +00:00
WAIT_FOR_SOME_INTERACTION ,
2015-04-20 19:35:47 +00:00
: ( before " End Primitive Recipe Numbers " )
2015-11-06 19:06:58 +00:00
put ( Recipe_ordinal , " wait-for-some-interaction " , WAIT_FOR_SOME_INTERACTION ) ;
2015-10-02 00:30:14 +00:00
: ( before " End Primitive Recipe Checks " )
case WAIT_FOR_SOME_INTERACTION : {
break ;
}
2015-04-20 19:35:47 +00:00
: ( before " End Primitive Recipe Implementations " )
2015-06-22 06:23:57 +00:00
case WAIT_FOR_SOME_INTERACTION : {
2016-09-08 19:12:06 +00:00
CHECK_SCREEN ;
2015-06-08 06:14:02 +00:00
tb_event event ;
2015-06-22 06:23:57 +00:00
tb_poll_event ( & event ) ;
2015-05-04 20:59:56 +00:00
break ;
}
: ( before " End Primitive Recipe Declarations " )
2015-06-22 06:23:57 +00:00
CHECK_FOR_INTERACTION ,
2015-05-04 20:59:56 +00:00
: ( before " End Primitive Recipe Numbers " )
2015-11-06 19:06:58 +00:00
put ( Recipe_ordinal , " check-for-interaction " , CHECK_FOR_INTERACTION ) ;
2015-10-02 00:30:14 +00:00
: ( before " End Primitive Recipe Checks " )
case CHECK_FOR_INTERACTION : {
break ;
}
2015-05-04 20:59:56 +00:00
: ( before " End Primitive Recipe Implementations " )
2015-06-22 06:23:57 +00:00
case CHECK_FOR_INTERACTION : {
2016-09-08 19:12:06 +00:00
CHECK_CONSOLE ;
2015-06-22 06:23:57 +00:00
products . resize ( 2 ) ; // result and status
2015-06-08 06:14:02 +00:00
tb_event event ;
2015-05-04 20:59:56 +00:00
int event_type = tb_peek_event ( & event , 5 /*ms*/ ) ;
2015-06-22 06:23:57 +00:00
if ( event_type = = TB_EVENT_KEY & & event . ch ) {
products . at ( 0 ) . push_back ( /*text event*/ 0 ) ;
products . at ( 0 ) . push_back ( event . ch ) ;
products . at ( 0 ) . push_back ( 0 ) ;
products . at ( 0 ) . push_back ( 0 ) ;
products . at ( 1 ) . push_back ( /*found*/ true ) ;
break ;
}
// treat keys within ascii as unicode characters
if ( event_type = = TB_EVENT_KEY & & event . key < 0xff ) {
products . at ( 0 ) . push_back ( /*text event*/ 0 ) ;
2017-06-10 21:36:38 +00:00
if ( event . key = = TB_KEY_CTRL_C ) exit ( 1 ) ;
2015-06-22 06:23:57 +00:00
if ( event . key = = TB_KEY_BACKSPACE2 ) event . key = TB_KEY_BACKSPACE ;
if ( event . key = = TB_KEY_CARRIAGE_RETURN ) event . key = TB_KEY_NEWLINE ;
products . at ( 0 ) . push_back ( event . key ) ;
products . at ( 0 ) . push_back ( 0 ) ;
products . at ( 0 ) . push_back ( 0 ) ;
products . at ( 1 ) . push_back ( /*found*/ true ) ;
break ;
}
// keys outside ascii aren't unicode characters but arbitrary termbox inventions
2015-05-07 22:06:53 +00:00
if ( event_type = = TB_EVENT_KEY ) {
2015-06-22 06:23:57 +00:00
products . at ( 0 ) . push_back ( /*keycode event*/ 1 ) ;
products . at ( 0 ) . push_back ( event . key ) ;
products . at ( 0 ) . push_back ( 0 ) ;
products . at ( 0 ) . push_back ( 0 ) ;
products . at ( 1 ) . push_back ( /*found*/ true ) ;
break ;
2015-05-04 20:59:56 +00:00
}
2015-06-22 06:23:57 +00:00
if ( event_type = = TB_EVENT_MOUSE ) {
2015-06-24 23:55:18 +00:00
products . at ( 0 ) . push_back ( /*touch event*/ 2 ) ;
2015-06-22 06:23:57 +00:00
products . at ( 0 ) . push_back ( 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 ;
}
2015-08-10 01:44:34 +00:00
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 ) ;
2015-06-22 06:23:57 +00:00
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 ) ;
2015-04-20 19:35:47 +00:00
break ;
}
2015-07-09 04:03:32 +00:00
: ( before " End Primitive Recipe Declarations " )
INTERACTIONS_LEFT ,
: ( before " End Primitive Recipe Numbers " )
2015-11-06 19:06:58 +00:00
put ( Recipe_ordinal , " interactions-left? " , INTERACTIONS_LEFT ) ;
2015-10-02 00:30:14 +00:00
: ( before " End Primitive Recipe Checks " )
case INTERACTIONS_LEFT : {
break ;
}
2015-07-09 04:03:32 +00:00
: ( before " End Primitive Recipe Implementations " )
case INTERACTIONS_LEFT : {
2016-09-08 19:12:06 +00:00
CHECK_CONSOLE ;
2015-07-09 04:03:32 +00:00
products . resize ( 1 ) ;
products . at ( 0 ) . push_back ( tb_event_ready ( ) ) ;
break ;
}
2015-08-12 20:49:51 +00:00
2017-05-10 23:13:25 +00:00
//: hacks to make text-mode apps more responsive under Unix
: ( 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 : {
CHECK_SCREEN ;
int width = tb_width ( ) ;
2017-05-19 07:09:18 +00:00
for ( int x = Display_column ; x < width ; + + x )
2017-05-19 07:56:51 +00:00
tb_print ( ' ' , TB_WHITE , TB_BLACK ) ;
2017-05-10 23:13:25 +00:00
tb_set_cursor ( Display_column , Display_row ) ;
break ;
}
2015-08-12 20:49:51 +00:00
: ( before " End Primitive Recipe Declarations " )
CLEAR_DISPLAY_FROM ,
: ( before " End Primitive Recipe Numbers " )
2015-11-06 19:06:58 +00:00
put ( Recipe_ordinal , " clear-display-from " , CLEAR_DISPLAY_FROM ) ;
2015-10-02 00:30:14 +00:00
: ( before " End Primitive Recipe Checks " )
case CLEAR_DISPLAY_FROM : {
break ;
}
2015-08-12 20:49:51 +00:00
: ( before " End Primitive Recipe Implementations " )
case CLEAR_DISPLAY_FROM : {
2016-09-08 19:12:06 +00:00
CHECK_SCREEN ;
2015-08-12 20:49:51 +00:00
// 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 ( ) ;
2016-10-20 05:10:35 +00:00
for ( /*nada*/ ; row < height ; + + row , column = left ) { // start column from left in every inner loop except first
2017-05-19 07:09:18 +00:00
tb_set_cursor ( column , row ) ;
for ( /*nada*/ ; column < = right ; + + column )
2017-05-19 07:56:51 +00:00
tb_print ( ' ' , TB_WHITE , TB_BLACK ) ;
2015-08-12 20:49:51 +00:00
}
2017-05-19 07:09:18 +00:00
tb_set_cursor ( Display_column , Display_row ) ;
2015-08-12 20:49:51 +00:00
break ;
}