@@ -657,16 +657,19 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
657657 }
658658 let mut dest: Option < PathBuf > = None ;
659659 if let Ok ( item) = state. get_item ( ) {
660+ let mut err: Option < FxError > = None ;
660661 match item. file_type {
661662 FileType :: File => {
662663 execute ! ( screen, EnterAlternateScreen ) ?;
663664 if let Err ( e) = state. open_file ( item) {
664- print_warning ( e, state. layout . y ) ;
665- continue ;
665+ err = Some ( e) ;
666666 }
667667 execute ! ( screen, EnterAlternateScreen ) ?;
668668 hide_cursor ( ) ;
669669 state. reload ( state. layout . y ) ?;
670+ if let Some ( e) = err {
671+ print_warning ( e, state. layout . y ) ;
672+ }
670673 continue ;
671674 }
672675 FileType :: Symlink => match & item. symlink_dir_path {
@@ -681,12 +684,14 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
681684 None => {
682685 execute ! ( screen, EnterAlternateScreen ) ?;
683686 if let Err ( e) = state. open_file ( item) {
684- print_warning ( e, state. layout . y ) ;
685- continue ;
687+ err = Some ( e) ;
686688 }
687689 execute ! ( screen, EnterAlternateScreen ) ?;
688690 hide_cursor ( ) ;
689- state. redraw ( state. layout . y ) ;
691+ state. reload ( state. layout . y ) ?;
692+ if let Some ( e) = err {
693+ print_warning ( e, state. layout . y ) ;
694+ }
690695 continue ;
691696 }
692697 } ,
@@ -1357,8 +1362,37 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
13571362
13581363 //rename
13591364 KeyCode :: Char ( 'c' ) => {
1360- //In visual mode, this is disabled .
1365+ //In visual mode, you can rename multiple items in default editor .
13611366 if state. v_start . is_some ( ) {
1367+ let items: Vec < ItemBuffer > = state
1368+ . list
1369+ . iter ( )
1370+ . filter ( |item| item. selected )
1371+ . map ( ItemBuffer :: new)
1372+ . collect ( ) ;
1373+ execute ! ( screen, EnterAlternateScreen ) ?;
1374+ let result = state. rename_multiple_items ( & items) ;
1375+ execute ! ( screen, EnterAlternateScreen ) ?;
1376+ hide_cursor ( ) ;
1377+ state. reset_selection ( ) ;
1378+ state. reload ( state. layout . y ) ?;
1379+ match result {
1380+ Err ( e) => {
1381+ print_warning ( e, state. layout . y ) ;
1382+ }
1383+ Ok ( result_len) => {
1384+ let message = {
1385+ match result_len {
1386+ 0 => "No item renamed." . to_owned ( ) ,
1387+ 1 => "1 item renamed." . to_owned ( ) ,
1388+ count => {
1389+ format ! ( "{} items renamed." , count)
1390+ }
1391+ }
1392+ } ;
1393+ print_info ( message, state. layout . y ) ;
1394+ }
1395+ }
13621396 continue ;
13631397 }
13641398 if len == 0 {
@@ -1506,12 +1540,10 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
15061540 }
15071541
15081542 state. operations . branch ( ) ;
1509- state. operations . push ( OpKind :: Rename (
1510- RenamedFile {
1511- original_name : item. file_path . clone ( ) ,
1512- new_name : to,
1513- } ,
1514- ) ) ;
1543+ state. operations . push ( OpKind :: Rename ( vec ! [ (
1544+ item. file_path. clone( ) ,
1545+ to,
1546+ ) ] ) ) ;
15151547
15161548 hide_cursor ( ) ;
15171549 state. reload ( state. layout . y ) ?;
@@ -2389,50 +2421,37 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
23892421 }
23902422
23912423 //Execute command as is
2424+ let mut err: Option < & str > = None ;
23922425 execute ! ( screen, EnterAlternateScreen ) ?;
23932426 if std:: env:: set_current_dir ( & state. current_dir )
23942427 . is_err ( )
23952428 {
2396- execute ! ( screen, EnterAlternateScreen ) ?;
2397- print_warning (
2398- "Cannot execute command" ,
2399- state. layout . y ,
2400- ) ;
2401- break ' command;
2402- }
2403- if let Ok ( sh) = std:: env:: var ( "SHELL" ) {
2429+ err =
2430+ Some ( "Changing current directory failed." ) ;
2431+ } else if let Ok ( sh) = std:: env:: var ( "SHELL" ) {
24042432 if std:: process:: Command :: new ( & sh)
24052433 . arg ( "-c" )
2406- . arg ( & commands. join ( " " ) )
2434+ . arg ( commands. join ( " " ) )
24072435 . status ( )
24082436 . is_err ( )
24092437 {
2410- execute ! ( screen, EnterAlternateScreen ) ?;
2411- state. redraw ( state. layout . y ) ;
2412- print_warning (
2413- "Cannot execute command" ,
2414- state. layout . y ,
2415- ) ;
2416- break ' command;
2438+ err = Some ( "Command execution failed." ) ;
24172439 }
24182440 } else if std:: process:: Command :: new ( command)
24192441 . args ( & commands[ 1 ..] )
24202442 . status ( )
24212443 . is_err ( )
24222444 {
2423- execute ! ( screen, EnterAlternateScreen ) ?;
2424- state. redraw ( state. layout . y ) ;
2425- print_warning (
2426- "Cannot execute command" ,
2427- state. layout . y ,
2428- ) ;
2429- break ' command;
2445+ err = Some ( "Command execution failed." ) ;
24302446 }
24312447
24322448 execute ! ( screen, EnterAlternateScreen ) ?;
24332449 hide_cursor ( ) ;
24342450 info ! ( "SHELL: {:?}" , commands) ;
24352451 state. reload ( state. layout . y ) ?;
2452+ if let Some ( e) = err {
2453+ print_warning ( e, state. layout . y ) ;
2454+ }
24362455 break ' command;
24372456 }
24382457
0 commit comments