@@ -457,21 +457,72 @@ Available `[options]`:
457457#### Open floating terminal
458458
459459``` lua
460- require (" nvim_updater.utils" ).open_floating_terminal ( [options ] )
460+ require (" nvim_updater.utils" ).open_floating_terminal ( [TerminalOptions ] )
461461```
462462
463463This is a helper function for opening a floating terminal that is used by the
464464updater to display the terminal output.
465465
466- Available ` [options ] ` :
466+ Available ` [TerminalOptions ] ` :
467467
468468- ** ` cmd ` ** : Command to run in the terminal.
469469- ** ` filetype ` ** : Filetype to assign to the terminal buffer.
470470 Default is ` "nvim_updater_term" ` .
471- - ** ` ispreupdate ` ** : Whether the terminal will be followed by an update build.
471+ - ** ` ispreupdate ` ** : (Deprecated)
472+ Whether the terminal will be followed by an update build.
472473 Default is ` false ` .
473474- ** ` autoclose ` ** : Whether the terminal buffer will be closed when the process ends.
474475 Default is ` false ` .
476+ - ** ` callback ` ** : A function to call when the terminal buffer is closed.
477+ Default is ` nil ` .
478+
479+ > [ !NOTE]
480+ > The ` ispreupdate ` option is now deprecated and will be removed in a future version.
481+
482+ ##### Callback Function
483+
484+ The callback function allows you to define a function to be triggered when the
485+ terminal buffer is closed.
486+
487+ The callback function is called with the following arguments:
488+
489+ - ` ev ` : The [ event object] ( https://neovim.io/doc/user/api.html#event-args )
490+ received from the terminal close event.
491+ - ` exit_code ` : The exit code of the process that was run in the terminal buffer.
492+
493+ In most cases, this will occur after the process has completed.
494+
495+ However, if the window is closed before the process is complete, the exit code
496+ returned will be ` -1 ` . This allows us to identify those scenarios and handle them
497+ appropriately.
498+
499+ Here is an example of how to use the callback function:
500+
501+ ``` lua
502+ require (" nvim_updater.utils" ).open_floating_terminal ({
503+ command = " my_test_script.sh" , -- Command to run
504+ filetype = " my_test_script_term" , -- Filetype to assign
505+ autoclose = true , -- Close the terminal buffer automatically
506+ callback = function (result ) -- Callback function
507+ if result .result_code == - 1 then
508+ vim .notify (
509+ " Terminal closed before process completed" ,
510+ vim .log .levels .ERROR
511+ )
512+ elseif result .result_code == 0 then
513+ vim .notify (
514+ " Terminal process completed successfully" ,
515+ vim .log .levels .INFO
516+ )
517+ else
518+ vim .notify (
519+ " Terminal process failed with exit code: " .. result .result_code ,
520+ vim .log .levels .ERROR
521+ )
522+ end
523+ end ,
524+ })
525+ ```
475526
476527#### Setup
477528
0 commit comments