@@ -1,4 +1,6 @@ |
| 1 | module server_installer_module | 1 | module server_installer_module |
| | 2 | + use raw_mode_module, only: disable_raw_mode, enable_raw_mode |
| | 3 | + use terminal_io_module, only: terminal_clear_screen, terminal_show_cursor |
| 2 | implicit none | 4 | implicit none |
| 3 | private | 5 | private |
| 4 | | 6 | |
@@ -16,7 +18,8 @@ contains |
| 16 | function run_install_command(command) result(result) | 18 | function run_install_command(command) result(result) |
| 17 | character(len=*), intent(in) :: command | 19 | character(len=*), intent(in) :: command |
| 18 | type(install_result_t) :: result | 20 | type(install_result_t) :: result |
| 19 | - integer :: exit_status | 21 | + integer :: exit_status, cmd_status |
| | 22 | + logical :: raw_disabled |
| 20 | | 23 | |
| 21 | result%success = .false. | 24 | result%success = .false. |
| 22 | result%exit_code = -1 | 25 | result%exit_code = -1 |
@@ -27,9 +30,27 @@ contains |
| 27 | return | 30 | return |
| 28 | end if | 31 | end if |
| 29 | | 32 | |
| 30 | - ! Execute the command | 33 | + ! Must exit raw mode before running external commands |
| 31 | - ! Note: This runs synchronously and blocks until complete | 34 | + ! Otherwise child process inherits broken terminal state |
| 32 | - call execute_command_line(trim(command), wait=.true., exitstat=exit_status) | 35 | + raw_disabled = disable_raw_mode() |
| | 36 | + |
| | 37 | + ! Show cursor and clear screen for command output |
| | 38 | + call terminal_show_cursor() |
| | 39 | + call terminal_clear_screen() |
| | 40 | + |
| | 41 | + ! Execute the command with cmdstat to catch errors gracefully |
| | 42 | + ! Without cmdstat, invalid commands cause Fortran runtime errors |
| | 43 | + call execute_command_line(trim(command), wait=.true., exitstat=exit_status, cmdstat=cmd_status) |
| | 44 | + |
| | 45 | + ! Re-enable raw mode for editor |
| | 46 | + raw_disabled = enable_raw_mode() |
| | 47 | + |
| | 48 | + ! Check for command execution errors (cmdstat /= 0 means execute failed) |
| | 49 | + if (cmd_status /= 0) then |
| | 50 | + result%exit_code = cmd_status |
| | 51 | + result%message = 'Failed to execute command (cmdstat=' // trim(itoa(cmd_status)) // ')' |
| | 52 | + return |
| | 53 | + end if |
| 33 | | 54 | |
| 34 | result%exit_code = exit_status | 55 | result%exit_code = exit_status |
| 35 | result%success = (exit_status == 0) | 56 | result%success = (exit_status == 0) |
@@ -41,4 +62,11 @@ contains |
| 41 | end if | 62 | end if |
| 42 | end function run_install_command | 63 | end function run_install_command |
| 43 | | 64 | |
| | 65 | + ! Simple integer to string helper |
| | 66 | + function itoa(i) result(str) |
| | 67 | + integer, intent(in) :: i |
| | 68 | + character(len=20) :: str |
| | 69 | + write(str, '(I0)') i |
| | 70 | + end function itoa |
| | 71 | + |
| 44 | end module server_installer_module | 72 | end module server_installer_module |