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, 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::FileInfo;
use crate::modes::FileKind;
use crate::modes::Tree;
use crate::modes::Users;
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};
use crate::modes::{TreeLineBuilder, TreeLines};
/// 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" | "7z"
| "gz" | "zst" => Self::Archive,
"png" | "jpg" | "jpeg" | "tiff" | "heif" | "gif" | "cr2" | "nef" | "orf" | "sr2" => {
Self::Image
}
"ogg" |