use std::cmp::min;
use std::fmt::Write as _;
use std::fs::metadata;
use std::io::Cursor;
use std::io::{BufRead, BufReader, Read};
use std::iter::{Enumerate, Skip, Take};
use std::path::{Path, PathBuf};
use std::slice::Iter;
use anyhow::{anyhow, Context, Result};
use content_inspector::{inspect, ContentType};
use syntect::easy::HighlightLines;
use syntect::highlighting::{Style, ThemeSet};
use syntect::parsing::{SyntaxReference, SyntaxSet};
use tuikit::attr::{Attr, Color};
use crate::common::{
CALC_PDF_PATH, DIFF, FFMPEG, FONTIMAGE, ISOINFO, JUPYTER, LIBREOFFICE, LSBLK, LSOF, MEDIAINFO,
PANDOC, RSVG_CONVERT, SS, THUMBNAIL_PATH, UEBERZUG,
};
use crate::log_info;
use crate::modes::ContentWindow;
use crate::modes::Users;
use crate::modes::{ColorEffect, FileInfo, FileKind};
use crate::modes::{ColoredString, Tree};
use crate::common::{clear_tmp_file, filename_from_path, is_program_in_path, path_to_string};
use crate::io::{execute_and_capture_output_without_check, execute_and_output_no_log};
use crate::modes::FilterKind;
use crate::modes::SortKind;
use crate::modes::{list_files_tar, list_files_zip};
/// Different kind of extension for grouped by previewers.
/// Any extension we can preview should be matched here.
#[derive(Default, Eq, PartialEq)]
pub enum ExtensionKind {
Archive,
Image,
Audio,
Video,
Font,
Svg,
Pdf,
Iso,
Notebook,
Office,
Epub,
#[default]
Unknown,
}
impl ExtensionKind {
/// Match any known extension against an extension kind.
pub fn matcher(ext: &str) -> Self {
match ext {
"zip" | "gzip" | "bzip2" | "xz" | "lzip" | "lzma" | "tar" | "mtree" | "raw" |