@ -86,11 +86,38 @@ fn call(app: &app::App, cmd: app::Command, silent: bool) -> io::Result<ExitStatu
. status ( )
}
pub ( crate ) fn run (
mut app : app ::App ,
pub struct Runner {
pwd : PathBuf ,
focused_path : Option < PathBuf > ,
lua : & mlua ::Lua ,
) -> Result < Option < String > > {
on_load : Vec < app ::ExternalMsg > ,
}
impl Runner {
pub ( crate ) fn new ( path : Option < PathBuf > ) -> Result < Self > {
let mut pwd = path . unwrap_or_else ( | | "." . into ( ) ) . canonicalize ( ) ? ;
let mut focused_path = None ;
if pwd . is_file ( ) {
focused_path = pwd . file_name ( ) . map ( | p | p . into ( ) ) ;
pwd = pwd . parent ( ) . map ( | p | p . into ( ) ) . unwrap_or_else ( | | "." . into ( ) ) ;
}
Ok ( Self {
pwd ,
focused_path ,
on_load : Default ::default ( ) ,
} )
}
pub fn with_on_load ( mut self , on_load : Vec < app ::ExternalMsg > ) -> Self {
self . on_load = on_load ;
self
}
pub fn run ( self ) -> Result < Option < String > > {
let lua = mlua ::Lua ::new ( ) ;
let mut app = app ::App ::create ( self . pwd , & lua ) ? ;
fs ::create_dir_all ( app . session_path ( ) ) ? ;
let ( tx_msg_in , rx_msg_in ) = mpsc ::channel ( ) ;
@ -99,7 +126,8 @@ pub(crate) fn run(
app = app . explore_pwd ( ) ? ;
app = if let Some ( f ) = focused_path
app = if let Some ( f ) = self
. focused_path
. clone ( )
. map ( | f | f . to_string_lossy ( ) . to_string ( ) )
{
@ -111,7 +139,7 @@ pub(crate) fn run(
explorer ::explore_recursive_async (
app . explorer_config ( ) . clone ( ) ,
app . pwd ( ) . into ( ) ,
focused_path ,
self . focused_path ,
app . directory_buffer ( ) . map ( | d | d . focus ( ) ) . unwrap_or ( 0 ) ,
tx_msg_in . clone ( ) ,
) ;
@ -142,6 +170,11 @@ pub(crate) fn run(
pwd_watcher ::keep_watching ( app . pwd ( ) , tx_msg_in . clone ( ) , rx_pwd_watcher ) ? ;
// pipe_reader::keep_reading(app.pipe().msg_in().clone(), tx_msg_in.clone());
// Enqueue on_load messages
for msg in self . on_load {
tx_msg_in . send ( app ::Task ::new ( app ::MsgIn ::External ( msg ) , None ) ) ? ;
}
' outer : for task in rx_msg_in {
match app . handle_task ( task ) {
Ok ( a ) = > {
@ -209,7 +242,10 @@ pub(crate) fn run(
app ::MsgOut ::EnableMouse = > {
if ! mouse_enabled {
match execute ! ( terminal . backend_mut ( ) , event ::EnableMouseCapture ) {
match execute ! (
terminal . backend_mut ( ) ,
event ::EnableMouseCapture
) {
Ok ( _ ) = > {
mouse_enabled = true ;
}
@ -226,13 +262,16 @@ pub(crate) fn run(
} else {
app ::ExternalMsg ::EnableMouse
} ;
app =
app . handle_task ( app ::Task ::new ( app ::MsgIn ::External ( msg ) , None ) ) ? ;
app = app
. handle_task ( app ::Task ::new ( app ::MsgIn ::External ( msg ) , None ) ) ? ;
}
app ::MsgOut ::DisableMouse = > {
if mouse_enabled {
match execute ! ( terminal . backend_mut ( ) , event ::DisableMouseCapture ) {
match execute ! (
terminal . backend_mut ( ) ,
event ::DisableMouseCapture
) {
Ok ( _ ) = > {
mouse_enabled = false ;
}
@ -333,7 +372,10 @@ pub(crate) fn run(
tx_event_reader . send ( false ) ? ;
if mouse_enabled {
match execute ! ( terminal . backend_mut ( ) , event ::EnableMouseCapture ) {
match execute ! (
terminal . backend_mut ( ) ,
event ::EnableMouseCapture
) {
Ok ( _ ) = > {
mouse_enabled = true ;
}
@ -392,7 +434,10 @@ pub(crate) fn run(
tx_event_reader . send ( false ) ? ;
if mouse_enabled {
match execute ! ( terminal . backend_mut ( ) , event ::EnableMouseCapture ) {
match execute ! (
terminal . backend_mut ( ) ,
event ::EnableMouseCapture
) {
Ok ( _ ) = > {
mouse_enabled = true ;
}
@ -424,3 +469,4 @@ pub(crate) fn run(
result
}
}