fn run(
    window_event_loop: GlutinEventLoop<Event>,
    config: Config,
    options: Options,
) -> Result<(), Box<dyn Error>> {
    info!("Welcome to Alacritty");

    // Log the configuration paths.
    log_config_path(&config);

    // Set environment variables.
    setup_env(&config);

    let event_proxy = EventProxy::new(window_event_loop.create_proxy());

    let tab_manager = TabManager::new(event_proxy.clone(), config.clone());

    let tab_manager_mutex = Arc::new(tab_manager);

    // Create a display.
    //
    let display = Display::new(&config, &window_event_loop, tab_manager_mutex.clone())?;
    info!(
        "PTY dimensions: {:?} x {:?}",
        display.size_info.screen_lines(),
        display.size_info.columns()
    );

    let tab_manager_main_clone = tab_manager_mutex.clone();
    tab_manager_main_clone.set_size(display.size_info);

    if let Ok(idx) = tab_manager_main_clone.new_tab() {
        tab_manager_main_clone.select_tab(idx);
    } else {
        panic!("Error: Unable to create and select the initial tab!");
    }

    let event_proxy_clone = event_proxy.clone();
    std::thread::spawn(move || loop {
        std::thread::sleep(Duration::from_millis(100));

        event_proxy_clone.send_event(crate::event::Event::Terminal(
            alacritty_terminal::event::Event::Wakeup,
        ));
    });

    // Create a config monitor when config was loaded from path.
    //
    // The monitor watches the config file for changes and reloads it. Pending
    // config changes are processed in the main loop.
    if config.ui_config.live_config_reload {
        monitor::watch(config.ui_config.config_paths.clone(), event_proxy);
    }

    // Setup storage for message UI.
    let message_buffer = MessageBuffer::new();

    // Event processor.
    let tab_manager_processor_mutex_clone = tab_manager_mutex;
    let mut processor =
        Processor::new(tab_manager_processor_mutex_clone, message_buffer, config, display, options);

    // Start event loop and block until shutdown.
    processor.run(window_event_loop);

    // This explicit drop is needed for Windows, ConPTY backend. Otherwise a deadlock can occur.
    // The cause:
    //   - Drop for ConPTY will deadlock if the conout pipe has already been dropped.
    //   - The conout pipe is dropped when the io_thread is joined below (io_thread owns PTY).
    //   - ConPTY is dropped when the last of processor and io_thread are dropped, because both of
    //     them own an Arc<ConPTY>.
    //
    // The fix is to ensure that processor is dropped first. That way, when io_thread (i.e. PTY)
    // is dropped, it can ensure ConPTY is dropped before the conout pipe in the PTY drop order.
    //
    // FIXME: Change PTY API to enforce the correct drop order with the typesystem.
    drop(processor);

    // Shutdown PTY parser event loop.
    // loop_tx.send(Msg::Shutdown).expect("Error sending shutdown to PTY event loop");
    // io_thread.join().expect("join io thread");

    // FIXME patch notify library to have a shutdown method.
    // config_reloader.join().ok();

    // Without explicitly detaching the console cmd won't redraw it's prompt.
    #[cfg(windows)]
    unsafe {
        FreeConsole();
    }

    info!("Goodbye");

    Ok(())
}
/// Run Alacritty.
///
/// Creates a window, the terminal state, PTY, I/O event loop, input processor,
/// config change monitor, and runs the main display loop.
Run Alacritty.
Creates a window, the terminal state, PTY, I/O event loop, input processor,
config change monitor, and runs the main display loop.
Run Alacritty . Creates a window the terminal state PTY I / O event loop input processor config change monitor and runs the main display loop .
fn run(
    window_event_loop: GlutinEventLoop<Event>,
    config: Config,
    options: Options,
) -> Result<(), Box<dyn Error>> {
    info!("Welcome to Alacritty");
    // Log the configuration paths.
    log_config_path(&config);
    // Set environment variables.
    setup_env(&config);
    let event_proxy = EventProxy::new(window_event_loop.create_proxy());
    let tab_manager = TabManager::new(event_proxy.clone(), config.clone());
    let tab_manager_mutex = Arc::new(tab_manager);
    // Create a display.
    //
    let display = Display::new(&config, &window_event_loop, tab_manager_mutex.clone())?;
    info!(
        "PTY dimensions: {:?} x {:?}",
        display.size_info.screen_lines(),
        display.size_info.columns()
    );
    let tab_manager_main_clone = tab_manager_mutex.clone();
    tab_manager_main_clone.set_size(display.size_info);
    if let Ok(idx) = tab_manager_main_clone.new_tab() {
        tab_manager_main_clone.select_tab(idx);
    } else {
        panic!("Error: Unable to create and select the initial tab!");
    }
    let event_proxy_clone = event_proxy.clone();
    std::thread::spawn(move || loop {
        std::thread::sleep(Duration::from_millis(100));
        event_proxy_clone.send_event(crate::event::Event::Terminal(
            alacritty_terminal::event::Event::Wakeup,
        ));
    });
    // Create a config monitor when config was loaded from path.
    //
    // The monitor watches the config file for changes and reloads it. Pending
    // config changes are processed in the main loop.
    if config.ui_config.live_config_reload {
        monitor::watch(config.ui_config.config_paths.clone(), event_proxy);
    }
    // Setup storage for message UI.
    let message_buffer = MessageBuffer::new();
    // Event processor.
    let tab_manager_processor_mutex_clone = tab_manager_mutex;
    let mut processor =
        Processor::new(tab_manager_processor_mutex_clone, message_buffer, config, display, options);
    // Start event loop and block until shutdown.
    processor.run(window_event_loop);
    // This explicit drop is needed for Windows, ConPTY backend. Otherwise a deadlock can occur.
    // The cause:
    //   - Drop for ConPTY will deadlock if the conout pipe has already been dropped.
    //   - The conout pipe is dropped when the io_thread is joined below (io_thread owns PTY).
    //   - ConPTY is dropped when the last of processor and io_thread are dropped, because both of
    //     them own an Arc<ConPTY>.
    //
    // The fix is to ensure that processor is dropped first. That way, when io_thread (i.e. PTY)
    // is dropped, it can ensure ConPTY is dropped before the conout pipe in the PTY drop order.
    //
    // FIXME: Change PTY API to enforce the correct drop order with the typesystem.
    drop(processor);
    // Shutdown PTY parser event loop.
    // loop_tx.send(Msg::Shutdown).expect("Error sending shutdown to PTY event loop");
    // io_thread.join().expect("join io thread");
    // FIXME patch notify library to have a shutdown method.
    // config_reloader.join().ok();
    // Without explicitly detaching the console cmd won't redraw it's prompt.
    #[cfg(windows)]
    unsafe {
        FreeConsole();
    }
    info!("Goodbye");
    Ok(())
}
fn run ( window_event_loop : GlutinEventLoop < Event > , config : Config , options : Options , ) -> Result < ( ) , Box < dyn Error > > { info ! ( " " ) ; // Log the configuration paths. log_config_path ( & config ) ; // Set environment variables. setup_env ( & config ) ; let event_proxy = EventProxy :: new ( window_event_loop . create_proxy ( ) ) ; let tab_manager = TabManager :: new ( event_proxy . clone ( ) , config . clone ( ) ) ; let tab_manager_mutex = Arc :: new ( tab_manager ) ; // Create a display. // let display = Display :: new ( & config , & window_event_loop , tab_manager_mutex . clone ( ) ) ? ; info ! ( " " display size_info screen_lines ( ) display size_info columns ( ) ) ; let tab_manager_main_clone = tab_manager_mutex . clone ( ) ; tab_manager_main_clone . set_size ( display . size_info ) ; if let Ok ( idx ) = tab_manager_main_clone . new_tab ( ) { tab_manager_main_clone . select_tab ( idx ) ; } else { panic ! ( " " ) ; } let event_proxy_clone = event_proxy . clone ( ) ; std :: thread :: spawn ( move | | loop { std :: thread :: sleep ( Duration :: from_millis ( 100 ) ) ; event_proxy_clone . send_event ( crate :: event :: Event :: Terminal ( alacritty_terminal :: event :: Event :: Wakeup , ) ) ; } ) ; // Create a config monitor when config was loaded from path. // // The monitor watches the config file for changes and reloads it. Pending // config changes are processed in the main loop. if config . ui_config . live_config_reload { monitor :: watch ( config . ui_config . config_paths . clone ( ) , event_proxy ) ; } // Setup storage for message UI. let message_buffer = MessageBuffer :: new ( ) ; // Event processor. let tab_manager_processor_mutex_clone = tab_manager_mutex ; let mut processor = Processor :: new ( tab_manager_processor_mutex_clone , message_buffer , config , display , options ) ; // Start event loop and block until shutdown. processor . run ( window_event_loop ) ; // This explicit drop is needed for Windows, ConPTY backend. Otherwise a deadlock can occur. // The cause: //   - Drop for ConPTY will deadlock if the conout pipe has already been dropped. //   - The conout pipe is dropped when the io_thread is joined below (io_thread owns PTY). //   - ConPTY is dropped when the last of processor and io_thread are dropped, because both of //     them own an Arc<ConPTY>. // // The fix is to ensure that processor is dropped first. That way, when io_thread (i.e. PTY) // is dropped, it can ensure ConPTY is dropped before the conout pipe in the PTY drop order. // // FIXME: Change PTY API to enforce the correct drop order with the typesystem. drop ( processor ) ; // Shutdown PTY parser event loop. // loop_tx.send(Msg::Shutdown).expect("Error sending shutdown to PTY event loop"); // io_thread.join().expect("join io thread"); // FIXME patch notify library to have a shutdown method. // config_reloader.join().ok(); // Without explicitly detaching the console cmd won't redraw it's prompt. # [ cfg ( windows ) ] unsafe { FreeConsole ( ) ; } info ! ( " " ) ; Ok ( ( ) ) }
Run Alacritty.
Run Alacritty .
window_event_loop
GlutinEventLoop<Event>
config
Config
options
Options
window_event_loop
GlutinEventLoop<Event>
config
Config
options
Options