mirror of
https://github.com/sharkdp/bat.git
synced 2025-09-02 03:12:25 +01:00
Strip dependencies of bat-as-a-library
This commit is contained in:
committed by
David Peter
parent
e7e1967bb0
commit
570805bc98
@@ -9,13 +9,9 @@ use crate::{
|
||||
config::{get_args_from_config_file, get_args_from_env_var},
|
||||
};
|
||||
use clap::ArgMatches;
|
||||
use wild;
|
||||
|
||||
use console::Term;
|
||||
|
||||
#[cfg(windows)]
|
||||
use ansi_term;
|
||||
|
||||
use bat::{
|
||||
config::{
|
||||
Config, HighlightedLineRanges, InputFile, LineRange, LineRanges, MappingTarget, OutputWrap,
|
||||
|
@@ -1,4 +1,4 @@
|
||||
use clap::{App as ClapApp, AppSettings, Arg, ArgGroup, SubCommand};
|
||||
use clap::{crate_name, crate_version, App as ClapApp, AppSettings, Arg, ArgGroup, SubCommand};
|
||||
use std::path::Path;
|
||||
|
||||
pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
|
||||
|
@@ -4,8 +4,6 @@ use std::fs;
|
||||
use std::io::{self, Write};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use shell_words;
|
||||
|
||||
use crate::directories::PROJECT_DIRS;
|
||||
|
||||
pub fn config_file() -> PathBuf {
|
||||
|
@@ -1,7 +1,6 @@
|
||||
use std::env;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use dirs;
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
/// Wrapper for 'dirs' that treats MacOS more like Linux, by following the XDG specification.
|
||||
|
@@ -1,11 +1,6 @@
|
||||
// `error_chain!` can recurse deeply
|
||||
#![recursion_limit = "1024"]
|
||||
|
||||
#[macro_use]
|
||||
extern crate clap;
|
||||
|
||||
extern crate dirs as dirs_rs;
|
||||
|
||||
mod app;
|
||||
mod assets;
|
||||
mod clap_app;
|
||||
|
@@ -2,20 +2,20 @@ use error_chain::error_chain;
|
||||
|
||||
error_chain! {
|
||||
foreign_links {
|
||||
Clap(::clap::Error);
|
||||
Io(::std::io::Error);
|
||||
SyntectError(::syntect::LoadingError);
|
||||
ParseIntError(::std::num::ParseIntError);
|
||||
GlobParsingError(::globset::Error);
|
||||
Clap(clap::Error);
|
||||
Io(std::io::Error);
|
||||
SyntectError(syntect::LoadingError);
|
||||
ParseIntError(std::num::ParseIntError);
|
||||
GlobParsingError(globset::Error);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn default_error_handler(error: &Error) {
|
||||
match error {
|
||||
Error(ErrorKind::Io(ref io_error), _)
|
||||
if io_error.kind() == ::std::io::ErrorKind::BrokenPipe =>
|
||||
if io_error.kind() == std::io::ErrorKind::BrokenPipe =>
|
||||
{
|
||||
::std::process::exit(0);
|
||||
std::process::exit(0);
|
||||
}
|
||||
_ => {
|
||||
use ansi_term::Colour::Red;
|
||||
@@ -23,3 +23,36 @@ pub fn default_error_handler(error: &Error) {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Mock out a type for clap::Error if we aren't pulling in a dependency on clap.
|
||||
//
|
||||
// This can be removed after migrating away from error_chain to some modern
|
||||
// derive-based error library such as thiserror, in favor of:
|
||||
//
|
||||
// #[derive(Error)]
|
||||
// pub enum Error {
|
||||
// #[cfg(feature = "application")]
|
||||
// Clap(clap::Error),
|
||||
// ...
|
||||
// }
|
||||
//
|
||||
#[cfg(not(feature = "application"))]
|
||||
mod clap {
|
||||
use std::fmt::{self, Debug, Display};
|
||||
|
||||
pub struct Error(());
|
||||
|
||||
impl Display for Error {
|
||||
fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for Error {
|
||||
fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for Error {}
|
||||
}
|
||||
|
11
src/lib.rs
11
src/lib.rs
@@ -1,17 +1,6 @@
|
||||
// `error_chain!` can recurse deeply
|
||||
#![recursion_limit = "1024"]
|
||||
|
||||
extern crate ansi_term;
|
||||
extern crate atty;
|
||||
extern crate console;
|
||||
extern crate content_inspector;
|
||||
extern crate dirs as dirs_rs;
|
||||
extern crate encoding;
|
||||
extern crate git2;
|
||||
extern crate shell_words;
|
||||
extern crate syntect;
|
||||
extern crate wild;
|
||||
|
||||
pub(crate) mod assets;
|
||||
pub mod config;
|
||||
pub(crate) mod controller;
|
||||
|
@@ -4,8 +4,6 @@ use std::io::{self, Write};
|
||||
use std::path::PathBuf;
|
||||
use std::process::{Child, Command, Stdio};
|
||||
|
||||
use shell_words;
|
||||
|
||||
use crate::config::PagingMode;
|
||||
use crate::errors::*;
|
||||
use crate::less::retrieve_less_version;
|
||||
|
@@ -1,5 +1,3 @@
|
||||
extern crate ansi_colours;
|
||||
|
||||
use ansi_term::Colour::{Fixed, RGB};
|
||||
use ansi_term::{self, Style};
|
||||
|
||||
|
Reference in New Issue
Block a user