@@ -75,6 +75,8 @@ getattr(int fd, conmode *t)
75
75
#define SET_LAST_ERROR (0)
76
76
#endif
77
77
78
+ #define CSI "\x1b\x5b"
79
+
78
80
static ID id_getc , id_console , id_close ;
79
81
static ID id_gets , id_flush , id_chomp_bang ;
80
82
@@ -1142,7 +1144,7 @@ static VALUE
1142
1144
console_scroll (VALUE io , int line )
1143
1145
{
1144
1146
if (line ) {
1145
- VALUE s = rb_sprintf ("\x1b[ %d%c" , line < 0 ? - line : line ,
1147
+ VALUE s = rb_sprintf (CSI " %d%c" , line < 0 ? - line : line ,
1146
1148
line < 0 ? 'T' : 'S' );
1147
1149
rb_io_write (io , s );
1148
1150
}
@@ -1204,7 +1206,7 @@ console_goto(VALUE io, VALUE y, VALUE x)
1204
1206
rb_syserr_fail (LAST_ERROR , 0 );
1205
1207
}
1206
1208
#else
1207
- rb_io_write (io , rb_sprintf ("\x1b[ %d;%dH" , NUM2UINT (y )+ 1 , NUM2UINT (x )+ 1 ));
1209
+ rb_io_write (io , rb_sprintf (CSI " %d;%dH" , NUM2UINT (y )+ 1 , NUM2UINT (x )+ 1 ));
1208
1210
#endif
1209
1211
return io ;
1210
1212
}
@@ -1229,8 +1231,8 @@ console_move(VALUE io, int y, int x)
1229
1231
#else
1230
1232
if (x || y ) {
1231
1233
VALUE s = rb_str_new_cstr ("" );
1232
- if (y ) rb_str_catf (s , "\x1b[ %d%c" , y < 0 ? - y : y , y < 0 ? 'A' : 'B' );
1233
- if (x ) rb_str_catf (s , "\x1b[ %d%c" , x < 0 ? - x : x , x < 0 ? 'D' : 'C' );
1234
+ if (y ) rb_str_catf (s , CSI " %d%c" , y < 0 ? - y : y , y < 0 ? 'A' : 'B' );
1235
+ if (x ) rb_str_catf (s , CSI " %d%c" , x < 0 ? - x : x , x < 0 ? 'D' : 'C' );
1234
1236
rb_io_write (io , s );
1235
1237
rb_io_flush (io );
1236
1238
}
@@ -1255,7 +1257,7 @@ console_goto_column(VALUE io, VALUE val)
1255
1257
rb_syserr_fail (LAST_ERROR , 0 );
1256
1258
}
1257
1259
#else
1258
- rb_io_write (io , rb_sprintf ("\x1b[ %dG" , NUM2UINT (val )+ 1 ));
1260
+ rb_io_write (io , rb_sprintf (CSI " %dG" , NUM2UINT (val )+ 1 ));
1259
1261
#endif
1260
1262
return io ;
1261
1263
}
@@ -1290,7 +1292,7 @@ console_erase_line(VALUE io, VALUE val)
1290
1292
constat_clear (h , ws .wAttributes , w , * pos );
1291
1293
return io ;
1292
1294
#else
1293
- rb_io_write (io , rb_sprintf ("\x1b[ %dK" , mode ));
1295
+ rb_io_write (io , rb_sprintf (CSI " %dK" , mode ));
1294
1296
#endif
1295
1297
return io ;
1296
1298
}
@@ -1332,7 +1334,7 @@ console_erase_screen(VALUE io, VALUE val)
1332
1334
}
1333
1335
constat_clear (h , ws .wAttributes , w , * pos );
1334
1336
#else
1335
- rb_io_write (io , rb_sprintf ("\x1b[ %dJ" , mode ));
1337
+ rb_io_write (io , rb_sprintf (CSI " %dJ" , mode ));
1336
1338
#endif
1337
1339
return io ;
1338
1340
}
0 commit comments