use std::fs;
use std::path::Path;
use std::sync::Arc;
use anyhow::{anyhow, Context, Result};
use clap::Parser;
use skim::SkimItem;
use sysinfo::{Disk, RefreshKind, System, SystemExt};
use tuikit::prelude::{from_keyname, Event};
use tuikit::term::Term;
use crate::app::ClickableLine;
use crate::app::Footer;
use crate::app::Header;
use crate::app::InternalSettings;
use crate::app::Session;
use crate::app::Tab;
use crate::common::{args_is_empty, is_sudo_command, path_to_string};
use crate::common::{current_username, disk_space, filename_from_path, is_program_in_path};
use crate::config::Bindings;
use crate::io::Args;
use crate::io::Internal;
use crate::io::Kind;
use crate::io::Opener;
use crate::io::MIN_WIDTH_FOR_DUAL_PANE;
use crate::io::{
execute_and_capture_output_without_check, execute_sudo_command_with_password,
execute_without_output_with_path, reset_sudo_faillock,
};
use crate::modes::CopyMove;
use crate::modes::Display;
use crate::modes::Edit;
use crate::modes::FileKind;
use crate::modes::InputSimple;
use crate::modes::IsoDevice;
use crate::modes::Menu;
use crate::modes::MountCommands;
use crate::modes::MountRepr;
use crate::modes::NeedConfirmation;
use crate::modes::PasswordKind;
use crate::modes::PasswordUsage;
use crate::modes::Permissions;
use crate::modes::Preview;
use crate::modes::SelectableContent;
use crate::modes::ShellCommandParser;
use crate::modes::Skimer;
use crate::modes::Tree;
use crate::modes::Users;
use crate::modes::{copy_move, regex_matcher};
use crate::modes::{BlockDeviceAction, Navigate};
use crate::{log_info, log_line};
pub enum Window {
Header,
Files,
Menu,
Footer,
}
/// 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,
skimer: Option<Result<Skimer>>,
/// Navigable menu
pub menu: Menu,
/// Display settings
pub display_settings: Session,
/// Interna settings
pub internal_settings: InternalSettings,
}
impl Status {
/// Creates a new status for the application.
/// It requires most of the information (arguments, configuration, height
/// of the terminal, the formated help string).
pub fn new(height: usize, term: Arc<Term>, opener: Opener) -> Result<Self> {
let skimer = None;
let index = 0;
let args = Args::parse();
let path = std::fs::canonicalize(Path::new(&args.path))?;
let start_dir = if path.is_dir() {
&path
} else {
path.parent().context("")?
};
let sys = System::new_with_specifics(RefreshKind::new().with_disks());
let display_settings = Session::new(term.term_size()?.0);
let mut internal_settings = InternalSettings::new(opener, term, sys);
let mount_points = internal_settings.mount_points();
let menu = Menu::new(start_dir, &mount_points)?;
let users_left = Users::new();
let users_right = users_left.clone();
let<