use std::borrow::Borrow;
use std::path;
use anyhow::{Context, Result};
use crate::app::Status;
use crate::app::Tab;
use crate::common::LAZYGIT;
use crate::common::NCDU;
use crate::common::{is_program_in_path, open_in_current_neovim};
use crate::common::{CONFIG_PATH, GIO};
use crate::config::Bindings;
use crate::config::START_FOLDER;
use crate::io::execute_without_output_with_path;
use crate::io::read_log;
use crate::io::SpecificCommand;
use crate::log_info;
use crate::log_line;
use crate::modes::help_string;
use crate::modes::lsblk_and_cryptsetup_installed;
use crate::modes::ContentWindow;
use crate::modes::Display;
use crate::modes::InputCompleted;
use crate::modes::LeaveMode;
use crate::modes::Mocp;
use crate::modes::Preview;
use crate::modes::RemovableDevices;
use crate::modes::SelectableContent;
use crate::modes::TuiApplications;
use crate::modes::MOCP;
use crate::modes::{Edit, InputSimple, MarkAction, Navigate, NeedConfirmation};
/// Links events from tuikit to custom actions.
/// It mutates `Status` or its children `Tab`.
pub struct EventAction {}
impl EventAction {
/// Once a quit event is received, we change a flag and break the main loop.
/// It's usefull to reset the cursor before leaving the application.
pub fn quit(status: &mut Status) -> Result<()> {
status.internal_settings.must_quit = true;
Ok(())
}
/// Refresh the current view, reloading the files. Move the selection to top.
pub fn refresh_view(status: &mut Status) -> Result<()> {
status.refresh_view()
}
/// Refresh the view if files were modified in current directory.
pub fn refresh_if_needed(tab: &mut Tab) -> Result<()> {
tab.refresh_if_needed()
}
pub fn resize(status: &mut Status, width: usize, height: usize) -> Result<()> {
status.resize(width, height)
}
/// Leave current mode to normal mode.
/// Reset the inputs and completion, reset the window, exit the preview.
pub fn reset_mode(status: &mut Status) -> Result<()> {
let tab = &mut status.tabs[status.index];
if matches!(tab.display_mode, Display::Preview) {
tab.set_display_mode(Display::Directory);
}
if tab.reset_edit_mode() {
status.menu.completion.reset();
tab.refresh_view()
} else {
tab.refresh_params()
}
}
/// Toggle between a full display (aka ls -lah) or a simple mode (only the
/// filenames).
pub fn toggle_display_full(status: &mut Status) -> Result<()> {
status.display_settings.metadata = !status.display_settings.metadata;
Ok(())
}
/// Toggle between dualpane and single pane. Does nothing if the width
/// is too low to display both panes.
pub fn toggle_dualpane(status: &mut Status) -> Result<()> {
status.display_settings.dual = !status.display_settings.dual;
status.select_left();
Ok(())
}
/// Toggle the second pane between preview & normal mode (files).
pub fn toggle_preview_second(status: &mut Status) -> Result<()> {
status.display_settings.preview =