use std::fs;
use std::os::unix::fs::PermissionsExt;
use std::path::Path;
use std::sync::Arc;
use anyhow::{anyhow, Context, Result};
use clap::Parser;
use log::info;
use regex::Regex;
use skim::SkimItem;
use sysinfo::{Disk, DiskExt, RefreshKind, System, SystemExt};
use tuikit::prelude::{from_keyname, Event};
use tuikit::term::Term;
use crate::args::Args;
use crate::bulkrename::Bulk;
use crate::cli_info::CliInfo;
use crate::compress::Compresser;
use crate::config::Settings;
use crate::constant_strings_paths::{NVIM, SS, TUIS_PATH};
use crate::copy_move::{copy_move, CopyMove};
use crate::cryptsetup::{BlockDeviceAction, CryptoDeviceOpener};
use crate::fileinfo::FileKind;
use crate::flagged::Flagged;
use crate::iso::IsoDevice;
use crate::log_line;
use crate::marks::Marks;
use crate::mode::{InputSimple, Mode, NeedConfirmation};
use crate::mount_help::MountHelper;
use crate::opener::{InternalVariant, Opener};
use crate::password::{
drop_sudo_privileges, execute_sudo_command_with_password, reset_sudo_faillock, PasswordHolder,
PasswordKind, PasswordUsage,
};
use crate::preview::Preview;
use crate::removable_devices::RemovableDevices;
use crate::selectable_content::SelectableContent;
use crate::shell_menu::ShellMenu;
use crate::shell_parser::ShellCommandParser;
use crate::skim::Skimer;
use crate::tab::Tab;
use crate::term_manager::MIN_WIDTH_FOR_DUAL_PANE;
use crate::trash::Trash;
use crate::tree::Tree;
use crate::users::Users;
use crate::utils::{current_username, disk_space, filename_from_path, is_program_in_path};
/// Holds every mutable parameter of the application itself, except for
/// the "display" information.
/// It holds 2 tabs (left & right), even if only one can be displayed sometimes.
/// It knows which tab is selected, which files are flagged,
/// which jump target is selected, a cache of normal file colors,
/// if we have to display one or two tabs and if all details are shown or only
/// the filename.
/// Mutation of this struct are mostly done externally, by the event crate :
/// `crate::event_exec`.
pub struct Status {
/// Vector of `Tab`, each of them are displayed in a separate tab.
pub tabs: [Tab; 2],
/// Index of the current selected tab
pub index: usize,
/// The flagged files
pub flagged: Flagged,
/// Marks allows you to jump to a save mark
pub marks: Marks,
/// terminal
pub term: Arc<Term>,
skimer: Option<Result<Skimer>>,
/// do we display one or two tabs ?
pub dual_pane: bool,
pub system_info: System,
/// do we display all info or only the filenames ?
pub display_full: bool,
/// use the second pane to preview auto
pub preview_second: bool,
/// The opener used by the application.
pub opener: Opener,
/// The help string.
pub help: String,
/// The trash
pub trash: Trash,
/// Encrypted devices opener
pub encrypted_devices: CryptoDeviceOpener,
/// Iso mounter. Set to None by default, dropped ASAP
pub iso_device: Option<IsoDevice>,
/// Compression methods
pub compression: Compresser,
/// NVIM RPC server address
pub nvim_server: String,
pub force_clear: bool,
pub bulk: Option<Bulk>,
pub