robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
3b00ddb601
master
1local t =require ( 'test.unit.testutil' ) 2local describe , before_each , pending =t . describe , t . before_each , t . pending 3local itp =t . gen_itp ( t . it ) 4local bit =require ( 'bit' ) 5 6--- @class vterm 7--- @field ENC_UTF8 integer 8--- @field VTERM_ATTR_BLINK integer 9--- @field VTERM_ATTR_BOLD integer 10--- @field VTERM_ATTR_FONT integer 11--- @field VTERM_ATTR_ITALIC integer 12--- @field VTERM_ATTR_REVERSE integer 13--- @field VTERM_ATTR_UNDERLINE integer 14--- @field VTERM_BASELINE_RAISE integer 15--- @field VTERM_KEY_ENTER integer 16--- @field VTERM_KEY_FUNCTION_0 integer 17--- @field VTERM_KEY_KP_0 integer 18--- @field VTERM_KEY_NONE integer 19--- @field VTERM_KEY_TAB integer 20--- @field VTERM_KEY_UP integer 21--- @field VTERM_KEY_BACKSPACE integer 22--- @field VTERM_KEY_ESCAPE integer 23--- @field VTERM_KEY_DEL integer 24--- @field VTERM_MOD_ALT integer 25--- @field VTERM_MOD_CTRL integer 26--- @field VTERM_MOD_SHIFT integer 27--- @field parser_apc function 28--- @field parser_csi function 29--- @field parser_dcs function 30--- @field parser_osc function 31--- @field parser_pm function 32--- @field parser_sos function 33--- @field parser_text function 34--- @field print_color function 35--- @field schar_get fun(any, any):integer 36--- @field screen_sb_clear function 37--- @field screen_sb_popline function 38--- @field screen_sb_pushline function 39--- @field selection_query function 40--- @field selection_set function 41--- @field state_erase function 42--- @field state_movecursor function 43--- @field state_moverect function 44--- @field state_pos function 45--- @field state_putglyph function 46--- @field state_sb_clear function 47--- @field state_scrollrect function 48--- @field state_setpenattr function 49--- @field state_settermprop function 50--- @field term_output function 51--- @field utf_ptr2char fun(any):integer 52--- @field utf_ptr2len fun(any):integer 53--- @field vterm_input_write function 54--- @field vterm_keyboard_end_paste function 55--- @field vterm_keyboard_key function 56--- @field vterm_keyboard_start_paste function 57--- @field vterm_keyboard_unichar function 58--- @field vterm_lookup_encoding fun(any, any):any 59--- @field vterm_mouse_button function 60--- @field vterm_mouse_move function 61--- @field vterm_new fun(any, any):any 62--- @field vterm_obtain_screen fun(any):any 63--- @field vterm_obtain_state fun(any): any 64--- @field vterm_output_set_callback function 65--- @field vterm_parser_set_callbacks fun(any, any, any):any 66--- @field vterm_screen_convert_color_to_rgb function 67--- @field vterm_screen_enable_altscreen function 68--- @field vterm_screen_enable_reflow function 69--- @field vterm_screen_get_attrs_extent function 70--- @field vterm_screen_get_cell function 71--- @field vterm_screen_get_text fun(any, any, any, any):any 72--- @field vterm_screen_is_eol fun(any, any):any 73--- @field vterm_screen_reset function 74--- @field vterm_screen_set_callbacks function 75--- @field vterm_set_size function 76--- @field vterm_set_utf8 fun(any, any, any):any 77--- @field vterm_state_focus_in function 78--- @field vterm_state_focus_out function 79--- @field vterm_state_get_cursorpos fun(any, any) 80--- @field vterm_state_get_lineinfo fun(any, any):any 81--- @field vterm_state_get_penattr function 82--- @field vterm_state_reset function 83--- @field vterm_state_set_bold_highbright function 84--- @field vterm_state_set_callbacks function 85--- @field vterm_state_set_selection_callbacks function 86--- @field vterm_state_set_unrecognised_fallbacks function 87local vterm =t . cimport ( 88'./src/nvim/grid.h' , 89'./src/nvim/mbyte.h' , 90'./src/nvim/vterm/encoding.h' , 91'./src/nvim/vterm/keyboard.h' , 92'./src/nvim/vterm/mouse.h' , 93'./src/nvim/vterm/parser.h' , 94'./src/nvim/vterm/pen.h' , 95'./src/nvim/vterm/screen.h' , 96'./src/nvim/vterm/state.h' , 97'./src/nvim/vterm/vterm.h' , 98'./src/nvim/vterm/vterm_internal_defs.h' , 99'./test/unit/fixtures/vterm_test.h' 100) 101 102-- libvterm stores pointers to these callback structs instead of copying them. 103-- Keep the cdata alive for as long as the owning handle exists, and let the 104-- weak-key table release everything once the handle itself becomes unreachable. 105local callback_structs =setmetatable ( {} , { __mode ='k' } ) 106 107---@param owner any 108---@param ... any 109local function keep_callback_structs ( owner , ... ) 110local refs =callback_structs [ owner ] 111if refs == nil then 112refs ={} 113callback_structs [ owner ] =refs 114end 115 116for i =1 , select ( '#' , ... ) do 117local ref =select ( i , ... ) 118if ref ~= nil then 119refs [ # refs + 1 ] =ref 120end 121end 122end 123 124--- @return string 125local function read_rm () 126local f =assert ( io . open ( t . paths . vterm_test_file , 'rb' )) 127local text =f : read ( '*a' ) 128f : close () 129vim . fs . rm ( t . paths . vterm_test_file , { force =true } ) 130return text 131end 132 133local function append ( str ) 134local f =assert ( io . open ( t . paths . vterm_test_file , 'a' )) 135f : write ( str ) 136f : close () 137return 1 138end 139 140local function parser_control ( control ) 141return append ( string . format ( 'control %02x\n' , control )) 142end 143 144local function parser_escape ( bytes ) 145return append ( string . format ( 'escape %s\n' , t . ffi . string ( bytes ))) 146end 147 148local function wantparser ( vt ) 149assert ( vt ) 150 151local parser_cbs =t . ffi . new ( 'VTermParserCallbacks' ) 152parser_cbs [ 'text' ] =vterm . parser_text 153parser_cbs [ 'control' ] =parser_control 154parser_cbs [ 'escape' ] =parser_escape 155parser_cbs [ 'csi' ] =vterm . parser_csi 156parser_cbs [ 'osc' ] =vterm . parser_osc 157parser_cbs [ 'dcs' ] =vterm . parser_dcs 158parser_cbs [ 'apc' ] =vterm . parser_apc 159parser_cbs [ 'pm' ] =vterm . parser_pm 160parser_cbs [ 'sos' ] =vterm . parser_sos 161 162vterm . vterm_parser_set_callbacks ( vt , parser_cbs , nil ) 163keep_callback_structs ( vt , parser_cbs ) 164end 165 166--- @return any 167local function init () 168local vt =vterm . vterm_new ( 25 , 80 ) 169vterm . vterm_output_set_callback ( vt , vterm . term_output , nil ) 170vterm . vterm_set_utf8 ( vt , true ) 171return vt 172end 173 174local function state_setlineinfo () 175return 1 176end 177 178--- @return any 179local function wantstate ( vt , opts ) 180opts =opts or {} 181assert ( vt ) 182local state =vterm . vterm_obtain_state ( vt ) 183 184local state_cbs =t . ffi . new ( 'VTermStateCallbacks' ) 185state_cbs [ 'putglyph' ] =vterm . state_putglyph 186state_cbs [ 'movecursor' ] =vterm . state_movecursor 187state_cbs [ 'scrollrect' ] =vterm . state_scrollrect 188state_cbs [ 'moverect' ] =vterm . state_moverect 189state_cbs [ 'erase' ] =vterm . state_erase 190state_cbs [ 'setpenattr' ] =vterm . state_setpenattr 191state_cbs [ 'settermprop' ] =vterm . state_settermprop 192state_cbs [ 'setlineinfo' ] =state_setlineinfo 193state_cbs [ 'sb_clear' ] =vterm . state_sb_clear 194 195local selection_cbs =t . ffi . new ( 'VTermSelectionCallbacks' ) 196selection_cbs [ 'set' ] =vterm . selection_set 197selection_cbs [ 'query' ] =vterm . selection_query 198 199vterm . vterm_state_set_callbacks ( state , state_cbs , nil ) 200 201-- In some tests we want to check the behaviour of overflowing the buffer, so make it nicely small 202vterm . vterm_state_set_selection_callbacks ( state , selection_cbs , nil , nil , 16 ) 203vterm . vterm_state_set_bold_highbright ( state , 1 ) 204vterm . vterm_state_reset ( state , 1 ) 205 206local fallback_cbs 207if opts . f then 208fallback_cbs =t . ffi . new ( 'VTermStateFallbacks' ) 209fallback_cbs [ 'control' ] =parser_control 210fallback_cbs [ 'csi' ] =vterm . parser_csi 211fallback_cbs [ 'osc' ] =vterm . parser_osc 212fallback_cbs [ 'dcs' ] =vterm . parser_dcs 213fallback_cbs [ 'apc' ] =vterm . parser_apc 214fallback_cbs [ 'pm' ] =vterm . parser_pm 215fallback_cbs [ 'sos' ] =vterm . parser_sos 216end 217 218vterm . want_state_scrollback =opts . b or false 219vterm . want_state_erase =opts . e or false 220vterm . vterm_state_set_unrecognised_fallbacks ( state , fallback_cbs , nil ) 221vterm . want_state_putglyph =opts . g or false 222vterm . want_state_moverect =opts . m or false 223vterm . want_state_settermprop =opts . p or false 224vterm . want_state_scrollrect =opts . s or false 225 226keep_callback_structs ( state , state_cbs , selection_cbs , fallback_cbs ) 227return state 228end 229 230--- @return any 231local function wantscreen ( vt , opts ) 232opts =opts or {} 233local screen =vterm . vterm_obtain_screen ( vt ) 234local screen_cbs =t . ffi . new ( 'VTermScreenCallbacks' ) 235 236-- TODO(dundargoc): fix 237-- screen_cbs['damage'] = vterm.screen_damage 238screen_cbs [ 'moverect' ] =vterm . state_moverect 239screen_cbs [ 'movecursor' ] =vterm . state_movecursor 240screen_cbs [ 'settermprop' ] =vterm . state_settermprop 241screen_cbs [ 'sb_pushline' ] =vterm . screen_sb_pushline 242screen_cbs [ 'sb_popline' ] =vterm . screen_sb_popline 243screen_cbs [ 'sb_clear' ] =vterm . screen_sb_clear 244 245vterm . vterm_screen_set_callbacks ( screen , screen_cbs , nil ) 246 247if opts . a then 248vterm . vterm_screen_enable_altscreen ( screen , 1 ) 249end 250vterm . want_screen_scrollback =opts . b or false 251vterm . want_state_movecursor =opts . c or false 252-- TODO(dundargoc): fix 253-- vterm.want_screen_damage = opts.d or opts.D or false 254-- vterm.want_screen_cells = opts.D or false 255vterm . want_state_moverect =opts . m or false 256vterm . want_state_settermprop =opts . p or false 257if opts . r then 258vterm . vterm_screen_enable_reflow ( screen , true ) 259end 260 261keep_callback_structs ( screen , screen_cbs ) 262return screen 263end 264 265local function reset ( state , screen ) 266if state then 267vterm . vterm_state_reset ( state , 1 ) 268vterm . vterm_state_get_cursorpos ( state , vterm . state_pos ) 269end 270if screen then 271vterm . vterm_screen_reset ( screen , 1 ) 272end 273end 274 275local function push ( input , vt ) 276vterm . vterm_input_write ( vt , input , string . len ( input )) 277end 278 279-- vterm_input_write() can synchronously invoke the Lua callbacks installed 280-- above. LuaJIT must not JIT-compile an FFI call that re-enters Lua, or the 281-- test can panic with "bad callback". 282if jit then 283jit . off ( push , true ) 284end 285 286local function expect ( expected ) 287local actual =read_rm () 288t . eq ( expected .. '\n' , actual ) 289end 290 291local function expect_output ( expected_preformat ) 292local actual =read_rm () 293local expected ='output ' 294 295for c in string . gmatch ( expected_preformat , '.' ) do 296if expected ~= 'output ' then 297expected =expected .. ',' 298end 299expected =string . format ( '%s%x' , expected , string . byte ( c )) 300end 301 302t . eq ( expected .. '\n' , actual ) 303end 304 305local function cursor ( row , col , state ) 306local pos =t . ffi . new ( 'VTermPos' ) --- @type {row: integer, col: integer} 307vterm . vterm_state_get_cursorpos ( state , pos ) 308t . eq ( row , pos . row ) 309t . eq ( col , pos . col ) 310end 311 312local function lineinfo ( row , expected , state ) 313local info =vterm . vterm_state_get_lineinfo ( state , row ) 314local dwl =info . doublewidth == 1 315local dhl =info . doubleheight == 1 316local cont =info . continuation == 1 317 318t . eq ( expected . dwl or false , dwl ) 319t . eq ( expected . dhl or false , dhl ) 320t . eq ( expected . cont or false , cont ) 321end 322 323local function pen ( attribute , expected , state ) 324local is_bool = 325{ bold =true , italic =true , blink =true , reverse =true , dim =true , overline =true } 326local vterm_attribute ={ 327bold =vterm . VTERM_ATTR_BOLD , 328underline =vterm . VTERM_ATTR_UNDERLINE , 329italic =vterm . VTERM_ATTR_ITALIC , 330blink =vterm . VTERM_ATTR_BLINK , 331reverse =vterm . VTERM_ATTR_REVERSE , 332font =vterm . VTERM_ATTR_FONT , 333dim =vterm . VTERM_ATTR_DIM , 334overline =vterm . VTERM_ATTR_OVERLINE , 335} 336 337local val =t . ffi . new ( 'VTermValue' ) --- @type {boolean: integer} 338vterm . vterm_state_get_penattr ( state , vterm_attribute [ attribute ], val ) 339local actual =val . boolean --- @type integer|boolean 340if is_bool [ attribute ] then 341actual =val . boolean == 1 342end 343t . eq ( expected , actual ) 344end 345 346local function resize ( rows , cols , vt ) 347vterm . vterm_set_size ( vt , rows , cols ) 348end 349 350local function screen_chars ( start_row , start_col , end_row , end_col , expected , screen ) 351local rect =t . ffi . new ( 'VTermRect' ) 352rect [ 'start_row' ] =start_row 353rect [ 'start_col' ] =start_col 354rect [ 'end_row' ] =end_row 355rect [ 'end_col' ] =end_col 356 357local len =vterm . vterm_screen_get_text ( screen , nil , 0 , rect ) 358 359local text =t . ffi . new ( 'unsigned char[?]' , len ) 360vterm . vterm_screen_get_text ( screen , text , len , rect ) 361 362local actual =t . ffi . string ( text , len ) 363t . eq ( expected , actual ) 364end 365 366local function screen_text ( start_row , start_col , end_row , end_col , expected , screen ) 367local rect =t . ffi . new ( 'VTermRect' ) 368rect [ 'start_row' ] =start_row 369rect [ 'start_col' ] =start_col 370rect [ 'end_row' ] =end_row 371rect [ 'end_col' ] =end_col 372 373local len =vterm . vterm_screen_get_text ( screen , nil , 0 , rect ) 374 375local text =t . ffi . new ( 'unsigned char[?]' , len ) 376vterm . vterm_screen_get_text ( screen , text , len , rect ) 377 378local actual ='' 379for i =0 , tonumber ( len ) - 1 do 380actual =string . format ( '%s%02x,' , actual , text [ i ]) 381end 382actual =actual : sub ( 1 , - 2 ) 383 384t . eq ( expected , actual ) 385end 386 387--- @param row integer 388local function screen_row ( row , expected , screen , end_col ) 389local rect =t . ffi . new ( 'VTermRect' ) 390rect [ 'start_row' ] =row 391rect [ 'start_col' ] =0 392rect [ 'end_row' ] =row + 1 393rect [ 'end_col' ] =end_col or 80 394 395local len =vterm . vterm_screen_get_text ( screen , nil , 0 , rect ) 396 397local text =t . ffi . new ( 'unsigned char[?]' , len ) 398vterm . vterm_screen_get_text ( screen , text , len , rect ) 399 400t . eq ( expected , t . ffi . string ( text , len )) 401end 402 403local function screen_cell ( row , col , expected , screen ) 404local pos =t . ffi . new ( 'VTermPos' ) 405pos [ 'row' ] =row 406pos [ 'col' ] =col 407 408local cell =t . ffi . new ( 'VTermScreenCell' ) ---@type any 409vterm . vterm_screen_get_cell ( screen , pos , cell ) 410 411local buf =t . ffi . new ( 'unsigned char[32]' ) 412vterm . schar_get ( buf , cell . schar ) 413 414local actual ='{' 415local i =0 416while buf [ i ] > 0 do 417local char =vterm . utf_ptr2char ( buf + i ) 418local charlen =vterm . utf_ptr2len ( buf + i ) 419if i > 0 then 420actual =actual .. ',' 421end 422local invalid =char >= 128 and charlen == 1 423actual =string . format ( '%s%s%02x' , actual , invalid and '?' or '' , char ) 424i =i + charlen 425end 426actual =string . format ( '%s} width=%d attrs={' , actual , cell [ 'width' ]) 427actual =actual .. ( cell [ 'attrs' ]. bold ~= 0 and 'B' or '' ) 428actual =actual .. ( cell [ 'attrs' ]. dim ~= 0 and 'D' or '' ) 429actual =actual 430.. ( cell [ 'attrs' ]. underline ~= 0 and string . format ( 'U%d' , cell [ 'attrs' ]. underline ) or '' ) 431actual =actual .. ( cell [ 'attrs' ]. italic ~= 0 and 'I' or '' ) 432actual =actual .. ( cell [ 'attrs' ]. blink ~= 0 and 'K' or '' ) 433actual =actual .. ( cell [ 'attrs' ]. reverse ~= 0 and 'R' or '' ) 434actual =actual .. ( cell [ 'attrs' ]. overline ~= 0 and 'O' or '' ) 435actual =actual .. ( cell [ 'attrs' ]. font ~= 0 and string . format ( 'F%d' , cell [ 'attrs' ]. font ) or '' ) 436actual =actual .. ( cell [ 'attrs' ]. small ~= 0 and 'S' or '' ) 437if cell [ 'attrs' ]. baseline ~= 0 then 438actual =actual .. ( cell [ 'attrs' ]. baseline == vterm . VTERM_BASELINE_RAISE and '^' or '_' ) 439end 440actual =actual .. '} ' 441 442actual =actual .. ( cell [ 'attrs' ]. dwl ~= 0 and 'dwl ' or '' ) 443if cell [ 'attrs' ]. dhl ~= 0 then 444actual =actual .. string . format ( 'dhl-%s ' , cell [ 'attrs' ]. dhl == 2 and 'bottom' or 'top' ) 445end 446 447actual =string . format ( '%sfg=' , actual ) 448vterm . vterm_screen_convert_color_to_rgb ( screen , cell [ 'fg' ]) 449vterm . print_color ( cell [ 'fg' ]) 450 451actual =actual .. read_rm () 452actual =actual .. ' bg=' 453 454vterm . vterm_screen_convert_color_to_rgb ( screen , cell [ 'bg' ]) 455vterm . print_color ( cell [ 'bg' ]) 456 457actual =actual .. read_rm () 458 459t . eq ( expected , actual ) 460end 461 462local function screen_eol ( row , col , expected , screen ) 463local pos =t . ffi . new ( 'VTermPos' ) 464pos [ 'row' ] =row 465pos [ 'col' ] =col 466 467local is_eol =vterm . vterm_screen_is_eol ( screen , pos ) 468t . eq ( expected , is_eol ) 469end 470 471local function screen_attrs_extent ( row , col , expected , screen ) 472local pos =t . ffi . new ( 'VTermPos' ) 473pos [ 'row' ] =row 474pos [ 'col' ] =col 475 476local rect =t . ffi . new ( 'VTermRect' ) 477rect [ 'start_col' ] =0 478rect [ 'end_col' ] =- 1 479vterm . vterm_screen_get_attrs_extent ( screen , rect , pos , 1 ) 480 481local actual =string . format ( 482'%d,%d-%d,%d' , 483rect [ 'start_row' ], 484rect [ 'start_col' ], 485rect [ 'end_row' ], 486rect [ 'end_col' ] 487) 488 489t . eq ( expected , actual ) 490end 491 492local function wantencoding () 493local encoding =t . ffi . new ( 'VTermEncodingInstance' ) 494encoding [ 'enc' ] =vterm . vterm_lookup_encoding ( vterm . ENC_UTF8 , string . byte ( 'u' )) 495if encoding . enc . init then 496encoding . enc . init ( encoding . enc , encoding [ 'data' ]) 497end 498return encoding 499end 500 501local function encin ( input , encoding ) 502local len =string . len ( input ) 503 504local cp =t . ffi . new ( 'uint32_t[?]' , len ) 505local cpi =t . ffi . new ( 'int[1]' ) 506local pos =t . ffi . new ( 'size_t[1]' , 0 ) 507 508encoding . enc . decode ( encoding . enc , encoding . data , cp , cpi , len , input , pos , len ) 509 510local f =assert ( io . open ( t . paths . vterm_test_file , 'w' )) 511if tonumber ( cpi [ 0 ]) > 0 then 512f : write ( 'encout ' ) 513for i =0 , cpi [ 0 ] - 1 do 514if i == 0 then 515f : write ( string . format ( '%x' , cp [ i ])) 516else 517f : write ( string . format ( ',%x' , cp [ i ])) 518end 519end 520f : write ( '\n' ) 521end 522f : close () 523end 524 525local function strpe_modifiers ( input_mod ) 526local mod =t . ffi . new ( 'VTermModifier' ) ---@type any 527if input_mod . C then 528mod =bit . bor ( mod , vterm . VTERM_MOD_CTRL ) 529end 530if input_mod . S then 531mod =bit . bor ( mod , vterm . VTERM_MOD_SHIFT ) 532end 533if input_mod . A then 534mod =bit . bor ( mod , vterm . VTERM_MOD_ALT ) 535end 536return mod 537end 538 539local function strp_key ( input_key ) 540if input_key == 'up' then 541return vterm . VTERM_KEY_UP 542end 543 544if input_key == 'tab' then 545return vterm . VTERM_KEY_TAB 546end 547 548if input_key == 'enter' then 549return vterm . VTERM_KEY_ENTER 550end 551 552if input_key == 'bs' then 553return vterm . VTERM_KEY_BACKSPACE 554end 555 556if input_key == 'del' then 557return vterm . VTERM_KEY_DEL 558end 559 560if input_key == 'esc' then 561return vterm . VTERM_KEY_ESCAPE 562end 563 564if input_key == 'f1' then 565return vterm . VTERM_KEY_FUNCTION_0 + 1 566end 567 568if input_key == 'kp0' then 569return vterm . VTERM_KEY_KP_0 570end 571 572return vterm . VTERM_KEY_NONE 573end 574 575local function mousemove ( row , col , vt , input_mod ) 576input_mod =input_mod or {} 577local mod =strpe_modifiers ( input_mod ) 578vterm . vterm_mouse_move ( vt , row , col , mod ) 579end 580 581local function mousebtn ( press , button , vt , input_mod ) 582input_mod =input_mod or {} 583local mod =strpe_modifiers ( input_mod ) 584local flag =press == 'd' or press == 'D' 585vterm . vterm_mouse_button ( vt , button , flag , mod ) 586end 587 588local function inchar ( c , vt , input_mod ) 589input_mod =input_mod or {} 590local mod =strpe_modifiers ( input_mod ) 591vterm . vterm_keyboard_unichar ( vt , c , mod ) 592end 593 594local function inkey ( input_key , vt , input_mod ) 595input_mod =input_mod or {} 596local mod =strpe_modifiers ( input_mod ) 597local key =strp_key ( input_key ) 598vterm . vterm_keyboard_key ( vt , key , mod ) 599end 600 601before_each ( function () 602vim . fs . rm ( t . paths . vterm_test_file , { force =true } ) 603end ) 604 605describe ( 'vterm' , function () 606itp ( '02parser' , function () 607local vt =init () 608vterm . vterm_set_utf8 ( vt , false ) 609wantparser ( vt ) 610 611-- Basic text 612push ( 'hello' , vt ) 613expect ( 'text 68,65,6c,6c,6f' ) 614 615-- C0 616push ( '\x03' , vt ) 617expect ( 'control 03' ) 618push ( '\x1f' , vt ) 619expect ( 'control 1f' ) 620 621-- C1 8bit 622push ( '\x83' , vt ) 623expect ( 'control 83' ) 624push ( '\x99' , vt ) 625expect ( 'control 99' ) 626 627-- C1 7bit 628push ( '\x1b\x43' , vt ) 629expect ( 'control 83' ) 630push ( '\x1b\x59' , vt ) 631expect ( 'control 99' ) 632 633-- High bytes 634push ( '\xa0\xcc\xfe' , vt ) 635expect ( 'text a0,cc,fe' ) 636 637-- Mixed 638push ( '1\n2' , vt ) 639expect ( 'text 31\ncontrol 0a\ntext 32' ) 640 641-- Escape 642push ( '\x1b=' , vt ) 643expect ( 'escape =' ) 644 645-- Escape 2-byte 646push ( '\x1b(X' , vt ) 647expect ( 'escape (X' ) 648 649-- Split write Escape 650push ( '\x1b(' , vt ) 651push ( 'Y' , vt ) 652expect ( 'escape (Y' ) 653 654-- Escape cancels Escape, starts another 655push ( '\x1b(\x1b)Z' , vt ) 656expect ( 'escape )Z' ) 657 658-- CAN cancels Escape, returns to normal mode 659push ( '\x1b(\x18AB' , vt ) 660expect ( 'text 41,42' ) 661 662-- C0 in Escape interrupts and continues 663push ( '\x1b(\nX' , vt ) 664expect ( 'control 0a\nescape (X' ) 665 666-- CSI 0 args 667push ( '\x1b[a' , vt ) 668expect ( 'csi 61 *' ) 669 670-- CSI 1 arg 671push ( '\x1b[9b' , vt ) 672expect ( 'csi 62 9' ) 673 674-- CSI 2 args 675push ( '\x1b[3;4c' , vt ) 676expect ( 'csi 63 3,4' ) 677 678-- CSI 1 arg 1 sub 679push ( '\x1b[1:2c' , vt ) 680expect ( 'csi 63 1+,2' ) 681 682-- CSI many digits 683push ( '\x1b[678d' , vt ) 684expect ( 'csi 64 678' ) 685 686-- CSI leading zero 687push ( '\x1b[007e' , vt ) 688expect ( 'csi 65 7' ) 689 690-- CSI qmark 691push ( '\x1b[?2;7f' , vt ) 692expect ( 'csi 66 L=3f 2,7' ) 693 694-- CSI greater 695push ( '\x1b[>c' , vt ) 696expect ( 'csi 63 L=3e *' ) 697 698-- CSI SP 699push ( '\x1b[12 q' , vt ) 700expect ( 'csi 71 12 I=20' ) 701 702-- Mixed CSI 703push ( 'A\x1b[8mB' , vt ) 704expect ( 'text 41\ncsi 6d 8\ntext 42' ) 705 706-- Split write 707push ( '\x1b' , vt ) 708push ( '[a' , vt ) 709expect ( 'csi 61 *' ) 710push ( 'foo\x1b[' , vt ) 711expect ( 'text 66,6f,6f' ) 712push ( '4b' , vt ) 713expect ( 'csi 62 4' ) 714push ( '\x1b[12;' , vt ) 715push ( '3c' , vt ) 716expect ( 'csi 63 12,3' ) 717 718-- Escape cancels CSI, starts Escape 719push ( '\x1b[123\x1b9' , vt ) 720expect ( 'escape 9' ) 721 722-- CAN cancels CSI, returns to normal mode 723push ( '\x1b[12\x18AB' , vt ) 724expect ( 'text 41,42' ) 725 726-- C0 in Escape interrupts and continues 727push ( '\x1b(\nX' , vt ) 728expect ( 'control 0a\nescape (X' ) 729 730-- OSC BEL 731push ( '\x1b]1;Hello\x07' , vt ) 732expect ( 'osc [1;Hello]' ) 733 734-- OSC ST (7bit) 735push ( '\x1b]1;Hello\x1b\\' , vt ) 736expect ( 'osc [1;Hello]' ) 737 738-- OSC ST (8bit) 739push ( '\x9d1;Hello\x9c' , vt ) 740expect ( 'osc [1;Hello]' ) 741 742-- OSC in parts 743push ( '\x1b]52;abc' , vt ) 744expect ( 'osc [52;abc' ) 745push ( 'def' , vt ) 746expect ( 'osc def' ) 747push ( 'ghi\x1b\\' , vt ) 748expect ( 'osc ghi]' ) 749 750-- OSC BEL without semicolon 751push ( '\x1b]1234\x07' , vt ) 752expect ( 'osc [1234;]' ) 753 754-- OSC ST without semicolon 755push ( '\x1b]1234\x1b\\' , vt ) 756expect ( 'osc [1234;]' ) 757 758-- Escape cancels OSC, starts Escape 759push ( '\x1b]Something\x1b9' , vt ) 760expect ( 'escape 9' ) 761 762-- CAN cancels OSC, returns to normal mode 763push ( '\x1b]12\x18AB' , vt ) 764expect ( 'text 41,42' ) 765 766-- C0 in OSC interrupts and continues 767push ( '\x1b]2;\nBye\x07' , vt ) 768expect ( 'osc [2;\ncontrol 0a\nosc Bye]' ) 769 770-- DCS BEL 771push ( '\x1bPHello\x07' , vt ) 772expect ( 'dcs [Hello]' ) 773 774-- DCS ST (7bit) 775push ( '\x1bPHello\x1b\\' , vt ) 776expect ( 'dcs [Hello]' ) 777 778-- DCS ST (8bit) 779push ( '\x90Hello\x9c' , vt ) 780expect ( 'dcs [Hello]' ) 781 782-- Split write of 7bit ST 783push ( '\x1bPABC\x1b' , vt ) 784expect ( 'dcs [ABC' ) 785push ( '\\' , vt ) 786expect ( 'dcs ]' ) 787 788-- Escape cancels DCS, starts Escape 789push ( '\x1bPSomething\x1b9' , vt ) 790expect ( 'escape 9' ) 791 792-- CAN cancels DCS, returns to normal mode 793push ( '\x1bP12\x18AB' , vt ) 794expect ( 'text 41,42' ) 795 796-- C0 in OSC interrupts and continues 797push ( '\x1bPBy\ne\x07' , vt ) 798expect ( 'dcs [By\ncontrol 0a\ndcs e]' ) 799 800-- APC BEL 801push ( '\x1b_Hello\x07' , vt ) 802expect ( 'apc [Hello]' ) 803 804-- APC ST (7bit) 805push ( '\x1b_Hello\x1b\\' , vt ) 806expect ( 'apc [Hello]' ) 807 808-- APC ST (8bit) 809push ( '\x9fHello\x9c' , vt ) 810expect ( 'apc [Hello]' ) 811 812-- PM BEL 813push ( '\x1b^Hello\x07' , vt ) 814expect ( 'pm [Hello]' ) 815 816-- PM ST (7bit) 817push ( '\x1b^Hello\x1b\\' , vt ) 818expect ( 'pm [Hello]' ) 819 820-- PM ST (8bit) 821push ( '\x9eHello\x9c' , vt ) 822expect ( 'pm [Hello]' ) 823 824-- SOS BEL 825push ( '\x1bXHello\x07' , vt ) 826expect ( 'sos [Hello]' ) 827 828-- SOS ST (7bit) 829push ( '\x1bXHello\x1b\\' , vt ) 830expect ( 'sos [Hello]' ) 831 832-- SOS ST (8bit) 833push ( '\x98Hello\x9c' , vt ) 834expect ( 'sos [Hello]' ) 835 836push ( '\x1bXABC\x01DEF\x1b\\' , vt ) 837expect ( 'sos [ABC\x01DEF]' ) 838push ( '\x1bXABC\x99DEF\x1b\\' , vt ) 839expect ( 'sos [ABC\x99DEF]' ) 840 841-- NUL ignored 842push ( '\x00' , vt ) 843 844-- NUL ignored within CSI 845push ( '\x1b[12\x003m' , vt ) 846expect ( 'csi 6d 123' ) 847 848-- DEL ignored 849push ( '\x7f' , vt ) 850 851-- DEL ignored within CSI 852push ( '\x1b[12\x7f3m' , vt ) 853expect ( 'csi 6d 123' ) 854 855-- DEL inside text" 856push ( 'AB\x7fC' , vt ) 857expect ( 'text 41,42\ntext 43' ) 858end ) 859 860itp ( '03encoding_utf8' , function () 861local encoding =wantencoding () 862 863-- Low 864encin ( '123' , encoding ) 865expect ( 'encout 31,32,33' ) 866 867-- We want to prove the UTF-8 parser correctly handles all the sequences. 868-- Easy way to do this is to check it does low/high boundary cases, as that 869-- leaves only two for each sequence length 870-- 871-- These ranges are therefore: 872-- 873-- Two bytes: 874-- U+0080 = 000 10000000 => 00010 000000 875-- => 11000010 10000000 = C2 80 876-- U+07FF = 111 11111111 => 11111 111111 877-- => 11011111 10111111 = DF BF 878-- 879-- Three bytes: 880-- U+0800 = 00001000 00000000 => 0000 100000 000000 881-- => 11100000 10100000 10000000 = E0 A0 80 882-- U+FFFD = 11111111 11111101 => 1111 111111 111101 883-- => 11101111 10111111 10111101 = EF BF BD 884-- (We avoid U+FFFE and U+FFFF as they're invalid codepoints) 885-- 886-- Four bytes: 887-- U+10000 = 00001 00000000 00000000 => 000 010000 000000 000000 888-- => 11110000 10010000 10000000 10000000 = F0 90 80 80 889-- U+1FFFFF = 11111 11111111 11111111 => 111 111111 111111 111111 890-- => 11110111 10111111 10111111 10111111 = F7 BF BF BF 891 892-- 2 byte 893encin ( '\xC2\x80\xDF\xBF' , encoding ) 894expect ( 'encout 80,7ff' ) 895 896-- 3 byte 897encin ( '\xE0\xA0\x80\xEF\xBF\xBD' , encoding ) 898expect ( 'encout 800,fffd' ) 899 900-- 4 byte 901encin ( '\xF0\x90\x80\x80\xF7\xBF\xBF\xBF' , encoding ) 902expect ( 'encout 10000,1fffff' ) 903 904-- Next up, we check some invalid sequences 905-- + Early termination (back to low bytes too soon) 906-- + Early restart (another sequence introduction before the previous one was finished) 907 908-- Early termination 909encin ( '\xC2!' , encoding ) 910expect ( 'encout fffd,21' ) 911 912encin ( '\xE0!\xE0\xA0!' , encoding ) 913expect ( 'encout fffd,21,fffd,21' ) 914 915encin ( '\xF0!\xF0\x90!\xF0\x90\x80!' , encoding ) 916expect ( 'encout fffd,21,fffd,21,fffd,21' ) 917 918-- Early restart 919encin ( '\xC2\xC2\x90' , encoding ) 920expect ( 'encout fffd,90' ) 921 922encin ( '\xE0\xC2\x90\xE0\xA0\xC2\x90' , encoding ) 923expect ( 'encout fffd,90,fffd,90' ) 924 925encin ( '\xF0\xC2\x90\xF0\x90\xC2\x90\xF0\x90\x80\xC2\x90' , encoding ) 926expect ( 'encout fffd,90,fffd,90,fffd,90' ) 927 928-- Test the overlong sequences by giving an overlong encoding of U+0000 and 929-- an encoding of the highest codepoint still too short 930-- 931-- Two bytes: 932-- U+0000 = C0 80 933-- U+007F = 000 01111111 => 00001 111111 => 934-- => 11000001 10111111 => C1 BF 935-- 936-- Three bytes: 937-- U+0000 = E0 80 80 938-- U+07FF = 00000111 11111111 => 0000 011111 111111 939-- => 11100000 10011111 10111111 = E0 9F BF 940-- 941-- Four bytes: 942-- U+0000 = F0 80 80 80 943-- U+FFFF = 11111111 11111111 => 000 001111 111111 111111 944-- => 11110000 10001111 10111111 10111111 = F0 8F BF BF 945 946-- Overlong 947encin ( '\xC0\x80\xC1\xBF' , encoding ) 948expect ( 'encout fffd,fffd' ) 949 950encin ( '\xE0\x80\x80\xE0\x9F\xBF' , encoding ) 951expect ( 'encout fffd,fffd' ) 952 953encin ( '\xF0\x80\x80\x80\xF0\x8F\xBF\xBF' , encoding ) 954expect ( 'encout fffd,fffd' ) 955 956-- UTF-16 surrogates U+D800 and U+DFFF 957-- UTF-16 Surrogates 958encin ( '\xED\xA0\x80\xED\xBF\xBF' , encoding ) 959expect ( 'encout fffd,fffd' ) 960 961-- Split write 962encin ( '\xC2' , encoding ) 963encin ( '\xA0' , encoding ) 964expect ( 'encout a0' ) 965 966encin ( '\xE0' , encoding ) 967encin ( '\xA0\x80' , encoding ) 968expect ( 'encout 800' ) 969encin ( '\xE0\xA0' , encoding ) 970encin ( '\x80' , encoding ) 971expect ( 'encout 800' ) 972 973encin ( '\xF0' , encoding ) 974encin ( '\x90\x80\x80' , encoding ) 975expect ( 'encout 10000' ) 976encin ( '\xF0\x90' , encoding ) 977encin ( '\x80\x80' , encoding ) 978expect ( 'encout 10000' ) 979encin ( '\xF0\x90\x80' , encoding ) 980encin ( '\x80' , encoding ) 981expect ( 'encout 10000' ) 982end ) 983 984itp ( '10state_putglyph' , function () 985local vt =init () 986local state =wantstate ( vt , { g =true } ) 987 988-- Low 989reset ( state , nil ) 990push ( 'ABC' , vt ) 991expect ( 'putglyph 41 1 0,0\nputglyph 42 1 0,1\nputglyph 43 1 0,2' ) 992 993-- UTF-8 1 char 994-- U+00C1 = 0xC3 0x81 name: LATIN CAPITAL LETTER A WITH ACUTE 995-- U+00E9 = 0xC3 0xA9 name: LATIN SMALL LETTER E WITH ACUTE 996reset ( state , nil ) 997push ( '\xC3\x81\xC3\xA9' , vt ) 998expect ( 'putglyph c1 1 0,0\nputglyph e9 1 0,1' ) 999 1000-- UTF-8 split writes 1001reset ( state , nil ) 1002push ( '\xC3' , vt ) 1003push ( '\x81' , vt ) 1004expect ( 'putglyph c1 1 0,0' ) 1005 1006-- UTF-8 wide char 1007-- U+FF10 = EF BC 90 name: FULLWIDTH DIGIT ZERO 1008reset ( state , nil ) 1009push ( '\xEF\xBC\x90 ' , vt ) 1010expect ( 'putglyph ff10 2 0,0\nputglyph 20 1 0,2' ) 1011 1012-- UTF-8 emoji wide char 1013-- U+1F600 = F0 9F 98 80 name: GRINNING FACE 1014reset ( state , nil ) 1015push ( '\xF0\x9F\x98\x80 ' , vt ) 1016expect ( 'putglyph 1f600 2 0,0\nputglyph 20 1 0,2' ) 1017 1018-- UTF-8 combining chars 1019-- U+0301 = CC 81 name: COMBINING ACUTE 1020reset ( state , nil ) 1021push ( 'e\xCC\x81Z' , vt ) 1022expect ( 'putglyph 65,301 1 0,0\nputglyph 5a 1 0,1' ) 1023 1024-- Combining across buffers 1025reset ( state , nil ) 1026push ( 'e' , vt ) 1027expect ( 'putglyph 65 1 0,0' ) 1028push ( '\xCC\x81Z' , vt ) 1029expect ( 'putglyph 65,301 1 0,0\nputglyph 5a 1 0,1' ) 1030 1031-- Spare combining chars get truncated 1032reset ( state , nil ) 1033push ( 'e' .. string . rep ( '\xCC\x81' , 20 ), vt ) 1034expect ( 'putglyph 65,301,301,301,301,301,301,301,301,301,301,301,301,301,301 1 0,0' ) -- and nothing more 1035 1036-- Combining across buffers multiple times 1037reset ( state , nil ) 1038push ( 'e' , vt ) 1039expect ( 'putglyph 65 1 0,0' ) 1040push ( '\xCC\x81' , vt ) 1041expect ( 'putglyph 65,301 1 0,0' ) 1042push ( '\xCC\x82' , vt ) 1043expect ( 'putglyph 65,301,302 1 0,0' ) 1044 1045-- Combining across buffers at right edge 1046reset ( state , nil ) 1047push ( '\x1b[5;80H' , vt ) 1048push ( 'e' , vt ) 1049expect ( 'putglyph 65 1 4,79' ) 1050push ( '\xCC\x81' , vt ) 1051expect ( 'putglyph 65,301 1 4,79' ) 1052push ( '\xCC\x82Z' , vt ) 1053expect ( 'putglyph 65,301,302 1 4,79\nputglyph 5a 1 5,0' ) 1054 1055-- Combining regional indicators 1056reset ( state , nil ) 1057push ( '\x1b[5;77H' , vt ) 1058push ( '🇦' , vt ) 1059expect ( 'putglyph 1f1e6 2 4,76' ) 1060push ( '🇩' , vt ) 1061expect ( 'putglyph 1f1e6,1f1e9 2 4,76' ) 1062push ( '🇱' , vt ) 1063expect ( 'putglyph 1f1f1 2 4,78' ) 1064push ( '🇮' , vt ) 1065expect ( 'putglyph 1f1f1,1f1ee 2 4,78' ) 1066push ( '🇲' , vt ) 1067expect ( 'putglyph 1f1f2 2 5,0' ) 1068push ( '🇨' , vt ) 1069expect ( 'putglyph 1f1f2,1f1e8 2 5,0' ) 1070 1071-- emoji with ZWJ and variant selectors, as one chunk 1072reset ( state , nil ) 1073push ( '🏳️🌈🏳️⚧️🏴☠️' , vt ) 1074expect ( [[putglyph 1f3f3,fe0f,200d,1f308 2 0,0 1075putglyph 1f3f3,fe0f,200d,26a7,fe0f 2 0,2 1076putglyph 1f3f4,200d,2620,fe0f 2 0,4]] ) 1077 1078-- emoji, one code point at a time 1079reset ( state , nil ) 1080push ( '🏳' , vt ) 1081expect ( 'putglyph 1f3f3 2 0,0' ) 1082push ( '\xef\xb8\x8f' , vt ) 1083expect ( 'putglyph 1f3f3,fe0f 2 0,0' ) 1084push ( '\xe2\x80\x8d' , vt ) 1085expect ( 'putglyph 1f3f3,fe0f,200d 2 0,0' ) 1086push ( '🌈' , vt ) 1087expect ( 'putglyph 1f3f3,fe0f,200d,1f308 2 0,0' ) 1088 1089-- modifier can change width 1090push ( '❤' , vt ) 1091expect ( 'putglyph 2764 1 0,2' ) 1092push ( '\xef\xb8\x8f' , vt ) 1093expect ( 'putglyph 2764,fe0f 2 0,2' ) 1094 1095-- also works batched 1096push ( '❤️' , vt ) 1097expect ( 'putglyph 2764,fe0f 2 0,4' ) 1098 1099-- DECSCA protected 1100reset ( state , nil ) 1101push ( 'A\x1b[1"qB\x1b[2"qC' , vt ) 1102expect ( 'putglyph 41 1 0,0\nputglyph 42 1 0,1 prot\nputglyph 43 1 0,2' ) 1103end ) 1104 1105itp ( '11state_movecursor' , function () 1106local vt =init () 1107local state =wantstate ( vt ) 1108 1109-- Implicit 1110push ( 'ABC' , vt ) 1111cursor ( 0 , 3 , state ) 1112 1113-- Backspace 1114push ( '\b' , vt ) 1115cursor ( 0 , 2 , state ) 1116-- Horizontal Tab 1117push ( '\t' , vt ) 1118cursor ( 0 , 8 , state ) 1119-- Carriage Return 1120push ( '\r' , vt ) 1121cursor ( 0 , 0 , state ) 1122-- Linefeed 1123push ( '\n' , vt ) 1124cursor ( 1 , 0 , state ) 1125 1126-- Backspace bounded by lefthand edge 1127push ( '\x1b[4;2H' , vt ) 1128cursor ( 3 , 1 , state ) 1129push ( '\b' , vt ) 1130cursor ( 3 , 0 , state ) 1131push ( '\b' , vt ) 1132cursor ( 3 , 0 , state ) 1133 1134-- Backspace cancels phantom 1135push ( '\x1b[4;80H' , vt ) 1136cursor ( 3 , 79 , state ) 1137push ( 'X' , vt ) 1138cursor ( 3 , 79 , state ) 1139push ( '\b' , vt ) 1140cursor ( 3 , 78 , state ) 1141 1142-- HT bounded by righthand edge 1143push ( '\x1b[1;78H' , vt ) 1144cursor ( 0 , 77 , state ) 1145push ( '\t' , vt ) 1146cursor ( 0 , 79 , state ) 1147push ( '\t' , vt ) 1148cursor ( 0 , 79 , state ) 1149 1150reset ( state , nil ) 1151 1152-- Index 1153push ( 'ABC\x1bD' , vt ) 1154cursor ( 1 , 3 , state ) 1155-- Reverse Index 1156push ( '\x1bM' , vt ) 1157cursor ( 0 , 3 , state ) 1158-- Newline 1159push ( '\x1bE' , vt ) 1160cursor ( 1 , 0 , state ) 1161 1162reset ( state , nil ) 1163 1164-- Cursor Forward 1165push ( '\x1b[B' , vt ) 1166cursor ( 1 , 0 , state ) 1167push ( '\x1b[3B' , vt ) 1168cursor ( 4 , 0 , state ) 1169push ( '\x1b[0B' , vt ) 1170cursor ( 5 , 0 , state ) 1171 1172-- Cursor Down 1173push ( '\x1b[C' , vt ) 1174cursor ( 5 , 1 , state ) 1175push ( '\x1b[3C' , vt ) 1176cursor ( 5 , 4 , state ) 1177push ( '\x1b[0C' , vt ) 1178cursor ( 5 , 5 , state ) 1179 1180-- Cursor Up 1181push ( '\x1b[A' , vt ) 1182cursor ( 4 , 5 , state ) 1183push ( '\x1b[3A' , vt ) 1184cursor ( 1 , 5 , state ) 1185push ( '\x1b[0A' , vt ) 1186cursor ( 0 , 5 , state ) 1187 1188-- Cursor Backward 1189push ( '\x1b[D' , vt ) 1190cursor ( 0 , 4 , state ) 1191push ( '\x1b[3D' , vt ) 1192cursor ( 0 , 1 , state ) 1193push ( '\x1b[0D' , vt ) 1194cursor ( 0 , 0 , state ) 1195 1196-- Cursor Next Line 1197push ( ' ' , vt ) 1198cursor ( 0 , 3 , state ) 1199push ( '\x1b[E' , vt ) 1200cursor ( 1 , 0 , state ) 1201push ( ' ' , vt ) 1202cursor ( 1 , 3 , state ) 1203push ( '\x1b[2E' , vt ) 1204cursor ( 3 , 0 , state ) 1205push ( '\x1b[0E' , vt ) 1206cursor ( 4 , 0 , state ) 1207 1208-- Cursor Previous Line 1209push ( ' ' , vt ) 1210cursor ( 4 , 3 , state ) 1211push ( '\x1b[F' , vt ) 1212cursor ( 3 , 0 , state ) 1213push ( ' ' , vt ) 1214cursor ( 3 , 3 , state ) 1215push ( '\x1b[2F' , vt ) 1216cursor ( 1 , 0 , state ) 1217push ( '\x1b[0F' , vt ) 1218cursor ( 0 , 0 , state ) 1219 1220-- Cursor Horizontal Absolute 1221push ( '\n' , vt ) 1222cursor ( 1 , 0 , state ) 1223push ( '\x1b[20G' , vt ) 1224cursor ( 1 , 19 , state ) 1225push ( '\x1b[G' , vt ) 1226cursor ( 1 , 0 , state ) 1227 1228-- Cursor Position 1229push ( '\x1b[10;5H' , vt ) 1230cursor ( 9 , 4 , state ) 1231push ( '\x1b[8H' , vt ) 1232cursor ( 7 , 0 , state ) 1233push ( '\x1b[H' , vt ) 1234cursor ( 0 , 0 , state ) 1235 1236-- Cursor Position cancels phantom 1237push ( '\x1b[10;78H' , vt ) 1238cursor ( 9 , 77 , state ) 1239push ( 'ABC' , vt ) 1240cursor ( 9 , 79 , state ) 1241push ( '\x1b[10;80H' , vt ) 1242push ( 'C' , vt ) 1243cursor ( 9 , 79 , state ) 1244push ( 'X' , vt ) 1245cursor ( 10 , 1 , state ) 1246 1247reset ( state , nil ) 1248 1249-- Bounds Checking 1250push ( '\x1b[A' , vt ) 1251cursor ( 0 , 0 , state ) 1252push ( '\x1b[D' , vt ) 1253cursor ( 0 , 0 , state ) 1254push ( '\x1b[25;80H' , vt ) 1255cursor ( 24 , 79 , state ) 1256push ( '\x1b[B' , vt ) 1257cursor ( 24 , 79 , state ) 1258push ( '\x1b[C' , vt ) 1259cursor ( 24 , 79 , state ) 1260push ( '\x1b[E' , vt ) 1261cursor ( 24 , 0 , state ) 1262push ( '\x1b[H' , vt ) 1263cursor ( 0 , 0 , state ) 1264push ( '\x1b[F' , vt ) 1265cursor ( 0 , 0 , state ) 1266push ( '\x1b[999G' , vt ) 1267cursor ( 0 , 79 , state ) 1268push ( '\x1b[99;99H' , vt ) 1269cursor ( 24 , 79 , state ) 1270 1271reset ( state , nil ) 1272 1273-- Horizontal Position Absolute 1274push ( '\x1b[5`' , vt ) 1275cursor ( 0 , 4 , state ) 1276 1277-- Horizontal Position Relative 1278push ( '\x1b[3a' , vt ) 1279cursor ( 0 , 7 , state ) 1280 1281-- Horizontal Position Backward 1282push ( '\x1b[3j' , vt ) 1283cursor ( 0 , 4 , state ) 1284 1285-- Horizontal and Vertical Position 1286push ( '\x1b[3;3f' , vt ) 1287cursor ( 2 , 2 , state ) 1288 1289-- Vertical Position Absolute 1290push ( '\x1b[5d' , vt ) 1291cursor ( 4 , 2 , state ) 1292 1293-- Vertical Position Relative 1294push ( '\x1b[2e' , vt ) 1295cursor ( 6 , 2 , state ) 1296 1297-- Vertical Position Backward 1298push ( '\x1b[2k' , vt ) 1299cursor ( 4 , 2 , state ) 1300 1301reset ( state , nil ) 1302 1303-- Horizontal Tab 1304push ( '\t' , vt ) 1305cursor ( 0 , 8 , state ) 1306push ( ' ' , vt ) 1307cursor ( 0 , 11 , state ) 1308push ( '\t' , vt ) 1309cursor ( 0 , 16 , state ) 1310push ( ' ' , vt ) 1311cursor ( 0 , 23 , state ) 1312push ( '\t' , vt ) 1313cursor ( 0 , 24 , state ) 1314push ( ' ' , vt ) 1315cursor ( 0 , 32 , state ) 1316push ( '\t' , vt ) 1317cursor ( 0 , 40 , state ) 1318 1319-- Cursor Horizontal Tab 1320push ( '\x1b[I' , vt ) 1321cursor ( 0 , 48 , state ) 1322push ( '\x1b[2I' , vt ) 1323cursor ( 0 , 64 , state ) 1324 1325-- Cursor Backward Tab 1326push ( '\x1b[Z' , vt ) 1327cursor ( 0 , 56 , state ) 1328push ( '\x1b[2Z' , vt ) 1329cursor ( 0 , 40 , state ) 1330end ) 1331 1332itp ( '12state_scroll' , function () 1333local vt =init () 1334local state =wantstate ( vt , { s =true } ) 1335 1336-- Linefeed 1337push ( string . rep ( '\n' , 24 ), vt ) 1338cursor ( 24 , 0 , state ) 1339push ( '\n' , vt ) 1340expect ( 'scrollrect 0..25,0..80 => +1,+0' ) 1341cursor ( 24 , 0 , state ) 1342 1343reset ( state , nil ) 1344 1345-- Index 1346push ( '\x1b[25H' , vt ) 1347push ( '\x1bD' , vt ) 1348expect ( 'scrollrect 0..25,0..80 => +1,+0' ) 1349 1350reset ( state , nil ) 1351 1352-- Reverse Index 1353push ( '\x1bM' , vt ) 1354expect ( 'scrollrect 0..25,0..80 => -1,+0' ) 1355 1356reset ( state , nil ) 1357 1358-- Linefeed in DECSTBM 1359push ( '\x1b[1;10r' , vt ) 1360cursor ( 0 , 0 , state ) 1361push ( string . rep ( '\n' , 9 ), vt ) 1362cursor ( 9 , 0 , state ) 1363push ( '\n' , vt ) 1364expect ( 'scrollrect 0..10,0..80 => +1,+0' ) 1365cursor ( 9 , 0 , state ) 1366 1367-- Linefeed outside DECSTBM 1368push ( '\x1b[20H' , vt ) 1369cursor ( 19 , 0 , state ) 1370push ( '\n' , vt ) 1371cursor ( 20 , 0 , state ) 1372 1373-- Index in DECSTBM 1374push ( '\x1b[9;10r' , vt ) 1375push ( '\x1b[10H' , vt ) 1376push ( '\x1bM' , vt ) 1377cursor ( 8 , 0 , state ) 1378push ( '\x1bM' , vt ) 1379expect ( 'scrollrect 8..10,0..80 => -1,+0' ) 1380 1381-- Reverse Index in DECSTBM 1382push ( '\x1b[25H' , vt ) 1383cursor ( 24 , 0 , state ) 1384push ( '\n' , vt ) 1385-- no scrollrect 1386cursor ( 24 , 0 , state ) 1387 1388-- Linefeed in DECSTBM+DECSLRM 1389push ( '\x1b[?69h' , vt ) 1390push ( '\x1b[3;10r\x1b[10;40s' , vt ) 1391push ( '\x1b[10;10H\n' , vt ) 1392expect ( 'scrollrect 2..10,9..40 => +1,+0' ) 1393 1394-- IND/RI in DECSTBM+DECSLRM 1395push ( '\x1bD' , vt ) 1396expect ( 'scrollrect 2..10,9..40 => +1,+0' ) 1397push ( '\x1b[3;10H\x1bM' , vt ) 1398expect ( 'scrollrect 2..10,9..40 => -1,+0' ) 1399 1400-- DECRQSS on DECSTBM 1401push ( '\x1bP$qr\x1b\\' , vt ) 1402expect_output ( '\x1bP1$r3;10r\x1b\\' ) 1403 1404-- DECRQSS on DECSLRM 1405push ( '\x1bP$qs\x1b\\' , vt ) 1406expect_output ( '\x1bP1$r10;40s\x1b\\' ) 1407 1408-- Setting invalid DECSLRM with !DECVSSM is still rejected 1409push ( '\x1b[?69l\x1b[;0s\x1b[?69h' , vt ) 1410 1411reset ( state , nil ) 1412 1413-- Scroll Down 1414push ( '\x1b[S' , vt ) 1415expect ( 'scrollrect 0..25,0..80 => +1,+0' ) 1416cursor ( 0 , 0 , state ) 1417push ( '\x1b[2S' , vt ) 1418expect ( 'scrollrect 0..25,0..80 => +2,+0' ) 1419cursor ( 0 , 0 , state ) 1420push ( '\x1b[100S' , vt ) 1421expect ( 'scrollrect 0..25,0..80 => +25,+0' ) 1422 1423-- Scroll Up 1424push ( '\x1b[T' , vt ) 1425expect ( 'scrollrect 0..25,0..80 => -1,+0' ) 1426cursor ( 0 , 0 , state ) 1427push ( '\x1b[2T' , vt ) 1428expect ( 'scrollrect 0..25,0..80 => -2,+0' ) 1429cursor ( 0 , 0 , state ) 1430push ( '\x1b[100T' , vt ) 1431expect ( 'scrollrect 0..25,0..80 => -25,+0' ) 1432 1433-- SD/SU in DECSTBM 1434push ( '\x1b[5;20r' , vt ) 1435push ( '\x1b[S' , vt ) 1436expect ( 'scrollrect 4..20,0..80 => +1,+0' ) 1437push ( '\x1b[T' , vt ) 1438expect ( 'scrollrect 4..20,0..80 => -1,+0' ) 1439 1440reset ( state , nil ) 1441 1442-- SD/SU in DECSTBM+DECSLRM 1443push ( '\x1b[?69h' , vt ) 1444push ( '\x1b[3;10r\x1b[10;40s' , vt ) 1445cursor ( 0 , 0 , state ) 1446push ( '\x1b[3;10H' , vt ) 1447cursor ( 2 , 9 , state ) 1448push ( '\x1b[S' , vt ) 1449expect ( 'scrollrect 2..10,9..40 => +1,+0' ) 1450push ( '\x1b[?69l' , vt ) 1451push ( '\x1b[S' , vt ) 1452expect ( 'scrollrect 2..10,0..80 => +1,+0' ) 1453 1454-- Invalid boundaries 1455reset ( state , nil ) 1456 1457push ( '\x1b[100;105r\x1bD' , vt ) 1458push ( '\x1b[5;2r\x1bD' , vt ) 1459 1460reset ( state , nil ) 1461state =wantstate ( vt , { m =true , e =true } ) 1462 1463-- Scroll Down move+erase emulation 1464push ( '\x1b[S' , vt ) 1465expect ( 'moverect 1..25,0..80 -> 0..24,0..80\nerase 24..25,0..80' ) 1466cursor ( 0 , 0 , state ) 1467push ( '\x1b[2S' , vt ) 1468expect ( 'moverect 2..25,0..80 -> 0..23,0..80\nerase 23..25,0..80' ) 1469cursor ( 0 , 0 , state ) 1470 1471-- Scroll Up move+erase emulation 1472push ( '\x1b[T' , vt ) 1473expect ( 'moverect 0..24,0..80 -> 1..25,0..80\nerase 0..1,0..80' ) 1474cursor ( 0 , 0 , state ) 1475push ( '\x1b[2T' , vt ) 1476expect ( 'moverect 0..23,0..80 -> 2..25,0..80\nerase 0..2,0..80' ) 1477cursor ( 0 , 0 , state ) 1478 1479-- DECSTBM resets cursor position 1480push ( '\x1b[5;5H' , vt ) 1481cursor ( 4 , 4 , state ) 1482push ( '\x1b[r' , vt ) 1483cursor ( 0 , 0 , state ) 1484end ) 1485 1486itp ( '13state_edit' , function () 1487local vt =init () 1488local state =wantstate ( vt , { s =true , e =true , b =true } ) 1489 1490-- ICH 1491reset ( state , nil ) 1492expect ( 'erase 0..25,0..80' ) 1493cursor ( 0 , 0 , state ) 1494push ( 'ACD' , vt ) 1495push ( '\x1b[2D' , vt ) 1496cursor ( 0 , 1 , state ) 1497push ( '\x1b[@' , vt ) 1498expect ( 'scrollrect 0..1,1..80 => +0,-1' ) 1499cursor ( 0 , 1 , state ) 1500push ( 'B' , vt ) 1501cursor ( 0 , 2 , state ) 1502push ( '\x1b[3@' , vt ) 1503expect ( 'scrollrect 0..1,2..80 => +0,-3' ) 1504 1505-- ICH with DECSLRM 1506push ( '\x1b[?69h' , vt ) 1507push ( '\x1b[;50s' , vt ) 1508push ( '\x1b[20G\x1b[@' , vt ) 1509expect ( 'scrollrect 0..1,19..50 => +0,-1' ) 1510 1511-- ICH outside DECSLRM 1512push ( '\x1b[70G\x1b[@' , vt ) 1513-- nothing happens 1514 1515-- DCH 1516reset ( state , nil ) 1517expect ( 'erase 0..25,0..80' ) 1518cursor ( 0 , 0 , state ) 1519push ( 'ABBC' , vt ) 1520push ( '\x1b[3D' , vt ) 1521cursor ( 0 , 1 , state ) 1522push ( '\x1b[P' , vt ) 1523expect ( 'scrollrect 0..1,1..80 => +0,+1' ) 1524cursor ( 0 , 1 , state ) 1525push ( '\x1b[3P' , vt ) 1526expect ( 'scrollrect 0..1,1..80 => +0,+3' ) 1527cursor ( 0 , 1 , state ) 1528 1529-- DCH with DECSLRM 1530push ( '\x1b[?69h' , vt ) 1531push ( '\x1b[;50s' , vt ) 1532push ( '\x1b[20G\x1b[P' , vt ) 1533expect ( 'scrollrect 0..1,19..50 => +0,+1' ) 1534 1535-- DCH outside DECSLRM 1536push ( '\x1b[70G\x1b[P' , vt ) 1537-- nothing happens 1538 1539-- ECH 1540reset ( state , nil ) 1541expect ( 'erase 0..25,0..80' ) 1542cursor ( 0 , 0 , state ) 1543push ( 'ABC' , vt ) 1544push ( '\x1b[2D' , vt ) 1545cursor ( 0 , 1 , state ) 1546push ( '\x1b[X' , vt ) 1547expect ( 'erase 0..1,1..2' ) 1548cursor ( 0 , 1 , state ) 1549push ( '\x1b[3X' , vt ) 1550expect ( 'erase 0..1,1..4' ) 1551cursor ( 0 , 1 , state ) 1552-- ECH more columns than there are should be bounded 1553push ( '\x1b[100X' , vt ) 1554expect ( 'erase 0..1,1..80' ) 1555 1556-- IL 1557reset ( state , nil ) 1558expect ( 'erase 0..25,0..80' ) 1559cursor ( 0 , 0 , state ) 1560push ( 'A\r\nC' , vt ) 1561cursor ( 1 , 1 , state ) 1562push ( '\x1b[L' , vt ) 1563expect ( 'scrollrect 1..25,0..80 => -1,+0' ) 1564-- TODO(libvterm): ECMA-48 says we should move to line home, but neither xterm nor xfce4-terminal do this 1565cursor ( 1 , 1 , state ) 1566push ( '\rB' , vt ) 1567cursor ( 1 , 1 , state ) 1568push ( '\x1b[3L' , vt ) 1569expect ( 'scrollrect 1..25,0..80 => -3,+0' ) 1570 1571-- IL with DECSTBM 1572push ( '\x1b[5;15r' , vt ) 1573push ( '\x1b[5H\x1b[L' , vt ) 1574expect ( 'scrollrect 4..15,0..80 => -1,+0' ) 1575 1576-- IL outside DECSTBM 1577push ( '\x1b[20H\x1b[L' , vt ) 1578-- nothing happens 1579 1580-- IL with DECSTBM+DECSLRM 1581push ( '\x1b[?69h' , vt ) 1582push ( '\x1b[10;50s' , vt ) 1583push ( '\x1b[5;10H\x1b[L' , vt ) 1584expect ( 'scrollrect 4..15,9..50 => -1,+0' ) 1585 1586-- DL 1587reset ( state , nil ) 1588expect ( 'erase 0..25,0..80' ) 1589cursor ( 0 , 0 , state ) 1590push ( 'A\r\nB\r\nB\r\nC' , vt ) 1591cursor ( 3 , 1 , state ) 1592push ( '\x1b[2H' , vt ) 1593cursor ( 1 , 0 , state ) 1594push ( '\x1b[M' , vt ) 1595expect ( 'scrollrect 1..25,0..80 => +1,+0' ) 1596cursor ( 1 , 0 , state ) 1597push ( '\x1b[3M' , vt ) 1598expect ( 'scrollrect 1..25,0..80 => +3,+0' ) 1599cursor ( 1 , 0 , state ) 1600 1601-- DL with DECSTBM 1602push ( '\x1b[5;15r' , vt ) 1603push ( '\x1b[5H\x1b[M' , vt ) 1604expect ( 'scrollrect 4..15,0..80 => +1,+0' ) 1605 1606-- DL outside DECSTBM 1607push ( '\x1b[20H\x1b[M' , vt ) 1608-- nothing happens 1609 1610-- DL with DECSTBM+DECSLRM 1611push ( '\x1b[?69h' , vt ) 1612push ( '\x1b[10;50s' , vt ) 1613push ( '\x1b[5;10H\x1b[M' , vt ) 1614expect ( 'scrollrect 4..15,9..50 => +1,+0' ) 1615 1616-- DECIC 1617reset ( state , nil ) 1618expect ( 'erase 0..25,0..80' ) 1619push ( "\x1b[20G\x1b[5'}" , vt ) 1620expect ( 'scrollrect 0..25,19..80 => +0,-5' ) 1621 1622-- DECIC with DECSTBM+DECSLRM 1623push ( '\x1b[?69h' , vt ) 1624push ( '\x1b[4;20r\x1b[20;60s' , vt ) 1625push ( "\x1b[4;20H\x1b[3'}" , vt ) 1626expect ( 'scrollrect 3..20,19..60 => +0,-3' ) 1627 1628-- DECIC outside DECSLRM 1629push ( "\x1b[70G\x1b['}" , vt ) 1630-- nothing happens 1631 1632-- DECDC 1633reset ( state , nil ) 1634expect ( 'erase 0..25,0..80' ) 1635push ( "\x1b[20G\x1b[5'~" , vt ) 1636expect ( 'scrollrect 0..25,19..80 => +0,+5' ) 1637 1638-- DECDC with DECSTBM+DECSLRM 1639push ( '\x1b[?69h' , vt ) 1640push ( '\x1b[4;20r\x1b[20;60s' , vt ) 1641push ( "\x1b[4;20H\x1b[3'~" , vt ) 1642expect ( 'scrollrect 3..20,19..60 => +0,+3' ) 1643 1644-- DECDC outside DECSLRM 1645push ( "\x1b[70G\x1b['~" , vt ) 1646-- nothing happens 1647 1648-- EL 0 1649reset ( state , nil ) 1650expect ( 'erase 0..25,0..80' ) 1651cursor ( 0 , 0 , state ) 1652push ( 'ABCDE' , vt ) 1653push ( '\x1b[3D' , vt ) 1654cursor ( 0 , 2 , state ) 1655push ( '\x1b[0K' , vt ) 1656expect ( 'erase 0..1,2..80' ) 1657cursor ( 0 , 2 , state ) 1658 1659-- EL 1 1660reset ( state , nil ) 1661expect ( 'erase 0..25,0..80' ) 1662cursor ( 0 , 0 , state ) 1663push ( 'ABCDE' , vt ) 1664push ( '\x1b[3D' , vt ) 1665cursor ( 0 , 2 , state ) 1666push ( '\x1b[1K' , vt ) 1667expect ( 'erase 0..1,0..3' ) 1668cursor ( 0 , 2 , state ) 1669 1670-- EL 2 1671reset ( state , nil ) 1672expect ( 'erase 0..25,0..80' ) 1673cursor ( 0 , 0 , state ) 1674push ( 'ABCDE' , vt ) 1675push ( '\x1b[3D' , vt ) 1676cursor ( 0 , 2 , state ) 1677push ( '\x1b[2K' , vt ) 1678expect ( 'erase 0..1,0..80' ) 1679cursor ( 0 , 2 , state ) 1680 1681-- SEL 1682reset ( state , nil ) 1683expect ( 'erase 0..25,0..80' ) 1684cursor ( 0 , 0 , state ) 1685push ( '\x1b[11G' , vt ) 1686cursor ( 0 , 10 , state ) 1687push ( '\x1b[?0K' , vt ) 1688expect ( 'erase 0..1,10..80 selective' ) 1689cursor ( 0 , 10 , state ) 1690push ( '\x1b[?1K' , vt ) 1691expect ( 'erase 0..1,0..11 selective' ) 1692cursor ( 0 , 10 , state ) 1693push ( '\x1b[?2K' , vt ) 1694expect ( 'erase 0..1,0..80 selective' ) 1695cursor ( 0 , 10 , state ) 1696 1697-- ED 0 1698reset ( state , nil ) 1699expect ( 'erase 0..25,0..80' ) 1700cursor ( 0 , 0 , state ) 1701push ( '\x1b[2;2H' , vt ) 1702cursor ( 1 , 1 , state ) 1703push ( '\x1b[0J' , vt ) 1704expect ( 'erase 1..2,1..80\nerase 2..25,0..80' ) 1705cursor ( 1 , 1 , state ) 1706 1707-- ED 1 1708reset ( state , nil ) 1709expect ( 'erase 0..25,0..80' ) 1710cursor ( 0 , 0 , state ) 1711push ( '\x1b[2;2H' , vt ) 1712cursor ( 1 , 1 , state ) 1713push ( '\x1b[1J' , vt ) 1714expect ( 'erase 0..1,0..80\nerase 1..2,0..2' ) 1715cursor ( 1 , 1 , state ) 1716 1717-- ED 2 1718reset ( state , nil ) 1719expect ( 'erase 0..25,0..80' ) 1720cursor ( 0 , 0 , state ) 1721push ( '\x1b[2;2H' , vt ) 1722cursor ( 1 , 1 , state ) 1723push ( '\x1b[2J' , vt ) 1724expect ( 'erase 0..25,0..80' ) 1725cursor ( 1 , 1 , state ) 1726 1727-- ED 3 1728push ( '\x1b[3J' , vt ) 1729expect ( 'sb_clear' ) 1730 1731-- SED 1732reset ( state , nil ) 1733expect ( 'erase 0..25,0..80' ) 1734push ( '\x1b[5;5H' , vt ) 1735cursor ( 4 , 4 , state ) 1736push ( '\x1b[?0J' , vt ) 1737expect ( 'erase 4..5,4..80 selective\nerase 5..25,0..80 selective' ) 1738cursor ( 4 , 4 , state ) 1739push ( '\x1b[?1J' , vt ) 1740expect ( 'erase 0..4,0..80 selective\nerase 4..5,0..5 selective' ) 1741cursor ( 4 , 4 , state ) 1742push ( '\x1b[?2J' , vt ) 1743expect ( 'erase 0..25,0..80 selective' ) 1744cursor ( 4 , 4 , state ) 1745 1746-- DECRQSS on DECSCA 1747push ( '\x1b[2"q' , vt ) 1748push ( '\x1bP$q"q\x1b\\' , vt ) 1749expect_output ( '\x1bP1$r2"q\x1b\\' ) 1750 1751state =wantstate ( vt , { m =true , e =true , b =true } ) 1752expect ( 'erase 0..25,0..80' ) -- TODO(dundargoc): strange, this should not be needed according to the original code 1753 1754-- ICH move+erase emuation 1755reset ( state , nil ) 1756expect ( 'erase 0..25,0..80' ) 1757cursor ( 0 , 0 , state ) 1758push ( 'ACD' , vt ) 1759push ( '\x1b[2D' , vt ) 1760cursor ( 0 , 1 , state ) 1761push ( '\x1b[@' , vt ) 1762expect ( 'moverect 0..1,1..79 -> 0..1,2..80\nerase 0..1,1..2' ) 1763cursor ( 0 , 1 , state ) 1764push ( 'B' , vt ) 1765cursor ( 0 , 2 , state ) 1766push ( '\x1b[3@' , vt ) 1767expect ( 'moverect 0..1,2..77 -> 0..1,5..80\nerase 0..1,2..5' ) 1768 1769-- DCH move+erase emulation 1770reset ( state , nil ) 1771expect ( 'erase 0..25,0..80' ) 1772cursor ( 0 , 0 , state ) 1773push ( 'ABBC' , vt ) 1774push ( '\x1b[3D' , vt ) 1775cursor ( 0 , 1 , state ) 1776push ( '\x1b[P' , vt ) 1777expect ( 'moverect 0..1,2..80 -> 0..1,1..79\nerase 0..1,79..80' ) 1778cursor ( 0 , 1 , state ) 1779push ( '\x1b[3P' , vt ) 1780expect ( 'moverect 0..1,4..80 -> 0..1,1..77\nerase 0..1,77..80' ) 1781cursor ( 0 , 1 , state ) 1782end ) 1783 1784itp ( '14state_encoding' , function () 1785local vt =init () 1786vterm . vterm_set_utf8 ( vt , false ) 1787local state =wantstate ( vt , { g =true } ) 1788 1789-- Default 1790reset ( state , nil ) 1791push ( '#' , vt ) 1792expect ( 'putglyph 23 1 0,0' ) 1793 1794-- Designate G0=DEC drawing 1795reset ( state , nil ) 1796push ( '\x1b(0' , vt ) 1797push ( 'a' , vt ) 1798expect ( 'putglyph 2592 1 0,0' ) 1799 1800-- Designate G1 + LS1 1801reset ( state , nil ) 1802push ( '\x1b)0' , vt ) 1803push ( 'a' , vt ) 1804expect ( 'putglyph 61 1 0,0' ) 1805push ( '\x0e' , vt ) 1806push ( 'a' , vt ) 1807expect ( 'putglyph 2592 1 0,1' ) 1808-- LS0 1809push ( '\x0f' , vt ) 1810push ( 'a' , vt ) 1811expect ( 'putglyph 61 1 0,2' ) 1812 1813-- Designate G2 + LS2 1814push ( '\x1b*0' , vt ) 1815push ( 'a' , vt ) 1816expect ( 'putglyph 61 1 0,3' ) 1817push ( '\x1bn' , vt ) 1818push ( 'a' , vt ) 1819expect ( 'putglyph 2592 1 0,4' ) 1820push ( '\x0f' , vt ) 1821push ( 'a' , vt ) 1822expect ( 'putglyph 61 1 0,5' ) 1823 1824-- Designate G3 + LS3 1825push ( '\x1b+0' , vt ) 1826push ( 'a' , vt ) 1827expect ( 'putglyph 61 1 0,6' ) 1828push ( '\x1bo' , vt ) 1829push ( 'a' , vt ) 1830expect ( 'putglyph 2592 1 0,7' ) 1831push ( '\x0f' , vt ) 1832push ( 'a' , vt ) 1833expect ( 'putglyph 61 1 0,8' ) 1834 1835-- SS2 1836push ( 'a\x8eaa' , vt ) 1837expect ( 'putglyph 61 1 0,9\nputglyph 2592 1 0,10\nputglyph 61 1 0,11' ) 1838 1839-- SS3 1840push ( 'a\x8faa' , vt ) 1841expect ( 'putglyph 61 1 0,12\nputglyph 2592 1 0,13\nputglyph 61 1 0,14' ) 1842 1843-- LS1R 1844reset ( state , nil ) 1845push ( '\x1b~' , vt ) 1846push ( '\xe1' , vt ) 1847expect ( 'putglyph 61 1 0,0' ) 1848push ( '\x1b)0' , vt ) 1849push ( '\xe1' , vt ) 1850expect ( 'putglyph 2592 1 0,1' ) 1851 1852-- LS2R 1853reset ( state , nil ) 1854push ( '\x1b}' , vt ) 1855push ( '\xe1' , vt ) 1856expect ( 'putglyph 61 1 0,0' ) 1857push ( '\x1b*0' , vt ) 1858push ( '\xe1' , vt ) 1859expect ( 'putglyph 2592 1 0,1' ) 1860 1861-- LS3R 1862reset ( state , nil ) 1863push ( '\x1b|' , vt ) 1864push ( '\xe1' , vt ) 1865expect ( 'putglyph 61 1 0,0' ) 1866push ( '\x1b+0' , vt ) 1867push ( '\xe1' , vt ) 1868expect ( 'putglyph 2592 1 0,1' ) 1869 1870vterm . vterm_set_utf8 ( vt , true ) 1871 1872-- Mixed US-ASCII and UTF-8 1873-- U+0108 == c4 88 1874reset ( state , nil ) 1875push ( '\x1b(B' , vt ) 1876push ( 'AB\xc4\x88D' , vt ) 1877expect ( 'putglyph 41 1 0,0\nputglyph 42 1 0,1\nputglyph 108 1 0,2\nputglyph 44 1 0,3' ) 1878 1879-- Split UTF-8 after US-ASCII 1880reset ( state , nil ) 1881push ( 'AB\xc4' , vt ) 1882expect ( 'putglyph 41 1 0,0\nputglyph 42 1 0,1' ) 1883push ( '\x88D' , vt ) 1884expect ( 'putglyph 108 1 0,2\nputglyph 44 1 0,3' ) 1885end ) 1886 1887itp ( '15state_mode' , function () 1888local vt =init () 1889local state =wantstate ( vt , { g =true , m =true , e =true } ) 1890 1891-- Insert/Replace Mode 1892reset ( state , nil ) 1893expect ( 'erase 0..25,0..80' ) 1894cursor ( 0 , 0 , state ) 1895push ( 'AC\x1b[DB' , vt ) 1896expect ( 'putglyph 41 1 0,0\nputglyph 43 1 0,1\nputglyph 42 1 0,1' ) 1897push ( '\x1b[4h' , vt ) 1898push ( '\x1b[G' , vt ) 1899push ( 'AC\x1b[DB' , vt ) 1900expect ( 1901'moverect 0..1,0..79 -> 0..1,1..80\nerase 0..1,0..1\nputglyph 41 1 0,0\nmoverect 0..1,1..79 -> 0..1,2..80\nerase 0..1,1..2\nputglyph 43 1 0,1\nmoverect 0..1,1..79 -> 0..1,2..80\nerase 0..1,1..2\nputglyph 42 1 0,1' 1902) 1903 1904-- Insert mode only happens once for UTF-8 combining 1905push ( 'e' , vt ) 1906expect ( 'moverect 0..1,2..79 -> 0..1,3..80\nerase 0..1,2..3\nputglyph 65 1 0,2' ) 1907push ( '\xCC\x81' , vt ) 1908expect ( 'putglyph 65,301 1 0,2' ) 1909 1910-- Newline/Linefeed mode 1911reset ( state , nil ) 1912expect ( 'erase 0..25,0..80' ) 1913cursor ( 0 , 0 , state ) 1914push ( '\x1b[5G\n' , vt ) 1915cursor ( 1 , 4 , state ) 1916push ( '\x1b[20h' , vt ) 1917push ( '\x1b[5G\n' , vt ) 1918cursor ( 2 , 0 , state ) 1919 1920-- DEC origin mode 1921reset ( state , nil ) 1922expect ( 'erase 0..25,0..80' ) 1923cursor ( 0 , 0 , state ) 1924push ( '\x1b[5;15r' , vt ) 1925push ( '\x1b[H' , vt ) 1926cursor ( 0 , 0 , state ) 1927push ( '\x1b[3;3H' , vt ) 1928cursor ( 2 , 2 , state ) 1929push ( '\x1b[?6h' , vt ) 1930push ( '\x1b[H' , vt ) 1931cursor ( 4 , 0 , state ) 1932push ( '\x1b[3;3H' , vt ) 1933cursor ( 6 , 2 , state ) 1934 1935-- DECRQM on DECOM 1936push ( '\x1b[?6h' , vt ) 1937push ( '\x1b[?6$p' , vt ) 1938expect_output ( '\x1b[?6;1$y' ) 1939push ( '\x1b[?6l' , vt ) 1940push ( '\x1b[?6$p' , vt ) 1941expect_output ( '\x1b[?6;2$y' ) 1942 1943-- Origin mode with DECSLRM 1944push ( '\x1b[?6h' , vt ) 1945push ( '\x1b[?69h' , vt ) 1946push ( '\x1b[20;60s' , vt ) 1947push ( '\x1b[H' , vt ) 1948cursor ( 4 , 19 , state ) 1949 1950push ( '\x1b[?69l' , vt ) 1951 1952-- Origin mode bounds cursor to scrolling region 1953push ( '\x1b[H' , vt ) 1954push ( '\x1b[10A' , vt ) 1955cursor ( 4 , 0 , state ) 1956push ( '\x1b[20B' , vt ) 1957cursor ( 14 , 0 , state ) 1958 1959-- Origin mode without scroll region 1960push ( '\x1b[?6l' , vt ) 1961push ( '\x1b[r\x1b[?6h' , vt ) 1962cursor ( 0 , 0 , state ) 1963end ) 1964 1965itp ( '16state_resize' , function () 1966local vt =init () 1967local state =wantstate ( vt , { g =true } ) 1968 1969-- Placement 1970reset ( state , nil ) 1971push ( 'AB\x1b[79GCDE' , vt ) 1972expect ( 1973'putglyph 41 1 0,0\nputglyph 42 1 0,1\nputglyph 43 1 0,78\nputglyph 44 1 0,79\nputglyph 45 1 1,0' 1974) 1975 1976-- Resize 1977reset ( state , nil ) 1978resize ( 27 , 85 , vt ) 1979push ( 'AB\x1b[79GCDE' , vt ) 1980expect ( 1981'putglyph 41 1 0,0\nputglyph 42 1 0,1\nputglyph 43 1 0,78\nputglyph 44 1 0,79\nputglyph 45 1 0,80' 1982) 1983cursor ( 0 , 81 , state ) 1984 1985-- Resize without reset 1986resize ( 28 , 90 , vt ) 1987cursor ( 0 , 81 , state ) 1988push ( 'FGHI' , vt ) 1989expect ( 'putglyph 46 1 0,81\nputglyph 47 1 0,82\nputglyph 48 1 0,83\nputglyph 49 1 0,84' ) 1990cursor ( 0 , 85 , state ) 1991 1992-- Resize shrink moves cursor 1993resize ( 25 , 80 , vt ) 1994cursor ( 0 , 79 , state ) 1995 1996-- Resize grow doesn't cancel phantom 1997reset ( state , nil ) 1998push ( '\x1b[79GAB' , vt ) 1999expect ( 'putglyph 41 1 0,78\nputglyph 42 1 0,79' ) 2000cursor ( 0 , 79 , state ) 2001resize ( 30 , 100 , vt ) 2002cursor ( 0 , 80 , state ) 2003push ( 'C' , vt ) 2004expect ( 'putglyph 43 1 0,80' ) 2005cursor ( 0 , 81 , state ) 2006end ) 2007 2008itp ( '17state_mouse' , function () 2009local vt =init () 2010local state =wantstate ( vt , { p =true } ) 2011 2012-- DECRQM on with mouse off 2013push ( '\x1b[?1000$p' , vt ) 2014expect_output ( '\x1b[?1000;2$y' ) 2015push ( '\x1b[?1002$p' , vt ) 2016expect_output ( '\x1b[?1002;2$y' ) 2017push ( '\x1b[?1003$p' , vt ) 2018expect_output ( '\x1b[?1003;2$y' ) 2019 2020-- Mouse in simple button report mode 2021reset ( state , nil ) 2022expect ( 'settermprop 1 true\nsettermprop 2 true\nsettermprop 7 1' ) 2023push ( '\x1b[?1000h' , vt ) 2024expect ( 'settermprop 8 1' ) 2025 2026-- Press 1 2027mousemove ( 0 , 0 , vt ) 2028mousebtn ( 'd' , 1 , vt ) 2029expect_output ( '\x1b[M\x20\x21\x21' ) 2030 2031-- Release 1 2032mousebtn ( 'u' , 1 , vt ) 2033expect_output ( '\x1b[M\x23\x21\x21' ) 2034 2035-- Ctrl-Press 1 2036mousebtn ( 'd' , 1 , vt , { C =true } ) 2037expect_output ( '\x1b[M\x30\x21\x21' ) 2038mousebtn ( 'u' , 1 , vt , { C =true } ) 2039expect_output ( '\x1b[M\x33\x21\x21' ) 2040 2041-- Button 2 2042mousebtn ( 'd' , 2 , vt ) 2043expect_output ( '\x1b[M\x21\x21\x21' ) 2044mousebtn ( 'u' , 2 , vt ) 2045expect_output ( '\x1b[M\x23\x21\x21' ) 2046 2047-- Position 2048mousemove ( 10 , 20 , vt ) 2049mousebtn ( 'd' , 1 , vt ) 2050expect_output ( '\x1b[M\x20\x35\x2b' ) 2051 2052mousebtn ( 'u' , 1 , vt ) 2053expect_output ( '\x1b[M\x23\x35\x2b' ) 2054mousemove ( 10 , 21 , vt ) 2055-- no output 2056 2057-- Wheel events 2058mousebtn ( 'd' , 4 , vt ) 2059expect_output ( '\x1b[M\x60\x36\x2b' ) 2060mousebtn ( 'd' , 4 , vt ) 2061expect_output ( '\x1b[M\x60\x36\x2b' ) 2062mousebtn ( 'd' , 5 , vt ) 2063expect_output ( '\x1b[M\x61\x36\x2b' ) 2064mousebtn ( 'd' , 6 , vt ) 2065expect_output ( '\x1b[M\x62\x36\x2b' ) 2066mousebtn ( 'd' , 7 , vt ) 2067expect_output ( '\x1b[M\x63\x36\x2b' ) 2068 2069-- DECRQM on mouse button mode 2070push ( '\x1b[?1000$p' , vt ) 2071expect_output ( '\x1b[?1000;1$y' ) 2072push ( '\x1b[?1002$p' , vt ) 2073expect_output ( '\x1b[?1002;2$y' ) 2074push ( '\x1b[?1003$p' , vt ) 2075expect_output ( '\x1b[?1003;2$y' ) 2076 2077-- Drag events 2078reset ( state , nil ) 2079expect ( 'settermprop 1 true\nsettermprop 2 true\nsettermprop 7 1' ) 2080push ( '\x1b[?1002h' , vt ) 2081expect ( 'settermprop 8 2' ) 2082 2083mousemove ( 5 , 5 , vt ) 2084mousebtn ( 'd' , 1 , vt ) 2085expect_output ( '\x1b[M\x20\x26\x26' ) 2086mousemove ( 5 , 6 , vt ) 2087expect_output ( '\x1b[M\x40\x27\x26' ) 2088mousemove ( 6 , 6 , vt ) 2089expect_output ( '\x1b[M\x40\x27\x27' ) 2090mousemove ( 6 , 6 , vt ) 2091-- no output 2092mousebtn ( 'u' , 1 , vt ) 2093expect_output ( '\x1b[M\x23\x27\x27' ) 2094mousemove ( 6 , 7 , vt ) 2095-- no output 2096 2097-- DECRQM on mouse drag mode 2098push ( '\x1b[?1000$p' , vt ) 2099expect_output ( '\x1b[?1000;2$y' ) 2100push ( '\x1b[?1002$p' , vt ) 2101expect_output ( '\x1b[?1002;1$y' ) 2102push ( '\x1b[?1003$p' , vt ) 2103expect_output ( '\x1b[?1003;2$y' ) 2104 2105-- Non-drag motion events 2106push ( '\x1b[?1003h' , vt ) 2107expect ( 'settermprop 8 3' ) 2108 2109mousemove ( 6 , 8 , vt ) 2110expect_output ( '\x1b[M\x43\x29\x27' ) 2111 2112-- DECRQM on mouse motion mode 2113push ( '\x1b[?1000$p' , vt ) 2114expect_output ( '\x1b[?1000;2$y' ) 2115push ( '\x1b[?1002$p' , vt ) 2116expect_output ( '\x1b[?1002;2$y' ) 2117push ( '\x1b[?1003$p' , vt ) 2118expect_output ( '\x1b[?1003;1$y' ) 2119 2120-- Bounds checking 2121mousemove ( 300 , 300 , vt ) 2122expect_output ( '\x1b[M\x43\xff\xff' ) 2123mousebtn ( 'd' , 1 , vt ) 2124expect_output ( '\x1b[M\x20\xff\xff' ) 2125mousebtn ( 'u' , 1 , vt ) 2126expect_output ( '\x1b[M\x23\xff\xff' ) 2127 2128-- DECRQM on standard encoding mode 2129push ( '\x1b[?1005$p' , vt ) 2130expect_output ( '\x1b[?1005;2$y' ) 2131push ( '\x1b[?1006$p' , vt ) 2132expect_output ( '\x1b[?1006;2$y' ) 2133push ( '\x1b[?1015$p' , vt ) 2134expect_output ( '\x1b[?1015;2$y' ) 2135 2136-- UTF-8 extended encoding mode 2137-- 300 + 32 + 1 = 333 = U+014d = \xc5\x8d 2138push ( '\x1b[?1005h' , vt ) 2139mousebtn ( 'd' , 1 , vt ) 2140expect_output ( '\x1b[M\x20\xc5\x8d\xc5\x8d' ) 2141mousebtn ( 'u' , 1 , vt ) 2142expect_output ( '\x1b[M\x23\xc5\x8d\xc5\x8d' ) 2143 2144-- DECRQM on UTF-8 extended encoding mode 2145push ( '\x1b[?1005$p' , vt ) 2146expect_output ( '\x1b[?1005;1$y' ) 2147push ( '\x1b[?1006$p' , vt ) 2148expect_output ( '\x1b[?1006;2$y' ) 2149push ( '\x1b[?1015$p' , vt ) 2150expect_output ( '\x1b[?1015;2$y' ) 2151 2152-- SGR extended encoding mode 2153push ( '\x1b[?1006h' , vt ) 2154mousebtn ( 'd' , 1 , vt ) 2155expect_output ( '\x1b[<0;301;301M' ) 2156mousebtn ( 'u' , 1 , vt ) 2157expect_output ( '\x1b[<0;301;301m' ) 2158 2159-- Button 8 on SGR extended encoding mode 2160mousebtn ( 'd' , 8 , vt ) 2161expect_output ( '\x1b[<128;301;301M' ) 2162mousebtn ( 'u' , 8 , vt ) 2163expect_output ( '\x1b[<128;301;301m' ) 2164 2165-- Button 9 on SGR extended encoding mode 2166mousebtn ( 'd' , 9 , vt ) 2167expect_output ( '\x1b[<129;301;301M' ) 2168mousebtn ( 'u' , 9 , vt ) 2169expect_output ( '\x1b[<129;301;301m' ) 2170 2171-- DECRQM on SGR extended encoding mode 2172push ( '\x1b[?1005$p' , vt ) 2173expect_output ( '\x1b[?1005;2$y' ) 2174push ( '\x1b[?1006$p' , vt ) 2175expect_output ( '\x1b[?1006;1$y' ) 2176push ( '\x1b[?1015$p' , vt ) 2177expect_output ( '\x1b[?1015;2$y' ) 2178 2179-- rxvt extended encoding mode 2180push ( '\x1b[?1015h' , vt ) 2181mousebtn ( 'd' , 1 , vt ) 2182expect_output ( '\x1b[0;301;301M' ) 2183mousebtn ( 'u' , 1 , vt ) 2184expect_output ( '\x1b[3;301;301M' ) 2185 2186-- Button 8 on rxvt extended encoding mode 2187mousebtn ( 'd' , 8 , vt ) 2188expect_output ( '\x1b[128;301;301M' ) 2189mousebtn ( 'u' , 8 , vt ) 2190expect_output ( '\x1b[3;301;301M' ) 2191 2192-- Button 9 on rxvt extended encoding mode 2193mousebtn ( 'd' , 9 , vt ) 2194expect_output ( '\x1b[129;301;301M' ) 2195mousebtn ( 'u' , 9 , vt ) 2196expect_output ( '\x1b[3;301;301M' ) 2197 2198-- DECRQM on rxvt extended encoding mode 2199push ( '\x1b[?1005$p' , vt ) 2200expect_output ( '\x1b[?1005;2$y' ) 2201push ( '\x1b[?1006$p' , vt ) 2202expect_output ( '\x1b[?1006;2$y' ) 2203push ( '\x1b[?1015$p' , vt ) 2204expect_output ( '\x1b[?1015;1$y' ) 2205 2206-- Mouse disabled reports nothing 2207reset ( state , nil ) 2208expect ( 'settermprop 1 true\nsettermprop 2 true\nsettermprop 7 1' ) 2209mousemove ( 0 , 0 , vt ) 2210mousebtn ( 'd' , 1 , vt ) 2211mousebtn ( 'u' , 1 , vt ) 2212 2213-- DECSM can set multiple modes at once 2214push ( '\x1b[?1002;1006h' , vt ) 2215expect ( 'settermprop 8 2' ) 2216mousebtn ( 'd' , 1 , vt ) 2217expect_output ( '\x1b[<0;1;1M' ) 2218end ) 2219 2220itp ( '18state_termprops' , function () 2221local vt =init () 2222local state =wantstate ( vt , { p =true } ) 2223 2224reset ( state , nil ) 2225expect ( 'settermprop 1 true\nsettermprop 2 true\nsettermprop 7 1' ) 2226 2227-- Cursor visibility 2228push ( '\x1b[?25h' , vt ) 2229expect ( 'settermprop 1 true' ) 2230push ( '\x1b[?25$p' , vt ) 2231expect_output ( '\x1b[?25;1$y' ) 2232push ( '\x1b[?25l' , vt ) 2233expect ( 'settermprop 1 false' ) 2234push ( '\x1b[?25$p' , vt ) 2235expect_output ( '\x1b[?25;2$y' ) 2236 2237-- Cursor blink 2238push ( '\x1b[?12h' , vt ) 2239expect ( 'settermprop 2 true' ) 2240push ( '\x1b[?12$p' , vt ) 2241expect_output ( '\x1b[?12;1$y' ) 2242push ( '\x1b[?12l' , vt ) 2243expect ( 'settermprop 2 false' ) 2244push ( '\x1b[?12$p' , vt ) 2245expect_output ( '\x1b[?12;2$y' ) 2246 2247-- Cursor shape 2248push ( '\x1b[3 q' , vt ) 2249expect ( 'settermprop 2 true\nsettermprop 7 2' ) 2250 2251-- Title 2252push ( '\x1b]2;Here is my title\a' , vt ) 2253expect ( 'settermprop 4 ["Here is my title"]' ) 2254 2255-- Title split write 2256push ( '\x1b]2;Here is' , vt ) 2257expect ( 'settermprop 4 ["Here is"' ) 2258push ( ' another title\a' , vt ) 2259expect ( 'settermprop 4 " another title"]' ) 2260end ) 2261 2262itp ( '20state_wrapping' , function () 2263local vt =init () 2264local state =wantstate ( vt , { g =true , m =true } ) 2265 2266-- 79th Column 2267push ( '\x1b[75G' , vt ) 2268push ( string . rep ( 'A' , 5 ), vt ) 2269expect ( 2270'putglyph 41 1 0,74\nputglyph 41 1 0,75\nputglyph 41 1 0,76\nputglyph 41 1 0,77\nputglyph 41 1 0,78' 2271) 2272cursor ( 0 , 79 , state ) 2273 2274-- 80th Column Phantom 2275push ( 'A' , vt ) 2276expect ( 'putglyph 41 1 0,79' ) 2277cursor ( 0 , 79 , state ) 2278 2279-- Line Wraparound 2280push ( 'B' , vt ) 2281expect ( 'putglyph 42 1 1,0' ) 2282cursor ( 1 , 1 , state ) 2283 2284-- Line Wraparound during combined write 2285push ( '\x1b[78G' , vt ) 2286push ( 'BBBCC' , vt ) 2287expect ( 2288'putglyph 42 1 1,77\nputglyph 42 1 1,78\nputglyph 42 1 1,79\nputglyph 43 1 2,0\nputglyph 43 1 2,1' 2289) 2290cursor ( 2 , 2 , state ) 2291 2292-- DEC Auto Wrap Mode 2293reset ( state , nil ) 2294push ( '\x1b[?7l' , vt ) 2295push ( '\x1b[75G' , vt ) 2296push ( string . rep ( 'D' , 6 ), vt ) 2297expect ( 2298'putglyph 44 1 0,74\nputglyph 44 1 0,75\nputglyph 44 1 0,76\nputglyph 44 1 0,77\nputglyph 44 1 0,78\nputglyph 44 1 0,79' 2299) 2300cursor ( 0 , 79 , state ) 2301push ( 'D' , vt ) 2302expect ( 'putglyph 44 1 0,79' ) 2303cursor ( 0 , 79 , state ) 2304push ( '\x1b[?7h' , vt ) 2305 2306-- 80th column causes linefeed on wraparound 2307push ( '\x1b[25;78HABC' , vt ) 2308expect ( 'putglyph 41 1 24,77\nputglyph 42 1 24,78\nputglyph 43 1 24,79' ) 2309cursor ( 24 , 79 , state ) 2310push ( 'D' , vt ) 2311expect ( 'moverect 1..25,0..80 -> 0..24,0..80\nputglyph 44 1 24,0' ) 2312 2313-- 80th column phantom linefeed phantom cancelled by explicit cursor move 2314push ( '\x1b[25;78HABC' , vt ) 2315expect ( 'putglyph 41 1 24,77\nputglyph 42 1 24,78\nputglyph 43 1 24,79' ) 2316cursor ( 24 , 79 , state ) 2317push ( '\x1b[25;1HD' , vt ) 2318expect ( 'putglyph 44 1 24,0' ) 2319end ) 2320 2321itp ( '21state_tabstops' , function () 2322local vt =init () 2323local state =wantstate ( vt , { g =true } ) 2324 2325-- Initial 2326reset ( state , nil ) 2327push ( '\tX' , vt ) 2328expect ( 'putglyph 58 1 0,8' ) 2329push ( '\tX' , vt ) 2330expect ( 'putglyph 58 1 0,16' ) 2331cursor ( 0 , 17 , state ) 2332 2333-- HTS 2334push ( '\x1b[5G\x1bH' , vt ) 2335push ( '\x1b[G\tX' , vt ) 2336expect ( 'putglyph 58 1 0,4' ) 2337cursor ( 0 , 5 , state ) 2338 2339-- TBC 0 2340push ( '\x1b[9G\x1b[g' , vt ) 2341push ( '\x1b[G\tX\tX' , vt ) 2342expect ( 'putglyph 58 1 0,4\nputglyph 58 1 0,16' ) 2343cursor ( 0 , 17 , state ) 2344 2345-- TBC 3 2346push ( '\x1b[3g\x1b[50G\x1bH\x1b[G' , vt ) 2347cursor ( 0 , 0 , state ) 2348push ( '\tX' , vt ) 2349expect ( 'putglyph 58 1 0,49' ) 2350cursor ( 0 , 50 , state ) 2351 2352-- Tabstops after resize 2353reset ( state , nil ) 2354resize ( 30 , 100 , vt ) 2355-- Should be 100/8 = 12 tabstops 2356push ( '\tX' , vt ) 2357expect ( 'putglyph 58 1 0,8' ) 2358push ( '\tX' , vt ) 2359expect ( 'putglyph 58 1 0,16' ) 2360push ( '\tX' , vt ) 2361expect ( 'putglyph 58 1 0,24' ) 2362push ( '\tX' , vt ) 2363expect ( 'putglyph 58 1 0,32' ) 2364push ( '\tX' , vt ) 2365expect ( 'putglyph 58 1 0,40' ) 2366push ( '\tX' , vt ) 2367expect ( 'putglyph 58 1 0,48' ) 2368push ( '\tX' , vt ) 2369expect ( 'putglyph 58 1 0,56' ) 2370push ( '\tX' , vt ) 2371expect ( 'putglyph 58 1 0,64' ) 2372push ( '\tX' , vt ) 2373expect ( 'putglyph 58 1 0,72' ) 2374push ( '\tX' , vt ) 2375expect ( 'putglyph 58 1 0,80' ) 2376push ( '\tX' , vt ) 2377expect ( 'putglyph 58 1 0,88' ) 2378push ( '\tX' , vt ) 2379expect ( 'putglyph 58 1 0,96' ) 2380cursor ( 0 , 97 , state ) 2381end ) 2382 2383itp ( '22state_save' , function () 2384local vt =init () 2385local state =wantstate ( vt , { p =true } ) 2386 2387reset ( state , nil ) 2388expect ( 'settermprop 1 true\nsettermprop 2 true\nsettermprop 7 1' ) 2389 2390-- Set up state 2391push ( '\x1b[2;2H' , vt ) 2392cursor ( 1 , 1 , state ) 2393push ( '\x1b[1m' , vt ) 2394pen ( 'bold' , true , state ) 2395 2396-- Save 2397push ( '\x1b[?1048h' , vt ) 2398 2399-- Change state 2400push ( '\x1b[5;5H' , vt ) 2401cursor ( 4 , 4 , state ) 2402push ( '\x1b[4 q' , vt ) 2403expect ( 'settermprop 2 false\nsettermprop 7 2' ) 2404push ( '\x1b[22;4m' , vt ) 2405pen ( 'bold' , false , state ) 2406pen ( 'underline' , 1 , state ) 2407 2408-- Restore 2409push ( '\x1b[?1048l' , vt ) 2410expect ( 'settermprop 1 true\nsettermprop 2 true\nsettermprop 7 1' ) 2411cursor ( 1 , 1 , state ) 2412pen ( 'bold' , true , state ) 2413pen ( 'underline' , 0 , state ) 2414 2415-- Save/restore using DECSC/DECRC 2416push ( '\x1b[2;2H\x1b7' , vt ) 2417cursor ( 1 , 1 , state ) 2418 2419push ( '\x1b[5;5H' , vt ) 2420cursor ( 4 , 4 , state ) 2421push ( '\x1b8' , vt ) 2422expect ( 'settermprop 1 true\nsettermprop 2 true\nsettermprop 7 1' ) 2423cursor ( 1 , 1 , state ) 2424 2425-- Save twice, restore twice happens on both edge transitions 2426push ( '\x1b[2;10H\x1b[?1048h\x1b[6;10H\x1b[?1048h' , vt ) 2427push ( '\x1b[H' , vt ) 2428cursor ( 0 , 0 , state ) 2429push ( '\x1b[?1048l' , vt ) 2430expect ( 'settermprop 1 true\nsettermprop 2 true\nsettermprop 7 1' ) 2431cursor ( 5 , 9 , state ) 2432push ( '\x1b[H' , vt ) 2433cursor ( 0 , 0 , state ) 2434push ( '\x1b[?1048l' , vt ) 2435expect ( 'settermprop 1 true\nsettermprop 2 true\nsettermprop 7 1' ) 2436cursor ( 5 , 9 , state ) 2437end ) 2438 2439itp ( '25state_input' , function () 2440local vt =init () 2441local state =wantstate ( vt ) 2442 2443-- Disambiguate escape codes enabled 2444push ( '\x1b[>1u' , vt ) 2445 2446-- Unmodified ASCII 2447inchar ( 0x41 , vt ) 2448expect_output ( 'A' ) 2449inchar ( 0x61 , vt ) 2450expect_output ( 'a' ) 2451 2452-- Ctrl modifier on ASCII letters 2453inchar ( 0x41 , vt , { C =true } ) 2454expect_output ( '\x1b[97;6u' ) 2455inchar ( 0x61 , vt , { C =true } ) 2456expect_output ( '\x1b[97;5u' ) 2457 2458-- Alt modifier on ASCII letters 2459inchar ( 0x41 , vt , { A =true } ) 2460expect_output ( '\x1b[97;4u' ) 2461inchar ( 0x61 , vt , { A =true } ) 2462expect_output ( '\x1b[97;3u' ) 2463 2464-- Ctrl-Alt modifier on ASCII letters 2465inchar ( 0x41 , vt , { C =true , A =true } ) 2466expect_output ( '\x1b[97;8u' ) 2467inchar ( 0x61 , vt , { C =true , A =true } ) 2468expect_output ( '\x1b[97;7u' ) 2469 2470-- Ctrl-I is disambiguated 2471inchar ( 0x49 , vt ) 2472expect_output ( 'I' ) 2473inchar ( 0x69 , vt ) 2474expect_output ( 'i' ) 2475inchar ( 0x49 , vt , { C =true } ) 2476expect_output ( '\x1b[105;6u' ) 2477inchar ( 0x69 , vt , { C =true } ) 2478expect_output ( '\x1b[105;5u' ) 2479inchar ( 0x49 , vt , { A =true } ) 2480expect_output ( '\x1b[105;4u' ) 2481inchar ( 0x69 , vt , { A =true } ) 2482expect_output ( '\x1b[105;3u' ) 2483inchar ( 0x49 , vt , { A =true , C =true } ) 2484expect_output ( '\x1b[105;8u' ) 2485inchar ( 0x69 , vt , { A =true , C =true } ) 2486expect_output ( '\x1b[105;7u' ) 2487 2488-- Ctrl+Digits 2489for i =0 , 9 do 2490local c =0x30 + i 2491inchar ( c , vt ) 2492expect_output ( tostring ( i )) 2493inchar ( c , vt , { C =true } ) 2494expect_output ( string . format ( '\x1b[%d;5u' , c )) 2495inchar ( c , vt , { C =true , S =true } ) 2496expect_output ( string . format ( '\x1b[%d;6u' , c )) 2497inchar ( c , vt , { C =true , A =true } ) 2498expect_output ( string . format ( '\x1b[%d;7u' , c )) 2499inchar ( c , vt , { C =true , A =true , S =true } ) 2500expect_output ( string . format ( '\x1b[%d;8u' , c )) 2501end 2502 2503-- Special handling of Space 2504inchar ( 0x20 , vt ) 2505expect_output ( ' ' ) 2506inchar ( 0x20 , vt , { S =true } ) 2507expect_output ( '\x1b[32;2u' ) 2508inchar ( 0x20 , vt , { C =true } ) 2509expect_output ( '\x1b[32;5u' ) 2510inchar ( 0x20 , vt , { C =true , S =true } ) 2511expect_output ( '\x1b[32;6u' ) 2512inchar ( 0x20 , vt , { A =true } ) 2513expect_output ( '\x1b[32;3u' ) 2514inchar ( 0x20 , vt , { S =true , A =true } ) 2515expect_output ( '\x1b[32;4u' ) 2516inchar ( 0x20 , vt , { C =true , A =true } ) 2517expect_output ( '\x1b[32;7u' ) 2518inchar ( 0x20 , vt , { S =true , C =true , A =true } ) 2519expect_output ( '\x1b[32;8u' ) 2520 2521-- Cursor keys in reset (cursor) mode 2522inkey ( 'up' , vt ) 2523expect_output ( '\x1b[A' ) 2524inkey ( 'up' , vt , { S =true } ) 2525expect_output ( '\x1b[1;2A' ) 2526inkey ( 'up' , vt , { C =true } ) 2527expect_output ( '\x1b[1;5A' ) 2528inkey ( 'up' , vt , { S =true , C =true } ) 2529expect_output ( '\x1b[1;6A' ) 2530inkey ( 'up' , vt , { A =true } ) 2531expect_output ( '\x1b[1;3A' ) 2532inkey ( 'up' , vt , { S =true , A =true } ) 2533expect_output ( '\x1b[1;4A' ) 2534inkey ( 'up' , vt , { C =true , A =true } ) 2535expect_output ( '\x1b[1;7A' ) 2536inkey ( 'up' , vt , { S =true , C =true , A =true } ) 2537expect_output ( '\x1b[1;8A' ) 2538 2539-- Cursor keys in application mode 2540push ( '\x1b[?1h' , vt ) 2541-- Plain "Up" should be SS3 A now 2542inkey ( 'up' , vt ) 2543expect_output ( '\x1bOA' ) 2544-- Modified keys should still use CSI 2545inkey ( 'up' , vt , { S =true } ) 2546expect_output ( '\x1b[1;2A' ) 2547inkey ( 'up' , vt , { C =true } ) 2548expect_output ( '\x1b[1;5A' ) 2549 2550-- Tab 2551inkey ( 'tab' , vt ) 2552expect_output ( '\x09' ) 2553inkey ( 'tab' , vt , { S =true } ) 2554expect_output ( '\x1b[9;2u' ) 2555inkey ( 'tab' , vt , { C =true } ) 2556expect_output ( '\x1b[9;5u' ) 2557inkey ( 'tab' , vt , { A =true } ) 2558expect_output ( '\x1b[9;3u' ) 2559inkey ( 'tab' , vt , { C =true , A =true } ) 2560expect_output ( '\x1b[9;7u' ) 2561 2562-- Backspace 2563inkey ( 'bs' , vt ) 2564expect_output ( '\x7f' ) 2565inkey ( 'bs' , vt , { S =true } ) 2566expect_output ( '\x1b[127;2u' ) 2567inkey ( 'bs' , vt , { C =true } ) 2568expect_output ( '\x1b[127;5u' ) 2569inkey ( 'bs' , vt , { A =true } ) 2570expect_output ( '\x1b[127;3u' ) 2571inkey ( 'bs' , vt , { C =true , A =true } ) 2572expect_output ( '\x1b[127;7u' ) 2573 2574-- DEL 2575inkey ( 'del' , vt ) 2576expect_output ( '\x1b[3~' ) 2577inkey ( 'del' , vt , { S =true } ) 2578expect_output ( '\x1b[3;2~' ) 2579inkey ( 'del' , vt , { C =true } ) 2580expect_output ( '\x1b[3;5~' ) 2581inkey ( 'del' , vt , { A =true } ) 2582expect_output ( '\x1b[3;3~' ) 2583inkey ( 'del' , vt , { C =true , A =true } ) 2584expect_output ( '\x1b[3;7~' ) 2585 2586-- ESC 2587inkey ( 'esc' , vt ) 2588expect_output ( '\x1b[27;1u' ) 2589inkey ( 'esc' , vt , { S =true } ) 2590expect_output ( '\x1b[27;2u' ) 2591inkey ( 'esc' , vt , { C =true } ) 2592expect_output ( '\x1b[27;5u' ) 2593inkey ( 'esc' , vt , { A =true } ) 2594expect_output ( '\x1b[27;3u' ) 2595inkey ( 'esc' , vt , { C =true , A =true } ) 2596expect_output ( '\x1b[27;7u' ) 2597 2598-- Enter in linefeed mode 2599inkey ( 'enter' , vt ) 2600expect_output ( '\x0d' ) 2601inkey ( 'enter' , vt , { S =true } ) 2602expect_output ( '\x1b[13;2u' ) 2603inkey ( 'enter' , vt , { C =true } ) 2604expect_output ( '\x1b[13;5u' ) 2605inkey ( 'enter' , vt , { A =true } ) 2606expect_output ( '\x1b[13;3u' ) 2607inkey ( 'enter' , vt , { C =true , A =true } ) 2608expect_output ( '\x1b[13;7u' ) 2609 2610-- Enter in newline mode 2611push ( '\x1b[20h' , vt ) 2612inkey ( 'enter' , vt ) 2613expect_output ( '\x0d\x0a' ) 2614 2615-- Unmodified F1 is SS3 P 2616inkey ( 'f1' , vt ) 2617expect_output ( '\x1bOP' ) 2618 2619-- Modified F1 is CSI P 2620inkey ( 'f1' , vt , { S =true } ) 2621expect_output ( '\x1b[1;2P' ) 2622inkey ( 'f1' , vt , { A =true } ) 2623expect_output ( '\x1b[1;3P' ) 2624inkey ( 'f1' , vt , { C =true } ) 2625expect_output ( '\x1b[1;5P' ) 2626 2627-- Keypad in DECKPNM 2628inkey ( 'kp0' , vt ) 2629expect_output ( '\x1b[57399;1u' ) 2630 2631-- Keypad in DECKPAM 2632push ( '\x1b=' , vt ) 2633inkey ( 'kp0' , vt ) 2634expect_output ( '\x1bOp' ) 2635 2636-- Bracketed paste mode off 2637vterm . vterm_keyboard_start_paste ( vt ) 2638vterm . vterm_keyboard_end_paste ( vt ) 2639 2640-- Bracketed paste mode on 2641push ( '\x1b[?2004h' , vt ) 2642vterm . vterm_keyboard_start_paste ( vt ) 2643expect_output ( '\x1b[200~' ) 2644vterm . vterm_keyboard_end_paste ( vt ) 2645expect_output ( '\x1b[201~' ) 2646 2647-- Focus reporting disabled 2648vterm . vterm_state_focus_in ( state ) 2649vterm . vterm_state_focus_out ( state ) 2650 2651-- Focus reporting enabled 2652state =wantstate ( vt , { p =true } ) 2653push ( '\x1b[?1004h' , vt ) 2654expect ( 'settermprop 9 true' ) 2655vterm . vterm_state_focus_in ( state ) 2656expect_output ( '\x1b[I' ) 2657vterm . vterm_state_focus_out ( state ) 2658expect_output ( '\x1b[O' ) 2659 2660-- Synchronized output mode 2026 2661push ( '\x1b[?2026h' , vt ) 2662expect ( 'settermprop 11 true' ) 2663push ( '\x1b[?2026l' , vt ) 2664expect ( 'settermprop 11 false' ) 2665 2666-- DECRQM on synchronized output 2667push ( '\x1b[?2026h' , vt ) 2668expect ( 'settermprop 11 true' ) 2669push ( '\x1b[?2026$p' , vt ) 2670expect_output ( '\x1b[?2026;1$y' ) 2671push ( '\x1b[?2026l' , vt ) 2672expect ( 'settermprop 11 false' ) 2673push ( '\x1b[?2026$p' , vt ) 2674expect_output ( '\x1b[?2026;2$y' ) 2675 2676-- Disambiguate escape codes disabled 2677push ( '\x1b[<u' , vt ) 2678 2679-- Unmodified ASCII 2680inchar ( 0x41 , vt ) 2681expect_output ( 'A' ) 2682inchar ( 0x61 , vt ) 2683expect_output ( 'a' ) 2684 2685-- Ctrl modifier on ASCII letters 2686inchar ( 0x41 , vt , { C =true } ) 2687expect_output ( '\x01' ) 2688inchar ( 0x61 , vt , { C =true } ) 2689expect_output ( '\x01' ) 2690 2691-- Alt modifier on ASCII letters 2692inchar ( 0x41 , vt , { A =true } ) 2693expect_output ( '\x1bA' ) 2694inchar ( 0x61 , vt , { A =true } ) 2695expect_output ( '\x1ba' ) 2696 2697-- Ctrl-Alt modifier on ASCII letters 2698inchar ( 0x41 , vt , { C =true , A =true } ) 2699expect_output ( '\x1b\x01' ) 2700inchar ( 0x61 , vt , { C =true , A =true } ) 2701expect_output ( '\x1b\x01' ) 2702 2703-- Ctrl-I is ambiguous 2704inchar ( 0x49 , vt ) 2705expect_output ( 'I' ) 2706inchar ( 0x69 , vt ) 2707expect_output ( 'i' ) 2708inchar ( 0x49 , vt , { C =true } ) 2709expect_output ( '\x09' ) 2710inchar ( 0x69 , vt , { C =true } ) 2711expect_output ( '\x09' ) 2712inchar ( 0x49 , vt , { A =true } ) 2713expect_output ( '\x1bI' ) 2714inchar ( 0x69 , vt , { A =true } ) 2715expect_output ( '\x1bi' ) 2716inchar ( 0x49 , vt , { A =true , C =true } ) 2717expect_output ( '\x1b\x09' ) 2718inchar ( 0x69 , vt , { A =true , C =true } ) 2719expect_output ( '\x1b\x09' ) 2720 2721-- Ctrl+Digits 2722inchar ( 0x30 , vt , { C =true } ) 2723expect_output ( '0' ) 2724inchar ( 0x31 , vt , { C =true } ) 2725expect_output ( '1' ) 2726inchar ( 0x32 , vt , { C =true } ) 2727expect_output ( '\x00' ) 2728inchar ( 0x33 , vt , { C =true } ) 2729expect_output ( '\x1b' ) 2730inchar ( 0x34 , vt , { C =true } ) 2731expect_output ( '\x1c' ) 2732inchar ( 0x35 , vt , { C =true } ) 2733expect_output ( '\x1d' ) 2734inchar ( 0x36 , vt , { C =true } ) 2735expect_output ( '\x1e' ) 2736inchar ( 0x37 , vt , { C =true } ) 2737expect_output ( '\x1f' ) 2738inchar ( 0x38 , vt , { C =true } ) 2739expect_output ( '\x7f' ) 2740inchar ( 0x39 , vt , { C =true } ) 2741expect_output ( '9' ) 2742 2743-- Ctrl+/ 2744inchar ( 0x2F , vt , { C =true } ) 2745expect_output ( '\x1f' ) 2746end ) 2747 2748itp ( '26state_query' , function () 2749local vt =init () 2750local state =wantstate ( vt ) 2751 2752-- DA 2753reset ( state , nil ) 2754push ( '\x1b[c' , vt ) 2755expect_output ( '\x1b[?61;22;52c' ) 2756 2757-- XTVERSION 2758reset ( state , nil ) 2759push ( '\x1b[>q' , vt ) 2760expect_output ( '\x1bP>|libvterm(0.3)\x1b\\' ) 2761 2762-- DSR 2763reset ( state , nil ) 2764push ( '\x1b[5n' , vt ) 2765expect_output ( '\x1b[0n' ) 2766 2767-- CPR 2768push ( '\x1b[6n' , vt ) 2769expect_output ( '\x1b[1;1R' ) 2770push ( '\x1b[10;10H\x1b[6n' , vt ) 2771expect_output ( '\x1b[10;10R' ) 2772 2773-- DECCPR 2774push ( '\x1b[?6n' , vt ) 2775expect_output ( '\x1b[?10;10R' ) 2776 2777-- DECRQSS on DECSCUSR 2778push ( '\x1b[3 q' , vt ) 2779push ( '\x1bP$q q\x1b\\' , vt ) 2780expect_output ( '\x1bP1$r3 q\x1b\\' ) 2781 2782-- DECRQSS on SGR 2783push ( '\x1b[1;5;7m' , vt ) 2784push ( '\x1bP$qm\x1b\\' , vt ) 2785expect_output ( '\x1bP1$r1;5;7m\x1b\\' ) 2786 2787-- DECRQSS on SGR ANSI colours 2788push ( '\x1b[0;31;42m' , vt ) 2789push ( '\x1bP$qm\x1b\\' , vt ) 2790expect_output ( '\x1bP1$r31;42m\x1b\\' ) 2791 2792-- DECRQSS on SGR ANSI hi-bright colours 2793push ( '\x1b[0;93;104m' , vt ) 2794push ( '\x1bP$qm\x1b\\' , vt ) 2795expect_output ( '\x1bP1$r93;104m\x1b\\' ) 2796 2797-- DECRQSS on SGR 256-palette colours 2798push ( '\x1b[0;38:5:56;48:5:78m' , vt ) 2799push ( '\x1bP$qm\x1b\\' , vt ) 2800expect_output ( '\x1bP1$r38:5:56;48:5:78m\x1b\\' ) 2801 2802-- DECRQSS on SGR RGB8 colours 2803push ( '\x1b[0;38:2:24:68:112;48:2:13:57:101m' , vt ) 2804push ( '\x1bP$qm\x1b\\' , vt ) 2805expect_output ( '\x1bP1$r38:2:24:68:112;48:2:13:57:101m\x1b\\' ) 2806 2807-- S8C1T on DSR 2808push ( '\x1b G' , vt ) 2809push ( '\x1b[5n' , vt ) 2810expect_output ( '\x9b0n' ) 2811push ( '\x1b F' , vt ) 2812end ) 2813 2814itp ( '27state_reset' , function () 2815local vt =init () 2816local state =wantstate ( vt ) 2817 2818reset ( state , nil ) 2819 2820-- RIS homes cursor 2821push ( '\x1b[5;5H' , vt ) 2822cursor ( 4 , 4 , state ) 2823state =wantstate ( vt , { m =true } ) 2824push ( '\x1bc' , vt ) 2825cursor ( 0 , 0 , state ) 2826wantstate ( vt ) 2827 2828-- RIS cancels scrolling region 2829push ( '\x1b[5;10r' , vt ) 2830wantstate ( vt , { s =true } ) 2831push ( '\x1bc\x1b[25H\n' , vt ) 2832expect ( 'scrollrect 0..25,0..80 => +1,+0' ) 2833wantstate ( vt ) 2834 2835-- RIS erases screen 2836push ( 'ABCDE' , vt ) 2837state =wantstate ( vt , { e =true } ) 2838push ( '\x1bc' , vt ) 2839expect ( 'erase 0..25,0..80' ) 2840wantstate ( vt ) 2841 2842-- RIS clears tabstops 2843push ( '\x1b[5G\x1bH\x1b[G\t' , vt ) 2844cursor ( 0 , 4 , state ) 2845push ( '\x1bc\t' , vt ) 2846cursor ( 0 , 8 , state ) 2847end ) 2848 2849itp ( '28state_dbl_wh' , function () 2850local vt =init () 2851local state =wantstate ( vt , { g =true } ) 2852 2853-- Single Width, Single Height 2854reset ( state , nil ) 2855push ( '\x1b#5' , vt ) 2856push ( 'Hello' , vt ) 2857expect ( 2858'putglyph 48 1 0,0\nputglyph 65 1 0,1\nputglyph 6c 1 0,2\nputglyph 6c 1 0,3\nputglyph 6f 1 0,4' 2859) 2860 2861-- Double Width, Single Height 2862reset ( state , nil ) 2863push ( '\x1b#6' , vt ) 2864push ( 'Hello' , vt ) 2865expect ( 2866'putglyph 48 1 0,0 dwl\nputglyph 65 1 0,1 dwl\nputglyph 6c 1 0,2 dwl\nputglyph 6c 1 0,3 dwl\nputglyph 6f 1 0,4 dwl' 2867) 2868cursor ( 0 , 5 , state ) 2869push ( '\x1b[40GAB' , vt ) 2870expect ( 'putglyph 41 1 0,39 dwl\nputglyph 42 1 1,0' ) 2871cursor ( 1 , 1 , state ) 2872 2873-- Double Height 2874reset ( state , nil ) 2875push ( '\x1b#3' , vt ) 2876push ( 'Hello' , vt ) 2877expect ( 2878'putglyph 48 1 0,0 dwl dhl-top\nputglyph 65 1 0,1 dwl dhl-top\nputglyph 6c 1 0,2 dwl dhl-top\nputglyph 6c 1 0,3 dwl dhl-top\nputglyph 6f 1 0,4 dwl dhl-top' 2879) 2880cursor ( 0 , 5 , state ) 2881push ( '\r\n\x1b#4' , vt ) 2882push ( 'Hello' , vt ) 2883expect ( 2884'putglyph 48 1 1,0 dwl dhl-bottom\nputglyph 65 1 1,1 dwl dhl-bottom\nputglyph 6c 1 1,2 dwl dhl-bottom\nputglyph 6c 1 1,3 dwl dhl-bottom\nputglyph 6f 1 1,4 dwl dhl-bottom' 2885) 2886cursor ( 1 , 5 , state ) 2887 2888-- Double Width scrolling 2889reset ( state , nil ) 2890push ( '\x1b[20H\x1b#6ABC' , vt ) 2891expect ( 'putglyph 41 1 19,0 dwl\nputglyph 42 1 19,1 dwl\nputglyph 43 1 19,2 dwl' ) 2892push ( '\x1b[25H\n' , vt ) 2893push ( '\x1b[19;4HDE' , vt ) 2894expect ( 'putglyph 44 1 18,3 dwl\nputglyph 45 1 18,4 dwl' ) 2895push ( '\x1b[H\x1bM' , vt ) 2896push ( '\x1b[20;6HFG' , vt ) 2897expect ( 'putglyph 46 1 19,5 dwl\nputglyph 47 1 19,6 dwl' ) 2898end ) 2899 2900itp ( '29state_fallback' , function () 2901local vt =init () 2902local state =wantstate ( vt , { f =true } ) 2903reset ( state , nil ) 2904 2905-- Unrecognised control 2906push ( '\x03' , vt ) 2907expect ( 'control 03' ) 2908 2909-- Unrecognised CSI 2910push ( '\x1b[?15;2z' , vt ) 2911expect ( 'csi 7a L=3f 15,2' ) 2912 2913-- Unrecognised OSC 2914push ( '\x1b]27;Something\x1b\\' , vt ) 2915expect ( 'osc [27;Something]' ) 2916 2917-- Unrecognised DCS 2918push ( '\x1bPz123\x1b\\' , vt ) 2919expect ( 'dcs [z123]' ) 2920 2921-- Unrecognised APC 2922push ( '\x1b_z123\x1b\\' , vt ) 2923expect ( 'apc [z123]' ) 2924 2925-- Unrecognised PM 2926push ( '\x1b^z123\x1b\\' , vt ) 2927expect ( 'pm [z123]' ) 2928 2929-- Unrecognised SOS 2930push ( '\x1bXz123\x1b\\' , vt ) 2931expect ( 'sos [z123]' ) 2932end ) 2933 2934itp ( '30state_pen' , function () 2935local vt =init () 2936local state =wantstate ( vt ) 2937 2938-- Reset 2939push ( '\x1b[m' , vt ) 2940pen ( 'bold' , false , state ) 2941pen ( 'underline' , 0 , state ) 2942pen ( 'italic' , false , state ) 2943pen ( 'blink' , false , state ) 2944pen ( 'reverse' , false , state ) 2945pen ( 'font' , 0 , state ) 2946-- TODO(dundargoc): fix 2947-- ?pen foreground = rgb(240,240,240,is_default_fg) 2948-- ?pen background = rgb(0,0,0,is_default_bg) 2949 2950-- Bold 2951push ( '\x1b[1m' , vt ) 2952pen ( 'bold' , true , state ) 2953push ( '\x1b[22m' , vt ) 2954pen ( 'bold' , false , state ) 2955push ( '\x1b[1m\x1b[m' , vt ) 2956pen ( 'bold' , false , state ) 2957 2958-- Underline 2959push ( '\x1b[4m' , vt ) 2960pen ( 'underline' , 1 , state ) 2961push ( '\x1b[21m' , vt ) 2962pen ( 'underline' , 2 , state ) 2963push ( '\x1b[24m' , vt ) 2964pen ( 'underline' , 0 , state ) 2965push ( '\x1b[4m\x1b[4:0m' , vt ) 2966pen ( 'underline' , 0 , state ) 2967push ( '\x1b[4:1m' , vt ) 2968pen ( 'underline' , 1 , state ) 2969push ( '\x1b[4:2m' , vt ) 2970pen ( 'underline' , 2 , state ) 2971push ( '\x1b[4:3m' , vt ) 2972pen ( 'underline' , 3 , state ) 2973push ( '\x1b[4m\x1b[m' , vt ) 2974pen ( 'underline' , 0 , state ) 2975 2976-- Italic 2977push ( '\x1b[3m' , vt ) 2978pen ( 'italic' , true , state ) 2979push ( '\x1b[23m' , vt ) 2980pen ( 'italic' , false , state ) 2981push ( '\x1b[3m\x1b[m' , vt ) 2982pen ( 'italic' , false , state ) 2983 2984-- Blink 2985push ( '\x1b[5m' , vt ) 2986pen ( 'blink' , true , state ) 2987push ( '\x1b[25m' , vt ) 2988pen ( 'blink' , false , state ) 2989push ( '\x1b[5m\x1b[m' , vt ) 2990pen ( 'blink' , false , state ) 2991 2992-- Reverse 2993push ( '\x1b[7m' , vt ) 2994pen ( 'reverse' , true , state ) 2995push ( '\x1b[27m' , vt ) 2996pen ( 'reverse' , false , state ) 2997push ( '\x1b[7m\x1b[m' , vt ) 2998pen ( 'reverse' , false , state ) 2999 3000-- Font Selection 3001push ( '\x1b[11m' , vt ) 3002pen ( 'font' , 1 , state ) 3003push ( '\x1b[19m' , vt ) 3004pen ( 'font' , 9 , state ) 3005push ( '\x1b[10m' , vt ) 3006pen ( 'font' , 0 , state ) 3007push ( '\x1b[11m\x1b[m' , vt ) 3008pen ( 'font' , 0 , state ) 3009 3010-- Dim 3011push ( '\x1b[2m' , vt ) 3012pen ( 'dim' , true , state ) 3013push ( '\x1b[22m' , vt ) 3014pen ( 'dim' , false , state ) 3015push ( '\x1b[2m\x1b[m' , vt ) 3016pen ( 'dim' , false , state ) 3017 3018-- Bold and Dim interaction (SGR 22 turns off both) 3019push ( '\x1b[1;2m' , vt ) 3020pen ( 'bold' , true , state ) 3021pen ( 'dim' , true , state ) 3022push ( '\x1b[22m' , vt ) 3023pen ( 'bold' , false , state ) 3024pen ( 'dim' , false , state ) 3025 3026-- Overline 3027push ( '\x1b[53m' , vt ) 3028pen ( 'overline' , true , state ) 3029push ( '\x1b[55m' , vt ) 3030pen ( 'overline' , false , state ) 3031push ( '\x1b[53m\x1b[m' , vt ) 3032pen ( 'overline' , false , state ) 3033 3034-- TODO(dundargoc): fix 3035-- Foreground 3036-- push "\x1b[31m" 3037-- ?pen foreground = idx(1) 3038-- push "\x1b[32m" 3039-- ?pen foreground = idx(2) 3040-- push "\x1b[34m" 3041-- ?pen foreground = idx(4) 3042-- push "\x1b[91m" 3043-- ?pen foreground = idx(9) 3044-- push "\x1b[38:2:10:20:30m" 3045-- ?pen foreground = rgb(10,20,30) 3046-- push "\x1b[38:5:1m" 3047-- ?pen foreground = idx(1) 3048-- push "\x1b[39m" 3049-- ?pen foreground = rgb(240,240,240,is_default_fg) 3050-- 3051-- Background 3052-- push "\x1b[41m" 3053-- ?pen background = idx(1) 3054-- push "\x1b[42m" 3055-- ?pen background = idx(2) 3056-- push "\x1b[44m" 3057-- ?pen background = idx(4) 3058-- push "\x1b[101m" 3059-- ?pen background = idx(9) 3060-- push "\x1b[48:2:10:20:30m" 3061-- ?pen background = rgb(10,20,30) 3062-- push "\x1b[48:5:1m" 3063-- ?pen background = idx(1) 3064-- push "\x1b[49m" 3065-- ?pen background = rgb(0,0,0,is_default_bg) 3066-- 3067-- Bold+ANSI colour == highbright 3068-- push "\x1b[m\x1b[1;37m" 3069-- ?pen bold = on 3070-- ?pen foreground = idx(15) 3071-- push "\x1b[m\x1b[37;1m" 3072-- ?pen bold = on 3073-- ?pen foreground = idx(15) 3074-- 3075-- Super/Subscript 3076-- push "\x1b[73m" 3077-- ?pen small = on 3078-- ?pen baseline = raise 3079-- push "\x1b[74m" 3080-- ?pen small = on 3081-- ?pen baseline = lower 3082-- push "\x1b[75m" 3083-- ?pen small = off 3084-- ?pen baseline = normal 3085-- 3086-- DECSTR resets pen attributes 3087-- push "\x1b[1;4m" 3088-- ?pen bold = on 3089-- ?pen underline = 1 3090-- push "\x1b[!p" 3091-- ?pen bold = off 3092-- ?pen underline = 0 3093end ) 3094 3095itp ( '31state_rep' , function () 3096local vt =init () 3097local state =wantstate ( vt , { g =true } ) 3098 3099-- REP no argument 3100reset ( state , nil ) 3101push ( 'a\x1b[b' , vt ) 3102expect ( 'putglyph 61 1 0,0\nputglyph 61 1 0,1' ) 3103 3104-- REP zero (zero should be interpreted as one) 3105reset ( state , nil ) 3106push ( 'a\x1b[0b' , vt ) 3107expect ( 'putglyph 61 1 0,0\nputglyph 61 1 0,1' ) 3108 3109-- REP lowercase a times two 3110reset ( state , nil ) 3111push ( 'a\x1b[2b' , vt ) 3112expect ( 'putglyph 61 1 0,0\nputglyph 61 1 0,1\nputglyph 61 1 0,2' ) 3113 3114-- REP with UTF-8 1 char 3115-- U+00E9 = C3 A9 name: LATIN SMALL LETTER E WITH ACUTE 3116reset ( state , nil ) 3117push ( '\xC3\xA9\x1b[b' , vt ) 3118expect ( 'putglyph e9 1 0,0\nputglyph e9 1 0,1' ) 3119 3120-- REP with UTF-8 wide char 3121-- U+00E9 = C3 A9 name: LATIN SMALL LETTER E WITH ACUTE 3122reset ( state , nil ) 3123push ( '\xEF\xBC\x90\x1b[b' , vt ) 3124expect ( 'putglyph ff10 2 0,0\nputglyph ff10 2 0,2' ) 3125 3126-- REP with UTF-8 combining character 3127reset ( state , nil ) 3128push ( 'e\xCC\x81\x1b[b' , vt ) 3129expect ( 'putglyph 65,301 1 0,0\nputglyph 65,301 1 0,1' ) 3130 3131-- REP till end of line 3132reset ( state , nil ) 3133push ( 'a\x1b[1000bb' , vt ) 3134expect ( 3135'putglyph 61 1 0,0\nputglyph 61 1 0,1\nputglyph 61 1 0,2\nputglyph 61 1 0,3\nputglyph 61 1 0,4\nputglyph 61 1 0,5\nputglyph 61 1 0,6\nputglyph 61 1 0,7\nputglyph 61 1 0,8\nputglyph 61 1 0,9\nputglyph 61 1 0,10\nputglyph 61 1 0,11\nputglyph 61 1 0,12\nputglyph 61 1 0,13\nputglyph 61 1 0,14\nputglyph 61 1 0,15\nputglyph 61 1 0,16\nputglyph 61 1 0,17\nputglyph 61 1 0,18\nputglyph 61 1 0,19\nputglyph 61 1 0,20\nputglyph 61 1 0,21\nputglyph 61 1 0,22\nputglyph 61 1 0,23\nputglyph 61 1 0,24\nputglyph 61 1 0,25\nputglyph 61 1 0,26\nputglyph 61 1 0,27\nputglyph 61 1 0,28\nputglyph 61 1 0,29\nputglyph 61 1 0,30\nputglyph 61 1 0,31\nputglyph 61 1 0,32\nputglyph 61 1 0,33\nputglyph 61 1 0,34\nputglyph 61 1 0,35\nputglyph 61 1 0,36\nputglyph 61 1 0,37\nputglyph 61 1 0,38\nputglyph 61 1 0,39\nputglyph 61 1 0,40\nputglyph 61 1 0,41\nputglyph 61 1 0,42\nputglyph 61 1 0,43\nputglyph 61 1 0,44\nputglyph 61 1 0,45\nputglyph 61 1 0,46\nputglyph 61 1 0,47\nputglyph 61 1 0,48\nputglyph 61 1 0,49\nputglyph 61 1 0,50\nputglyph 61 1 0,51\nputglyph 61 1 0,52\nputglyph 61 1 0,53\nputglyph 61 1 0,54\nputglyph 61 1 0,55\nputglyph 61 1 0,56\nputglyph 61 1 0,57\nputglyph 61 1 0,58\nputglyph 61 1 0,59\nputglyph 61 1 0,60\nputglyph 61 1 0,61\nputglyph 61 1 0,62\nputglyph 61 1 0,63\nputglyph 61 1 0,64\nputglyph 61 1 0,65\nputglyph 61 1 0,66\nputglyph 61 1 0,67\nputglyph 61 1 0,68\nputglyph 61 1 0,69\nputglyph 61 1 0,70\nputglyph 61 1 0,71\nputglyph 61 1 0,72\nputglyph 61 1 0,73\nputglyph 61 1 0,74\nputglyph 61 1 0,75\nputglyph 61 1 0,76\nputglyph 61 1 0,77\nputglyph 61 1 0,78\nputglyph 61 1 0,79\nputglyph 62 1 1,0' 3136) 3137end ) 3138 3139itp ( '32state_flow' , function () 3140local vt =init () 3141local state =wantstate ( vt ) 3142 3143-- Many of these test cases inspired by 3144-- https://blueprints.launchpad.net/libvterm/+spec/reflow-cases 3145 3146-- Spillover text marks continuation on second line 3147reset ( state , nil ) 3148push ( string . rep ( 'A' , 100 ), vt ) 3149push ( '\r\n' , vt ) 3150lineinfo ( 0 , {} , state ) 3151lineinfo ( 1 , { cont =true } , state ) 3152 3153-- CRLF in column 80 does not mark continuation 3154reset ( state , nil ) 3155push ( string . rep ( 'B' , 80 ), vt ) 3156push ( '\r\n' , vt ) 3157push ( string . rep ( 'B' , 20 ), vt ) 3158push ( '\r\n' , vt ) 3159lineinfo ( 0 , {} , state ) 3160lineinfo ( 1 , {} , state ) 3161 3162-- EL cancels continuation of following line 3163reset ( state , nil ) 3164push ( string . rep ( 'D' , 100 ), vt ) 3165lineinfo ( 1 , { cont =true } , state ) 3166push ( '\x1bM\x1b[79G\x1b[K' , vt ) 3167lineinfo ( 1 , {} , state ) 3168end ) 3169 3170itp ( '40state_selection' , function () 3171local vt =init () 3172wantstate ( vt ) 3173 3174-- Set clipboard; final chunk len 4 3175push ( '\x1b]52;c;SGVsbG8s\x1b\\' , vt ) 3176expect ( 'selection-set mask=0001 [Hello,]' ) 3177 3178-- Set clipboard; final chunk len 3 3179push ( '\x1b]52;c;SGVsbG8sIHc=\x1b\\' , vt ) 3180expect ( 'selection-set mask=0001 [Hello, w]' ) 3181 3182-- Set clipboard; final chunk len 2 3183push ( '\x1b]52;c;SGVsbG8sIHdvcmxkCg==\x1b\\' , vt ) 3184expect ( 'selection-set mask=0001 [Hello, world\n]' ) 3185 3186-- Set clipboard; split between chunks 3187push ( '\x1b]52;c;SGVs' , vt ) 3188expect ( 'selection-set mask=0001 [Hel' ) 3189push ( 'bG8s\x1b\\' , vt ) 3190expect ( 'selection-set mask=0001 lo,]' ) 3191 3192-- Set clipboard; split within chunk 3193push ( '\x1b]52;c;SGVsbG' , vt ) 3194expect ( 'selection-set mask=0001 [Hel' ) 3195push ( '8s\x1b\\' , vt ) 3196expect ( 'selection-set mask=0001 lo,]' ) 3197 3198-- Set clipboard; empty first chunk 3199push ( '\x1b]52;c;' , vt ) 3200push ( 'SGVsbG8s\x1b\\' , vt ) 3201expect ( 'selection-set mask=0001 [Hello,]' ) 3202 3203-- Set clipboard; empty final chunk 3204push ( '\x1b]52;c;SGVsbG8s' , vt ) 3205expect ( 'selection-set mask=0001 [Hello,' ) 3206push ( '\x1b\\' , vt ) 3207expect ( 'selection-set mask=0001 ]' ) 3208 3209-- Set clipboard; longer than buffer 3210push ( '\x1b]52;c;' .. string . rep ( 'LS0t' , 10 ) .. '\x1b\\' , vt ) 3211expect ( 'selection-set mask=0001 [---------------\nselection-set mask=0001 ---------------]' ) 3212 3213-- Clear clipboard 3214push ( '\x1b]52;c;\x1b\\' , vt ) 3215expect ( 'selection-set mask=0001 []' ) 3216 3217-- Set invalid data clears and ignores 3218push ( '\x1b]52;c;SGVs*SGVsbG8s\x1b\\' , vt ) 3219expect ( 'selection-set mask=0001 []' ) 3220 3221-- Query clipboard 3222push ( '\x1b]52;c;?\x1b\\' , vt ) 3223expect ( 'selection-query mask=0001' ) 3224 3225-- TODO(dundargoc): fix 3226-- Send clipboard; final chunk len 4 3227-- SELECTION 1 ["Hello,"] 3228-- output "\x1b]52;c;" 3229-- output "SGVsbG8s" 3230-- output "\x1b\\" 3231-- 3232-- Send clipboard; final chunk len 3 3233-- SELECTION 1 ["Hello, w"] 3234-- output "\x1b]52;c;" 3235-- output "SGVsbG8s" 3236-- output "IHc=\x1b\\" 3237-- 3238-- Send clipboard; final chunk len 2 3239-- SELECTION 1 ["Hello, world\n"] 3240-- output "\x1b]52;c;" 3241-- output "SGVsbG8sIHdvcmxk" 3242-- output "Cg==\x1b\\" 3243-- 3244-- Send clipboard; split between chunks 3245-- SELECTION 1 ["Hel" 3246-- output "\x1b]52;c;" 3247-- output "SGVs" 3248-- SELECTION 1 "lo,"] 3249-- output "bG8s" 3250-- output "\x1b\\" 3251-- 3252-- Send clipboard; split within chunk 3253-- SELECTION 1 ["Hello" 3254-- output "\x1b]52;c;" 3255-- output "SGVs" 3256-- SELECTION 1 ","] 3257-- output "bG8s" 3258-- output "\x1b\\" 3259end ) 3260 3261itp ( '60screen_ascii' , function () 3262local vt =init () 3263local screen =wantscreen ( vt , { a =true , c =true } ) 3264 3265-- Get 3266reset ( nil , screen ) 3267push ( 'ABC' , vt ) 3268expect ( 'movecursor 0,3' ) 3269screen_chars ( 0 , 0 , 1 , 3 , 'ABC' , screen ) 3270screen_chars ( 0 , 0 , 1 , 80 , 'ABC' , screen ) 3271screen_text ( 0 , 0 , 1 , 3 , '41,42,43' , screen ) 3272screen_text ( 0 , 0 , 1 , 80 , '41,42,43' , screen ) 3273screen_cell ( 0 , 0 , '{41} width=1 attrs={} fg=rgb(240,240,240) bg=rgb(0,0,0)' , screen ) 3274screen_cell ( 0 , 1 , '{42} width=1 attrs={} fg=rgb(240,240,240) bg=rgb(0,0,0)' , screen ) 3275screen_cell ( 0 , 2 , '{43} width=1 attrs={} fg=rgb(240,240,240) bg=rgb(0,0,0)' , screen ) 3276screen_row ( 0 , 'ABC' , screen ) 3277screen_eol ( 0 , 0 , 0 , screen ) 3278screen_eol ( 0 , 2 , 0 , screen ) 3279screen_eol ( 0 , 3 , 1 , screen ) 3280push ( '\x1b[H' , vt ) 3281expect ( 'movecursor 0,0' ) 3282screen_row ( 0 , 'ABC' , screen ) 3283screen_text ( 0 , 0 , 1 , 80 , '41,42,43' , screen ) 3284push ( 'E' , vt ) 3285expect ( 'movecursor 0,1' ) 3286screen_row ( 0 , 'EBC' , screen ) 3287screen_text ( 0 , 0 , 1 , 80 , '45,42,43' , screen ) 3288 3289screen =wantscreen ( vt , { a =true } ) 3290 3291-- Erase 3292reset ( nil , screen ) 3293push ( 'ABCDE\x1b[H\x1b[K' , vt ) 3294-- TODO(dundargoc): fix 3295-- screen_row(0, '', screen) 3296screen_text ( 0 , 0 , 1 , 80 , '' , screen ) 3297 3298-- Copycell 3299reset ( nil , screen ) 3300push ( 'ABC\x1b[H\x1b[@' , vt ) 3301push ( '1' , vt ) 3302screen_row ( 0 , '1ABC' , screen ) 3303 3304reset ( nil , screen ) 3305push ( 'ABC\x1b[H\x1b[P' , vt ) 3306screen_chars ( 0 , 0 , 1 , 1 , 'B' , screen ) 3307screen_chars ( 0 , 1 , 1 , 2 , 'C' , screen ) 3308screen_chars ( 0 , 0 , 1 , 80 , 'BC' , screen ) 3309 3310-- Space padding 3311reset ( nil , screen ) 3312push ( 'Hello\x1b[CWorld' , vt ) 3313screen_row ( 0 , 'Hello World' , screen ) 3314screen_text ( 0 , 0 , 1 , 80 , '48,65,6c,6c,6f,20,57,6f,72,6c,64' , screen ) 3315 3316-- Linefeed padding 3317reset ( nil , screen ) 3318push ( 'Hello\r\nWorld' , vt ) 3319screen_chars ( 0 , 0 , 2 , 80 , 'Hello\nWorld' , screen ) 3320screen_text ( 0 , 0 , 2 , 80 , '48,65,6c,6c,6f,0a,57,6f,72,6c,64' , screen ) 3321 3322-- Altscreen 3323reset ( nil , screen ) 3324push ( 'P' , vt ) 3325screen_row ( 0 , 'P' , screen ) 3326-- TODO(dundargoc): fix 3327-- push('\x1b[?1049h', vt) 3328-- screen_row(0, '', screen) 3329-- push('\x1b[2K\x1b[HA', vt) 3330-- screen_row(0, 'A', screen) 3331-- push('\x1b[?1049l', vt) 3332-- screen_row(0, 'P', screen) 3333end ) 3334 3335itp ( '61screen_unicode' , function () 3336local vt =init () 3337local screen =wantscreen ( vt ) 3338 3339-- Single width UTF-8 3340-- U+00C1 = C3 81 name: LATIN CAPITAL LETTER A WITH ACUTE 3341-- U+00E9 = C3 A9 name: LATIN SMALL LETTER E WITH ACUTE 3342reset ( nil , screen ) 3343push ( '\xC3\x81\xC3\xA9' , vt ) 3344screen_row ( 0 , 'Áé' , screen ) 3345screen_text ( 0 , 0 , 1 , 80 , 'c3,81,c3,a9' , screen ) 3346screen_cell ( 0 , 0 , '{c1} width=1 attrs={} fg=rgb(240,240,240) bg=rgb(0,0,0)' , screen ) 3347 3348-- Wide char 3349-- U+FF10 = EF BC 90 name: FULLWIDTH DIGIT ZERO 3350reset ( nil , screen ) 3351push ( '0123\x1b[H' , vt ) 3352push ( '\xEF\xBC\x90' , vt ) 3353screen_row ( 0 , '023' , screen ) 3354screen_text ( 0 , 0 , 1 , 80 , 'ef,bc,90,32,33' , screen ) 3355screen_cell ( 0 , 0 , '{ff10} width=2 attrs={} fg=rgb(240,240,240) bg=rgb(0,0,0)' , screen ) 3356 3357-- Combining char 3358-- U+0301 = CC 81 name: COMBINING ACUTE 3359reset ( nil , screen ) 3360push ( '0123\x1b[H' , vt ) 3361push ( 'e\xCC\x81' , vt ) 3362screen_row ( 0 , 'é123' , screen ) 3363screen_text ( 0 , 0 , 1 , 80 , '65,cc,81,31,32,33' , screen ) 3364screen_cell ( 0 , 0 , '{65,301} width=1 attrs={} fg=rgb(240,240,240) bg=rgb(0,0,0)' , screen ) 3365 3366-- 10 combining accents should not crash 3367reset ( nil , screen ) 3368push ( 'e\xCC\x81\xCC\x82\xCC\x83\xCC\x84\xCC\x85\xCC\x86\xCC\x87\xCC\x88\xCC\x89\xCC\x8A' , vt ) 3369screen_cell ( 33700 , 33710 , 3372'{65,301,302,303,304,305,306,307,308,309,30a} width=1 attrs={} fg=rgb(240,240,240) bg=rgb(0,0,0)' , 3373screen 3374) 3375 3376-- 40 combining accents in two split writes of 20 should not crash 3377reset ( nil , screen ) 3378push ( 3379'e\xCC\x81\xCC\x81\xCC\x81\xCC\x81\xCC\x81\xCC\x81\xCC\x81\xCC\x81\xCC\x81\xCC\x81\xCC\x81\xCC\x81\xCC\x81\xCC\x81\xCC\x81\xCC\x81\xCC\x81\xCC\x81\xCC\x81\xCC\x81' , 3380vt 3381) 3382push ( 3383'\xCC\x81\xCC\x81\xCC\x81\xCC\x81\xCC\x81\xCC\x81\xCC\x81\xCC\x81\xCC\x81\xCC\x81\xCC\x81\xCC\x81\xCC\x81\xCC\x81\xCC\x81\xCC\x81\xCC\x81\xCC\x81\xCC\x81\xCC\x81' , 3384vt 3385) 3386screen_cell ( 33870 , 33880 , 3389'{65,301,301,301,301,301,301,301,301,301,301,301,301,301,301} width=1 attrs={} fg=rgb(240,240,240) bg=rgb(0,0,0)' , 3390screen 3391) 3392 3393-- Outputting CJK doublewidth in 80th column should wraparound to next line and not crash" 3394reset ( nil , screen ) 3395push ( '\x1b[80G\xEF\xBC\x90' , vt ) 3396screen_cell ( 0 , 79 , '{} width=1 attrs={} fg=rgb(240,240,240) bg=rgb(0,0,0)' , screen ) 3397screen_cell ( 1 , 0 , '{ff10} width=2 attrs={} fg=rgb(240,240,240) bg=rgb(0,0,0)' , screen ) 3398 3399-- Outputting emoji with ZWJ and variant selectors 3400reset ( nil , screen ) 3401push ( '🏳️🌈🏳️⚧️🏴☠️' , vt ) 3402 3403-- stylua: ignore start 3404screen_cell ( 0 , 0 , '{1f3f3,fe0f,200d,1f308} width=2 attrs={} fg=rgb(240,240,240) bg=rgb(0,0,0)' , screen ) 3405screen_cell ( 0 , 2 , '{1f3f3,fe0f,200d,26a7,fe0f} width=2 attrs={} fg=rgb(240,240,240) bg=rgb(0,0,0)' , screen ) 3406screen_cell ( 0 , 4 , '{1f3f4,200d,2620,fe0f} width=2 attrs={} fg=rgb(240,240,240) bg=rgb(0,0,0)' , screen ) 3407-- stylua: ignore end 3408end ) 3409 3410pending ( '62screen_damage' , function () end ) 3411 3412itp ( '63screen_resize' , function () 3413local vt =init () 3414local state =wantstate ( vt ) 3415local screen =wantscreen ( vt ) 3416 3417-- Resize wider preserves cells 3418reset ( state , screen ) 3419resize ( 25 , 80 , vt ) 3420push ( 'AB\r\nCD' , vt ) 3421screen_chars ( 0 , 0 , 1 , 80 , 'AB' , screen ) 3422screen_chars ( 1 , 0 , 2 , 80 , 'CD' , screen ) 3423resize ( 25 , 100 , vt ) 3424screen_chars ( 0 , 0 , 1 , 100 , 'AB' , screen ) 3425screen_chars ( 1 , 0 , 2 , 100 , 'CD' , screen ) 3426 3427-- Resize wider allows print in new area 3428reset ( state , screen ) 3429resize ( 25 , 80 , vt ) 3430push ( 'AB\x1b[79GCD' , vt ) 3431screen_chars ( 0 , 0 , 1 , 2 , 'AB' , screen ) 3432screen_chars ( 0 , 78 , 1 , 80 , 'CD' , screen ) 3433resize ( 25 , 100 , vt ) 3434screen_chars ( 0 , 0 , 1 , 2 , 'AB' , screen ) 3435screen_chars ( 0 , 78 , 1 , 80 , 'CD' , screen ) 3436push ( 'E' , vt ) 3437screen_chars ( 0 , 78 , 1 , 81 , 'CDE' , screen ) 3438 3439-- Resize shorter with blanks just truncates 3440reset ( state , screen ) 3441resize ( 25 , 80 , vt ) 3442push ( 'Top\x1b[10HLine 10' , vt ) 3443screen_row ( 0 , 'Top' , screen ) 3444screen_row ( 9 , 'Line 10' , screen ) 3445cursor ( 9 , 7 , state ) 3446resize ( 20 , 80 , vt ) 3447screen_row ( 0 , 'Top' , screen ) 3448screen_row ( 9 , 'Line 10' , screen ) 3449cursor ( 9 , 7 , state ) 3450 3451-- Resize shorter with content must scroll 3452reset ( state , screen ) 3453resize ( 25 , 80 , vt ) 3454push ( 'Top\x1b[25HLine 25\x1b[15H' , vt ) 3455screen_row ( 0 , 'Top' , screen ) 3456screen_row ( 24 , 'Line 25' , screen ) 3457cursor ( 14 , 0 , state ) 3458screen =wantscreen ( vt , { b =true } ) 3459resize ( 20 , 80 , vt ) 3460expect ( 3461'sb_pushline 80 = 54 6f 70\nsb_pushline 80 =\nsb_pushline 80 =\nsb_pushline 80 =\nsb_pushline 80 =' 3462) 3463-- TODO(dundargoc): fix or remove 3464-- screen_row( 0 , "",screen) 3465screen_row ( 19 , 'Line 25' , screen ) 3466cursor ( 9 , 0 , state ) 3467 3468-- Resize shorter does not lose line with cursor 3469-- See also https://github.com/neovim/libvterm/commit/1b745d29d45623aa8d22a7b9288c7b0e331c7088 3470reset ( state , screen ) 3471wantscreen ( vt ) 3472resize ( 25 , 80 , vt ) 3473screen =wantscreen ( vt , { b =true } ) 3474push ( '\x1b[24HLine 24\r\nLine 25\r\n' , vt ) 3475expect ( 'sb_pushline 80 =' ) 3476screen_row ( 23 , 'Line 25' , screen ) 3477cursor ( 24 , 0 , state ) 3478resize ( 24 , 80 , vt ) 3479expect ( 'sb_pushline 80 =' ) 3480screen_row ( 22 , 'Line 25' , screen ) 3481cursor ( 23 , 0 , state ) 3482 3483-- Resize shorter does not send the cursor to a negative row 3484-- See also https://github.com/vim/vim/pull/6141 3485reset ( state , screen ) 3486wantscreen ( vt ) 3487resize ( 25 , 80 , vt ) 3488screen =wantscreen ( vt , { b =true } ) 3489push ( '\x1b[24HLine 24\r\nLine 25\x1b[H' , vt ) 3490cursor ( 0 , 0 , state ) 3491resize ( 20 , 80 , vt ) 3492expect ( 3493'sb_pushline 80 =\nsb_pushline 80 =\nsb_pushline 80 =\nsb_pushline 80 =\nsb_pushline 80 =' 3494) 3495cursor ( 0 , 0 , state ) 3496 3497-- Resize taller attempts to pop scrollback 3498reset ( state , screen ) 3499screen =wantscreen ( vt ) 3500resize ( 25 , 80 , vt ) 3501push ( 'Line 1\x1b[25HBottom\x1b[15H' , vt ) 3502screen_row ( 0 , 'Line 1' , screen ) 3503screen_row ( 24 , 'Bottom' , screen ) 3504cursor ( 14 , 0 , state ) 3505screen =wantscreen ( vt , { b =true } ) 3506resize ( 30 , 80 , vt ) 3507expect ( 'sb_popline 80\nsb_popline 80\nsb_popline 80\nsb_popline 80\nsb_popline 80' ) 3508screen_row ( 0 , 'ABCDE' , screen ) 3509screen_row ( 5 , 'Line 1' , screen ) 3510screen_row ( 29 , 'Bottom' , screen ) 3511cursor ( 19 , 0 , state ) 3512screen =wantscreen ( vt ) 3513 3514-- Resize can operate on altscreen 3515reset ( state , screen ) 3516screen =wantscreen ( vt , { a =true } ) 3517resize ( 25 , 80 , vt ) 3518push ( 'Main screen\x1b[?1049h\x1b[HAlt screen' , vt ) 3519resize ( 30 , 80 , vt ) 3520screen_row ( 0 , 'Alt screen' , screen ) 3521push ( '\x1b[?1049l' , vt ) 3522screen_row ( 0 , 'Main screen' , screen ) 3523end ) 3524 3525itp ( '64screen_pen' , function () 3526local vt =init () 3527local screen =wantscreen ( vt ) 3528 3529reset ( nil , screen ) 3530 3531-- Plain 3532push ( 'A' , vt ) 3533screen_cell ( 0 , 0 , '{41} width=1 attrs={} fg=rgb(240,240,240) bg=rgb(0,0,0)' , screen ) 3534 3535-- Bold 3536push ( '\x1b[1mB' , vt ) 3537screen_cell ( 0 , 1 , '{42} width=1 attrs={B} fg=rgb(240,240,240) bg=rgb(0,0,0)' , screen ) 3538 3539-- Italic 3540push ( '\x1b[3mC' , vt ) 3541screen_cell ( 0 , 2 , '{43} width=1 attrs={BI} fg=rgb(240,240,240) bg=rgb(0,0,0)' , screen ) 3542 3543-- Underline 3544push ( '\x1b[4mD' , vt ) 3545screen_cell ( 0 , 3 , '{44} width=1 attrs={BU1I} fg=rgb(240,240,240) bg=rgb(0,0,0)' , screen ) 3546 3547-- Reset 3548push ( '\x1b[mE' , vt ) 3549screen_cell ( 0 , 4 , '{45} width=1 attrs={} fg=rgb(240,240,240) bg=rgb(0,0,0)' , screen ) 3550 3551-- Font 3552push ( '\x1b[11mF\x1b[m' , vt ) 3553screen_cell ( 0 , 5 , '{46} width=1 attrs={F1} fg=rgb(240,240,240) bg=rgb(0,0,0)' , screen ) 3554 3555-- Foreground 3556push ( '\x1b[31mG\x1b[m' , vt ) 3557screen_cell ( 0 , 6 , '{47} width=1 attrs={} fg=rgb(224,0,0) bg=rgb(0,0,0)' , screen ) 3558 3559-- Background 3560push ( '\x1b[42mH\x1b[m' , vt ) 3561screen_cell ( 0 , 7 , '{48} width=1 attrs={} fg=rgb(240,240,240) bg=rgb(0,224,0)' , screen ) 3562 3563-- Super/subscript 3564push ( 'x\x1b[74m0\x1b[73m2\x1b[m' , vt ) 3565screen_cell ( 0 , 8 , '{78} width=1 attrs={} fg=rgb(240,240,240) bg=rgb(0,0,0)' , screen ) 3566screen_cell ( 0 , 9 , '{30} width=1 attrs={S_} fg=rgb(240,240,240) bg=rgb(0,0,0)' , screen ) 3567screen_cell ( 0 , 10 , '{32} width=1 attrs={S^} fg=rgb(240,240,240) bg=rgb(0,0,0)' , screen ) 3568 3569-- Dim 3570push ( '\x1b[2mI\x1b[m' , vt ) 3571screen_cell ( 0 , 11 , '{49} width=1 attrs={D} fg=rgb(240,240,240) bg=rgb(0,0,0)' , screen ) 3572 3573-- Overline 3574push ( '\x1b[53mJ\x1b[m' , vt ) 3575screen_cell ( 0 , 12 , '{4a} width=1 attrs={O} fg=rgb(240,240,240) bg=rgb(0,0,0)' , screen ) 3576 3577-- EL sets only colours to end of line, not other attrs 3578push ( '\x1b[H\x1b[7;33;44m\x1b[K' , vt ) 3579screen_cell ( 0 , 0 , '{} width=1 attrs={} fg=rgb(224,224,0) bg=rgb(0,0,224)' , screen ) 3580screen_cell ( 0 , 79 , '{} width=1 attrs={} fg=rgb(224,224,0) bg=rgb(0,0,224)' , screen ) 3581 3582-- DECSCNM xors reverse for entire screen 3583push ( 'R\x1b[?5h' , vt ) 3584screen_cell ( 0 , 0 , '{52} width=1 attrs={} fg=rgb(224,224,0) bg=rgb(0,0,224)' , screen ) 3585screen_cell ( 1 , 0 , '{} width=1 attrs={R} fg=rgb(240,240,240) bg=rgb(0,0,0)' , screen ) 3586push ( '\x1b[?5$p' , vt ) 3587expect_output ( '\x1b[?5;1$y' ) 3588push ( '\x1b[?5l' , vt ) 3589screen_cell ( 0 , 0 , '{52} width=1 attrs={R} fg=rgb(224,224,0) bg=rgb(0,0,224)' , screen ) 3590screen_cell ( 1 , 0 , '{} width=1 attrs={} fg=rgb(240,240,240) bg=rgb(0,0,0)' , screen ) 3591-- TODO(dundargoc): fix 3592-- push('\x1b[?5$p') 3593-- expect_output('\x1b[?5;2$y') 3594 3595-- Set default colours 3596reset ( nil , screen ) 3597push ( 'ABC\x1b[31mDEF\x1b[m' , vt ) 3598screen_cell ( 0 , 0 , '{41} width=1 attrs={} fg=rgb(240,240,240) bg=rgb(0,0,0)' , screen ) 3599screen_cell ( 0 , 3 , '{44} width=1 attrs={} fg=rgb(224,0,0) bg=rgb(0,0,0)' , screen ) 3600-- TODO(dundargoc): fix 3601-- SETDEFAULTCOL rgb(252,253,254) 3602-- ?screen_cell 0,0 = {41} width=1 attrs={} fg=rgb(252,253,254) bg=rgb(0,0,0) 3603-- ?screen_cell 0,3 = {44} width=1 attrs={} fg=rgb(224,0,0) bg=rgb(0,0,0) 3604-- SETDEFAULTCOL rgb(250,250,250) rgb(10,20,30) 3605-- ?screen_cell 0,0 = {41} width=1 attrs={} fg=rgb(250,250,250) bg=rgb(10,20,30) 3606-- ?screen_cell 0,3 = {44} width=1 attrs={} fg=rgb(224,0,0) bg=rgb(10,20,30) 3607end ) 3608 3609itp ( '65screen_protect' , function () 3610local vt =init () 3611local screen =wantscreen ( vt ) 3612 3613-- Selective erase 3614reset ( nil , screen ) 3615push ( 'A\x1b[1"qB\x1b["qC' , vt ) 3616screen_row ( 0 , 'ABC' , screen ) 3617push ( '\x1b[G\x1b[?J' , vt ) 3618screen_row ( 0 , ' B' , screen ) 3619 3620-- Non-selective erase 3621reset ( nil , screen ) 3622push ( 'A\x1b[1"qB\x1b["qC' , vt ) 3623screen_row ( 0 , 'ABC' , screen ) 3624-- TODO(dundargoc): fix 3625-- push('\x1b[G\x1b[J', vt) 3626-- screen_row(0, '', screen) 3627end ) 3628 3629itp ( '66screen_extent' , function () 3630local vt =init () 3631local screen =wantscreen ( vt ) 3632 3633-- Bold extent 3634reset ( nil , screen ) 3635push ( 'AB\x1b[1mCD\x1b[mE' , vt ) 3636screen_attrs_extent ( 0 , 0 , '0,0-1,1' , screen ) 3637screen_attrs_extent ( 0 , 1 , '0,0-1,1' , screen ) 3638screen_attrs_extent ( 0 , 2 , '0,2-1,3' , screen ) 3639screen_attrs_extent ( 0 , 3 , '0,2-1,3' , screen ) 3640screen_attrs_extent ( 0 , 4 , '0,4-1,79' , screen ) 3641end ) 3642 3643itp ( '67screen_dbl_wh' , function () 3644local vt =init () 3645local screen =wantscreen ( vt ) 3646 3647reset ( nil , screen ) 3648 3649-- Single Width, Single Height 3650reset ( nil , screen ) 3651push ( '\x1b#5' , vt ) 3652push ( 'abcde' , vt ) 3653screen_cell ( 0 , 0 , '{61} width=1 attrs={} fg=rgb(240,240,240) bg=rgb(0,0,0)' , screen ) 3654 3655-- Double Width, Single Height 3656reset ( nil , screen ) 3657push ( '\x1b#6' , vt ) 3658push ( 'abcde' , vt ) 3659screen_cell ( 0 , 0 , '{61} width=1 attrs={} dwl fg=rgb(240,240,240) bg=rgb(0,0,0)' , screen ) 3660 3661-- Double Height 3662reset ( nil , screen ) 3663push ( '\x1b#3' , vt ) 3664push ( 'abcde' , vt ) 3665push ( '\r\n\x1b#4' , vt ) 3666push ( 'abcde' , vt ) 3667screen_cell ( 0 , 0 , '{61} width=1 attrs={} dwl dhl-top fg=rgb(240,240,240) bg=rgb(0,0,0)' , screen ) 3668screen_cell ( 36691 , 36700 , 3671'{61} width=1 attrs={} dwl dhl-bottom fg=rgb(240,240,240) bg=rgb(0,0,0)' , 3672screen 3673) 3674 3675-- Late change 3676reset ( nil , screen ) 3677push ( 'abcde' , vt ) 3678screen_cell ( 0 , 0 , '{61} width=1 attrs={} fg=rgb(240,240,240) bg=rgb(0,0,0)' , screen ) 3679push ( '\x1b#6' , vt ) 3680screen_cell ( 0 , 0 , '{61} width=1 attrs={} dwl fg=rgb(240,240,240) bg=rgb(0,0,0)' , screen ) 3681 3682-- DWL doesn't spill over on scroll 3683reset ( nil , screen ) 3684push ( '\x1b[25H\x1b#6Final\r\n' , vt ) 3685screen_cell ( 23 , 0 , '{46} width=1 attrs={} dwl fg=rgb(240,240,240) bg=rgb(0,0,0)' , screen ) 3686screen_cell ( 24 , 0 , '{} width=1 attrs={} fg=rgb(240,240,240) bg=rgb(0,0,0)' , screen ) 3687end ) 3688 3689itp ( '68screen_termprops' , function () 3690local vt =init () 3691local screen =wantscreen ( vt , { p =true } ) 3692 3693reset ( nil , screen ) 3694expect ( 'settermprop 1 true\nsettermprop 2 true\nsettermprop 7 1' ) 3695 3696-- Cursor visibility 3697push ( '\x1b[?25h' , vt ) 3698expect ( 'settermprop 1 true' ) 3699push ( '\x1b[?25l' , vt ) 3700expect ( 'settermprop 1 false' ) 3701 3702-- Title 3703push ( '\x1b]2;Here is my title\a' , vt ) 3704expect ( 'settermprop 4 ["Here is my title"]' ) 3705end ) 3706 3707itp ( '69screen_pushline' , function () 3708local vt =init () 3709-- Run these tests on a much smaller default screen, so debug output is nowhere near as noisy 3710resize ( 5 , 10 , vt ) 3711local state =wantstate ( vt ) 3712local screen =wantscreen ( vt , { r =true } ) 3713reset ( state , screen ) 3714 3715-- Resize wider reflows wide lines 3716reset ( state , screen ) 3717push ( string . rep ( 'A' , 12 ), vt ) 3718screen_row ( 0 , 'AAAAAAAAAA' , screen , vt . cols ) 3719screen_row ( 1 , 'AA' , screen , vt . cols ) 3720lineinfo ( 1 , { cont =true } , state ) 3721cursor ( 1 , 2 , state ) 3722resize ( 5 , 15 , vt ) 3723screen_row ( 0 , 'AAAAAAAAAAAA' , screen , vt . cols ) 3724-- TODO(dundargoc): fix 3725-- screen_row(1, '', screen, vt.cols) 3726lineinfo ( 1 , {} , state ) 3727cursor ( 0 , 12 , state ) 3728resize ( 5 , 20 , vt ) 3729screen_row ( 0 , 'AAAAAAAAAAAA' , screen , vt . cols ) 3730-- TODO(dundargoc): fix 3731-- screen_row( 1 ,'',screen, vt.cols) 3732lineinfo ( 1 , {} , state ) 3733cursor ( 0 , 12 , state ) 3734 3735-- Resize narrower can create continuation lines 3736reset ( state , screen ) 3737resize ( 5 , 10 , vt ) 3738push ( 'ABCDEFGHI' , vt ) 3739screen_row ( 0 , 'ABCDEFGHI' , screen , vt . cols ) 3740-- TODO(dundargoc): fix 3741-- screen_row( 1 , "",screen, vt.cols) 3742lineinfo ( 1 , {} , state ) 3743cursor ( 0 , 9 , state ) 3744resize ( 5 , 8 , vt ) 3745-- TODO(dundargoc): fix 3746-- screen_row( 0 , "ABCDEFGH",screen,vt.cols) 3747screen_row ( 1 , 'I' , screen , vt . cols ) 3748lineinfo ( 1 , { cont =true } , state ) 3749cursor ( 1 , 1 , state ) 3750resize ( 5 , 6 , vt ) 3751screen_row ( 0 , 'ABCDEF' , screen , vt . cols ) 3752screen_row ( 1 , 'GHI' , screen , vt . cols ) 3753lineinfo ( 1 , { cont =true } , state ) 3754cursor ( 1 , 3 , state ) 3755 3756-- Shell wrapped prompt behaviour 3757reset ( state , screen ) 3758resize ( 5 , 10 , vt ) 3759push ( 'PROMPT GOES HERE\r\n> \r\n\r\nPROMPT GOES HERE\r\n> ' , vt ) 3760screen_row ( 0 , '> ' , screen , vt . cols ) 3761-- TODO(dundargoc): fix 3762-- screen_row( 1 , "",screen,vt.cols) 3763screen_row ( 2 , 'PROMPT GOE' , screen , vt . cols ) 3764screen_row ( 3 , 'S HERE' , screen , vt . cols ) 3765lineinfo ( 3 , { cont =true } , state ) 3766screen_row ( 4 , '> ' , screen , vt . cols ) 3767cursor ( 4 , 2 , state ) 3768resize ( 5 , 11 , vt ) 3769screen_row ( 0 , '> ' , screen , vt . cols ) 3770-- TODO(dundargoc): fix 3771-- screen_row( 1 , "",screen,vt.cols) 3772screen_row ( 2 , 'PROMPT GOES' , screen , vt . cols ) 3773screen_row ( 3 , ' HERE' , screen , vt . cols ) 3774lineinfo ( 3 , { cont =true } , state ) 3775screen_row ( 4 , '> ' , screen , vt . cols ) 3776cursor ( 4 , 2 , state ) 3777resize ( 5 , 12 , vt ) 3778screen_row ( 0 , '> ' , screen , vt . cols ) 3779-- TODO(dundargoc): fix 3780-- screen_row( 1 , "",screen,vt.cols) 3781screen_row ( 2 , 'PROMPT GOES ' , screen , vt . cols ) 3782screen_row ( 3 , 'HERE' , screen , vt . cols ) 3783lineinfo ( 3 , { cont =true } , state ) 3784screen_row ( 4 , '> ' , screen , vt . cols ) 3785cursor ( 4 , 2 , state ) 3786resize ( 5 , 16 , vt ) 3787screen_row ( 0 , '> ' , screen , vt . cols ) 3788-- TODO(dundargoc): fix 3789-- screen_row( 1 , "",screen,vt.cols) 3790-- screen_row( 2 , "PROMPT GOES HERE",screen,vt.cols) 3791lineinfo ( 3 , {} , state ) 3792screen_row ( 3 , '> ' , screen , vt . cols ) 3793cursor ( 3 , 2 , state ) 3794 3795-- Cursor goes missing 3796-- For more context: https://github.com/neovim/neovim/pull/21124 3797reset ( state , screen ) 3798resize ( 5 , 5 , vt ) 3799resize ( 3 , 1 , vt ) 3800push ( '\x1b[2;1Habc\r\n\x1b[H' , vt ) 3801resize ( 1 , 1 , vt ) 3802cursor ( 0 , 0 , state ) 3803 3804reset ( state , screen ) 3805resize ( 4 , 4 , vt ) 3806push ( 'ABCD\r\nX' , vt ) 3807screen_row ( 0 , 'ABCD' , screen , vt . cols ) 3808screen_row ( 1 , 'X' , screen , vt . cols ) 3809cursor ( 1 , 1 , state ) 3810resize ( 4 , 5 , vt ) 3811screen_row ( 0 , 'ABCD' , screen , vt . cols ) 3812screen_row ( 1 , 'X' , screen , vt . cols ) 3813cursor ( 1 , 1 , state ) 3814 3815reset ( state , screen ) 3816resize ( 4 , 4 , vt ) 3817push ( 'ABCD\r\nX' , vt ) 3818cursor ( 1 , 1 , state ) 3819resize ( 3 , 4 , vt ) 3820screen_row ( 0 , 'ABCD' , screen , vt . cols ) 3821screen_row ( 1 , 'X' , screen , vt . cols ) 3822cursor ( 1 , 1 , state ) 3823 3824resize ( 5 , 10 , vt ) 3825end ) 3826 3827pending ( '90vttest_01-movement-1' , function () end ) 3828pending ( '90vttest_01-movement-2' , function () end ) 3829 3830itp ( '90vttest_01-movement-3' , function () 3831-- Test of cursor-control characters inside ESC sequences 3832local vt =init () 3833local state =wantstate ( vt ) 3834local screen =wantscreen ( vt ) 3835 3836reset ( state , screen ) 3837 3838push ( 'A B C D E F G H I' , vt ) 3839push ( '\x0d\x0a' , vt ) 3840push ( 'A\x1b[2\bCB\x1b[2\bCC\x1b[2\bCD\x1b[2\bCE\x1b[2\bCF\x1b[2\bCG\x1b[2\bCH\x1b[2\bCI' , vt ) 3841push ( '\x0d\x0a' , vt ) 3842push ( 3843'A \x1b[\x0d2CB\x1b[\x0d4CC\x1b[\x0d6CD\x1b[\x0d8CE\x1b[\x0d10CF\x1b[\x0d12CG\x1b[\x0d14CH\x1b[\x0d16CI' , 3844vt 3845) 3846push ( '\x0d\x0a' , vt ) 3847push ( 3848'A \x1b[1\x0bAB \x1b[1\x0bAC \x1b[1\x0bAD \x1b[1\x0bAE \x1b[1\x0bAF \x1b[1\x0bAG \x1b[1\x0bAH \x1b[1\x0bAI \x1b[1\x0bA' , 3849vt 3850) 3851 3852-- Output 3853 3854for i =0 , 2 do 3855screen_row ( i , 'A B C D E F G H I' , screen ) 3856end 3857screen_row ( 3 , 'A B C D E F G H I ' , screen ) 3858 3859cursor ( 3 , 18 , state ) 3860end ) 3861 3862itp ( '90vttest_01-movement-4' , function () 3863-- Test of leading zeroes in ESC sequences 3864local vt =init () 3865local screen =wantscreen ( vt ) 3866 3867reset ( nil , screen ) 3868 3869push ( '\x1b[00000000004;000000001HT' , vt ) 3870push ( '\x1b[00000000004;000000002Hh' , vt ) 3871push ( '\x1b[00000000004;000000003Hi' , vt ) 3872push ( '\x1b[00000000004;000000004Hs' , vt ) 3873push ( '\x1b[00000000004;000000005H ' , vt ) 3874push ( '\x1b[00000000004;000000006Hi' , vt ) 3875push ( '\x1b[00000000004;000000007Hs' , vt ) 3876push ( '\x1b[00000000004;000000008H ' , vt ) 3877push ( '\x1b[00000000004;000000009Ha' , vt ) 3878push ( '\x1b[00000000004;0000000010H ' , vt ) 3879push ( '\x1b[00000000004;0000000011Hc' , vt ) 3880push ( '\x1b[00000000004;0000000012Ho' , vt ) 3881push ( '\x1b[00000000004;0000000013Hr' , vt ) 3882push ( '\x1b[00000000004;0000000014Hr' , vt ) 3883push ( '\x1b[00000000004;0000000015He' , vt ) 3884push ( '\x1b[00000000004;0000000016Hc' , vt ) 3885push ( '\x1b[00000000004;0000000017Ht' , vt ) 3886push ( '\x1b[00000000004;0000000018H ' , vt ) 3887push ( '\x1b[00000000004;0000000019Hs' , vt ) 3888push ( '\x1b[00000000004;0000000020He' , vt ) 3889push ( '\x1b[00000000004;0000000021Hn' , vt ) 3890push ( '\x1b[00000000004;0000000022Ht' , vt ) 3891push ( '\x1b[00000000004;0000000023He' , vt ) 3892push ( '\x1b[00000000004;0000000024Hn' , vt ) 3893push ( '\x1b[00000000004;0000000025Hc' , vt ) 3894push ( '\x1b[00000000004;0000000026He' , vt ) 3895 3896-- Output 3897 3898screen_row ( 3 , 'This is a correct sentence' , screen ) 3899end ) 3900 3901pending ( '90vttest_02-screen-1' , function () end ) 3902pending ( '90vttest_02-screen-2' , function () end ) 3903 3904itp ( '90vttest_02-screen-3' , function () 3905-- Origin mode 3906local vt =init () 3907local screen =wantscreen ( vt ) 3908 3909reset ( nil , screen ) 3910 3911push ( '\x1b[?6h' , vt ) 3912push ( '\x1b[23;24r' , vt ) 3913push ( '\n' , vt ) 3914push ( 'Bottom' , vt ) 3915push ( '\x1b[1;1H' , vt ) 3916push ( 'Above' , vt ) 3917 3918-- Output 3919screen_row ( 22 , 'Above' , screen ) 3920screen_row ( 23 , 'Bottom' , screen ) 3921end ) 3922 3923itp ( '90vttest_02-screen-4' , function () 3924-- Origin mode (2) 3925local vt =init () 3926local screen =wantscreen ( vt ) 3927 3928reset ( nil , screen ) 3929 3930push ( '\x1b[?6l' , vt ) 3931push ( '\x1b[23;24r' , vt ) 3932push ( '\x1b[24;1H' , vt ) 3933push ( 'Bottom' , vt ) 3934push ( '\x1b[1;1H' , vt ) 3935push ( 'Top' , vt ) 3936 3937-- Output 3938screen_row ( 23 , 'Bottom' , screen ) 3939screen_row ( 0 , 'Top' , screen ) 3940end ) 3941 3942itp ( 'Mouse reporting should not break by idempotent DECSM 1002' , function () 3943-- Regression test for https://bugs.launchpad.net/libvterm/+bug/1640917 3944-- Related: https://github.com/neovim/neovim/issues/5583 3945local vt =init () 3946wantstate ( vt , {} ) 3947 3948push ( '\x1b[?1002h' , vt ) 3949mousemove ( 0 , 0 , vt ) 3950mousebtn ( 'd' , 1 , vt ) 3951expect_output ( '\x1b[M\x20\x21\x21' ) 3952mousemove ( 1 , 0 , vt ) 3953expect_output ( '\x1b[M\x40\x21\x22' ) 3954push ( '\x1b[?1002h' , vt ) 3955mousemove ( 2 , 0 , vt ) 3956expect_output ( '\x1b[M\x40\x21\x23' ) 3957end ) 3958end )