@@ -222,6 +222,7 @@ static void statement_sleep(char **p);
222222static void statement_def (char * * p );
223223static void statement_get (char * * p );
224224static void do_sleep_ticks (double ticks );
225+ static void statement_locate (char * * p );
225226static int function_lookup (const char * name , int len );
226227
227228enum func_code {
@@ -2088,6 +2089,29 @@ static void statement_print(char **p)
20882089 fflush (stdout );
20892090}
20902091
2092+
2093+ static void statement_locate (char * * p )
2094+ {
2095+ // Passed as LOCATE x, y
2096+ struct value vx , vy ;
2097+ int x , y ;
2098+
2099+ // Validation
2100+ vx = eval_expr (p ); ensure_num (& vx );
2101+ skip_spaces (p );
2102+ if (* * p != ',' ) { runtime_error ("LOCATE: expected ',' after X" ); return ; }
2103+ (* p )++ ;
2104+ vy = eval_expr (p ); ensure_num (& vy );
2105+ skip_spaces (p );
2106+
2107+ x = (int )vx .num ; if (x < 0 ) x = 0 ;
2108+ y = (int )vy .num ; if (y < 0 ) y = 0 ;
2109+
2110+ // Move cursor with ANSI: rows/cols are 1-based
2111+ printf ("\033[%d;%dH" , y + 1 , x + 1 );
2112+ fflush (stdout );
2113+ }
2114+
20912115static void statement_input (char * * p )
20922116{
20932117 char prompt [MAX_STR_LEN ];
@@ -2514,6 +2538,11 @@ static void execute_statement(char **p)
25142538 statement_let (p );
25152539 return ;
25162540 }
2541+ if (c == 'L' && starts_with_kw (* p , "LOCATE" )) {
2542+ * p += 6 ;
2543+ statement_locate (p );
2544+ return ;
2545+ }
25172546 if (c == 'G' && starts_with_kw (* p , "GET" )) {
25182547 * p += 3 ;
25192548 statement_get (p );
0 commit comments