@@ -272,3 +272,57 @@ fn test_pty_vi_utf8_display() {
272272 let contents = std:: fs:: read_to_string ( & file_path) . unwrap ( ) ;
273273 assert_eq ! ( contents, "Привет мир\n " ) ;
274274}
275+
276+ /// Test: `:set number` displays line numbers without panic.
277+ /// Regression test for issue #530.
278+ #[ test]
279+ fn test_pty_vi_set_number ( ) {
280+ let td = tempdir ( ) . unwrap ( ) ;
281+ let file_path = td. path ( ) . join ( "test_number.txt" ) ;
282+ std:: fs:: write ( & file_path, "line1\n line2\n line3\n " ) . unwrap ( ) ;
283+
284+ let pty_system = native_pty_system ( ) ;
285+ let pair = pty_system
286+ . openpty ( PtySize {
287+ rows : 25 ,
288+ cols : 80 ,
289+ pixel_width : 0 ,
290+ pixel_height : 0 ,
291+ } )
292+ . unwrap ( ) ;
293+
294+ let mut cmd = CommandBuilder :: new ( env ! ( "CARGO_BIN_EXE_vi" ) ) ;
295+ cmd. arg ( & file_path) ;
296+ cmd. env ( "TERM" , "vt100" ) ;
297+
298+ let mut child = pair. slave . spawn_command ( cmd) . unwrap ( ) ;
299+ drop ( pair. slave ) ;
300+
301+ let reader = pair. master . try_clone_reader ( ) . unwrap ( ) ;
302+ let _reader_thread = spawn_reader_drain ( reader) ;
303+ let mut writer = pair. master . take_writer ( ) . unwrap ( ) ;
304+
305+ // Wait for vi startup
306+ thread:: sleep ( Duration :: from_millis ( 500 ) ) ;
307+
308+ // Enable line numbers
309+ write_keys ( & mut writer, ":set number\r " ) ;
310+ thread:: sleep ( Duration :: from_millis ( 200 ) ) ;
311+
312+ // Move cursor to verify positioning works with line numbers
313+ write_keys ( & mut writer, "jjk" ) ;
314+ thread:: sleep ( Duration :: from_millis ( 100 ) ) ;
315+
316+ // Disable line numbers
317+ write_keys ( & mut writer, ":set nonumber\r " ) ;
318+ thread:: sleep ( Duration :: from_millis ( 100 ) ) ;
319+
320+ // Quit without saving
321+ write_keys ( & mut writer, ":q!\r " ) ;
322+
323+ wait_with_timeout ( & mut child, Duration :: from_secs ( 5 ) ) ;
324+
325+ // File should be unchanged
326+ let contents = std:: fs:: read_to_string ( & file_path) . unwrap ( ) ;
327+ assert_eq ! ( contents, "line1\n line2\n line3\n " ) ;
328+ }
0 commit comments