diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 1b73af90..00000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,46 +0,0 @@ -on: - release: - types: [created] - push: - pull_request: - -name: ci - -jobs: - check: - name: Check - runs-on: ubuntu-latest - steps: - - name: Checkout sources - uses: actions/checkout@v2 - - - name: Install stable toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - - name: Run cargo check - uses: actions-rs/cargo@v1 - with: - command: check - - test: - name: Test Suite - runs-on: ubuntu-latest - steps: - - name: Checkout sources - uses: actions/checkout@v2 - - - name: Install stable toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - - name: Run cargo test - uses: actions-rs/cargo@v1 - with: - command: test diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index 7a35b143..00000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,109 +0,0 @@ -name: Publish - -on: - workflow_dispatch: - push: - tags: - - '*' - -jobs: - publish: - name: ${{ matrix.target }} - runs-on: ${{ matrix.os }} - strategy: - matrix: - include: - - os: ubuntu-20.04 - target: x86_64-unknown-linux-gnu - toolchain: stable - use-cross: false - - - os: ubuntu-20.04 - target: x86_64-unknown-linux-musl - toolchain: stable - use-cross: false - - - os: ubuntu-20.04 - target: aarch64-unknown-linux-gnu - toolchain: stable - use-cross: true - - - os: ubuntu-20.04 - target: aarch64-unknown-linux-musl - toolchain: stable - use-cross: true - - - os: macos-latest - target: x86_64-apple-darwin - toolchain: stable - use-cross: false - - - os: macos-latest - target: aarch64-apple-darwin - toolchain: stable - use-cross: false - - - os: windows-latest - target: x86_64-pc-windows-msvc - toolchain: nightly - use-cross: false - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - with: - fetch-depth: 1 - - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{ matrix.toolchain }} - profile: minimal - override: true - target: ${{ matrix.target }} - - - name: rust cache restore - uses: actions/cache/restore@v3 - with: - path: | - ~/.cargo/bin/ - ~/.cargo/registry/index/ - ~/.cargo/registry/cache/ - ~/.cargo/git/db/ - target/ - key: ${{ runner.os }}-cargo-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }} - - - name: Build - uses: actions-rs/cargo@v1 - with: - use-cross: ${{ matrix.use-cross }} - command: build - args: --target ${{ matrix.target }} --release --locked - - - name: Upload files (only for Mac/Linux) - if: matrix.target != 'x86_64-pc-windows-msvc' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - UPLOADTOOL_ISPRERELEASE: true - VERSION: ${{ github.ref_name }} - run: | - curl -L https://github.com/probonopd/uploadtool/raw/master/upload.sh --output upload.sh - mv target/${{ matrix.target }}/release/et et - tar -cavf et-${VERSION}-${{ matrix.target }}.tar.gz et CHANGELOG.md README.md LICENSE - bash upload.sh et-${VERSION}-${{ matrix.target }}.tar.gz - - - name: Rename files (only for Windows) - if: matrix.target == 'x86_64-pc-windows-msvc' - env: - VERSION: ${{ github.ref_name }} - run: | - mkdir output/ - mv target/${{ matrix.target }}/release/et.exe output/et-$env:VERSION-${{ matrix.target }}.exe - - - name: Upload files (only for Windows) - uses: ncipollo/release-action@v1 - if: matrix.target == 'x86_64-pc-windows-msvc' - with: - allowUpdates: true - artifacts: "output/*" - token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..ea1ec629 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,64 @@ +name: Release + +on: + push: + tags: + - v[0-9]+.[0-9]+.[0-9]+-custom + - v[0-9]+.[0-9]+.[0-9]+-custom-r[0-9]+ + +permissions: + contents: write + +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + - os: ubuntu-22.04 + rust-target: x86_64-unknown-linux-musl + - os: macos-12 + rust-target: x86_64-apple-darwin + - os: macos-12 + rust-target: aarch64-apple-darwin + env: + xcode_version: 14.2 + macosx_sdk: macosx13.1 + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set RUST_TARGET + run: echo 'RUST_TARGET=${{ matrix.rust-target }}' >> $GITHUB_ENV + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable + target: ${{ matrix.rust-target }} + + - name: Setup musl for Linux + if: matrix.os == 'ubuntu-22.04' + run: sudo apt-get -y -qq install musl-tools + + - name: Setup Xcode for macOS + if: matrix.os == 'macos-12' + run: sudo xcode-select -s '/Applications/Xcode_${{ env.xcode_version }}.app' + + - name: Set environment variables for Apple Silicon + if: matrix.rust-target == 'aarch64-apple-darwin' + run: | + export SDKROOT=$(xcrun -sdk ${{ env.macosx_sdk }} --show-sdk-path) + [[ -n $SDKROOT ]] && echo "SDKROOT=$SDKROOT" >> $GITHUB_ENV + export MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk ${{ env.macosx_sdk }} --show-sdk-platform-version) + [[ -n $MACOSX_DEPLOYMENT_TARGET ]] && echo "MACOSX_DEPLOYMENT_TARGET=$MACOSX_DEPLOYMENT_TARGET" >> $GITHUB_ENV + + - name: Build + run: make + + - name: Release + uses: ncipollo/release-action@v1 + with: + artifacts: "*.tar.xz" + allowUpdates: true diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index f7bd7ac6..00000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,116 +0,0 @@ -name: Test App With Cache - -on: - workflow_dispatch: - inputs: - version: - description: "tag version" - required: true - default: "v0.0.1" - -jobs: - publish: - name: ${{ matrix.target }} - runs-on: ${{ matrix.os }} - strategy: - matrix: - include: - - os: ubuntu-20.04 - target: x86_64-unknown-linux-gnu - use-cross: false - - - os: ubuntu-20.04 - target: x86_64-unknown-linux-musl - use-cross: false - - - os: ubuntu-20.04 - target: aarch64-unknown-linux-gnu - use-cross: true - - - os: ubuntu-20.04 - target: aarch64-unknown-linux-musl - use-cross: true - - - os: macos-latest - target: x86_64-apple-darwin - use-cross: false - - - os: macos-latest - target: aarch64-apple-darwin - use-cross: false - - - os: windows-latest - target: x86_64-pc-windows-msvc - use-cross: false - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - with: - fetch-depth: 1 - - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - profile: minimal - override: true - target: ${{ matrix.target }} - - - name: rust cache restore - uses: actions/cache/restore@v3 - with: - path: | - ~/.cargo/bin/ - ~/.cargo/registry/index/ - ~/.cargo/registry/cache/ - ~/.cargo/git/db/ - target/ - key: ${{ runner.os }}-cargo-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }} - - - - name: Build - uses: actions-rs/cargo@v1 - with: - use-cross: ${{ matrix.use-cross }} - command: build - args: --target ${{ matrix.target }} --release --locked - - - name: Rename files (only for Mac/Linux) - if: matrix.target != 'x86_64-pc-windows-msvc' - env: - VERSION: ${{ inputs.version }} - run: | - mkdir output/ - mv target/${{ matrix.target }}/release/et et - tar -cavf output/et-${VERSION}-${{ matrix.target }}.tar.gz et CHANGELOG.md README.md LICENSE - - - name: Rename files (only for Windows) - if: matrix.target == 'x86_64-pc-windows-msvc' - env: - VERSION: ${{ inputs.version }} - run: | - mkdir output/ - mv target/${{ matrix.target }}/release/et.exe output/et-$env:VERSION-${{ matrix.target }}.exe - - - name: Upload files - # arg info: https://github.com/ncipollo/release-action#release-action - uses: ncipollo/release-action@v1 - with: - allowUpdates: true - prerelease: true - artifacts: "output/*" - tag: ${{ inputs.version }} - token: ${{ secrets.GITHUB_TOKEN }} - - - - name: rust cache store - uses: actions/cache/save@v3 - with: - path: | - ~/.cargo/bin/ - ~/.cargo/registry/index/ - ~/.cargo/registry/cache/ - ~/.cargo/git/db/ - target/ - key: ${{ runner.os }}-cargo-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }} diff --git a/Cargo.toml b/Cargo.toml index ceab5774..d82c0efa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,3 +39,9 @@ thiserror = "1.0.40" indoc = "2.0.0" strip-ansi-escapes = "0.1.1" tempfile = "3.4.0" + +[profile.release] +codegen-units = 1 +lto = true +strip = true +opt-level = 3 diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..2b126ae5 --- /dev/null +++ b/Makefile @@ -0,0 +1,42 @@ +ifeq ($(RUST_TARGET),) + TARGET := + RELEASE_SUFFIX := +else + TARGET := $(RUST_TARGET) + RELEASE_SUFFIX := -$(TARGET) + export CARGO_BUILD_TARGET = $(RUST_TARGET) +endif + +PROJECT_NAME := et + +_HASH := \# +VERSION := $(lastword $(subst @, ,$(subst $(_HASH), ,$(shell cargo pkgid)))) +RELEASE := $(PROJECT_NAME)-$(VERSION)$(RELEASE_SUFFIX) + +DIST_DIR := dist +RELEASE_DIR := $(DIST_DIR)/$(RELEASE) + +BINARY := target/$(TARGET)/release/$(PROJECT_NAME) + +RELEASE_BINARY := $(RELEASE_DIR)/$(PROJECT_NAME) + +ARTIFACT := $(RELEASE).tar.xz + +.PHONY: all +all: $(ARTIFACT) + +$(BINARY): + cargo build --locked --release + +$(DIST_DIR) $(RELEASE_DIR): + mkdir -p $@ + +$(RELEASE_BINARY): $(BINARY) $(RELEASE_DIR) + cp -f $< $@ + +$(ARTIFACT): $(RELEASE_BINARY) + tar -C $(DIST_DIR) -Jcvf $@ $(RELEASE) + +.PHONY: clean +clean: + $(RM) -rf $(ARTIFACT) $(DIST_DIR) diff --git a/src/icons.rs b/src/icons.rs index b5980f8e..2248c100 100644 --- a/src/icons.rs +++ b/src/icons.rs @@ -138,18 +138,18 @@ static EXT_ICON_MAP: Lazy> = Lazy::new(|| { OsString::from("cpp") => (67, "\u{e61d}"), //  OsString::from("cpy") => (25, "\u{2699}"), // ⚙ OsString::from("cr") => (16, "\u{e24f}"), //  - OsString::from("cs") => (58, "\u{f81a}"), //  + OsString::from("cs") => (58, "\u{f031b}"), // 󰌛 OsString::from("csh") => (59, "\u{e795}"), //  OsString::from("cson") => (185, "\u{e60b}"), //  OsString::from("css") => (39, "\u{e749}"), //  - OsString::from("csv") => (113, "\u{f718}"), //  + OsString::from("csv") => (113, "\u{f0219}"), // 󰈙 OsString::from("cxx") => (67, "\u{e61d}"), //  OsString::from("dart") => (25, "\u{e798}"), //  OsString::from("db") => (188, "\u{e706}"), //  OsString::from("d") => (64, "\u{e7af}"), //  OsString::from("desktop") => (60, "\u{f108}"), //  OsString::from("diff") => (59, "\u{e728}"), //  - OsString::from("doc") => (25, "\u{f72b}"), //  + OsString::from("doc") => (25, "\u{f022c}"), // 󰈬 OsString::from("drl") => (217, "\u{e28c}"), //  OsString::from("dropbox") => (27, "\u{e707}"), //  OsString::from("dump") => (188, "\u{e706}"), //  @@ -198,7 +198,7 @@ static EXT_ICON_MAP: Lazy> = Lazy::new(|| { OsString::from("jpeg") => (140, "\u{e60d}"), //  OsString::from("jpg") => (140, "\u{e60d}"), //  OsString::from("js") => (185, "\u{e60c}"), //  - OsString::from("json5") => (185, "\u{fb25}"), // ﬥ + OsString::from("json5") => (185, "\u{f0626}"), // 󰘦 OsString::from("json") => (185, "\u{e60b}"), //  OsString::from("jsx") => (67, "\u{e625}"), //  OsString::from("ksh") => (59, "\u{e795}"), //  @@ -210,16 +210,16 @@ static EXT_ICON_MAP: Lazy> = Lazy::new(|| { OsString::from("license") => (185, "\u{e60a}"), //  OsString::from("licence") => (185, "\u{e60a}"), //  OsString::from("lock") => (250, "\u{f13e}"), //  - OsString::from("log") => (255, "\u{f831}"), //  + OsString::from("log") => (255, "\u{f00bc}"), // 󰂼 OsString::from("lua") => (74, "\u{e620}"), //  OsString::from("luau") => (74, "\u{e620}"), //  OsString::from("makefile") => (66, "\u{e779}"), //  OsString::from("markdown") => (67, "\u{e609}"), //  OsString::from("Makefile") => (66, "\u{e779}"), //  - OsString::from("material") => (132, "\u{f7f4}"), //  + OsString::from("material") => (132, "\u{f02f5}"), // 󰋵 OsString::from("md") => (255, "\u{f48a}"), //  OsString::from("mdx") => (67, "\u{f48a}"), //  - OsString::from("mint") => (108, "\u{f829}"), //  + OsString::from("mint") => (108, "\u{f032a}"), // 󰌪 OsString::from("mjs") => (221, "\u{e60c}"), //  OsString::from("mk") => (66, "\u{e779}"), //  OsString::from("ml") => (173, "\u{3bb}"), // λ @@ -228,16 +228,16 @@ static EXT_ICON_MAP: Lazy> = Lazy::new(|| { OsString::from("mustache") => (173, "\u{e60f}"), //  OsString::from("nim") => (220, "\u{1f451}"), // 👑 OsString::from("nix") => (110, "\u{f313}"), //  - OsString::from("opus") => (208, "\u{f722}"), //  + OsString::from("opus") => (208, "\u{f0223}"), // 󰈣 OsString::from("otf") => (231, "\u{f031}"), //  OsString::from("pck") => (66, "\u{f487}"), //  - OsString::from("pdf") => (124, "\u{f724}"), //  + OsString::from("pdf") => (124, "\u{f0226}"), // 󰈦 OsString::from("php") => (140, "\u{e608}"), //  OsString::from("pl") => (67, "\u{e769}"), //  OsString::from("pm") => (67, "\u{e769}"), //  OsString::from("png") => (140, "\u{e60d}"), //  OsString::from("pp") => (255, "\u{e631}"), //  - OsString::from("ppt") => (167, "\u{f726}"), //  + OsString::from("ppt") => (167, "\u{f0227}"), // 󰈧 OsString::from("prisma") => (255, "\u{5351}"), // 卑 OsString::from("pro") => (179, "\u{e7a1}"), //  OsString::from("ps1") => (69, "\u{f0a0a}"), // 󰨊 @@ -252,7 +252,7 @@ static EXT_ICON_MAP: Lazy> = Lazy::new(|| { OsString::from("query") => (154, "\u{e21c}"), //  OsString::from("rake") => (52, "\u{e791}"), //  OsString::from("rb") => (52, "\u{e791}"), //  - OsString::from("r") => (65, "\u{fcd2}"), // ﳒ + OsString::from("r") => (65, "\u{f07d4}"), // 󰟔 OsString::from("rlib") => (180, "\u{e7a8}"), //  OsString::from("rmd") => (67, "\u{e609}"), //  OsString::from("rproj") => (65, "\u{9276}"), // 鉶 @@ -261,53 +261,53 @@ static EXT_ICON_MAP: Lazy> = Lazy::new(|| { OsString::from("sass") => (204, "\u{e603}"), //  OsString::from("sbt") => (167, "\u{e737}"), //  OsString::from("scala") => (167, "\u{e737}"), //  - OsString::from("scm") => (16, "\u{fb26}"), // ﬦ + OsString::from("scm") => (16, "\u{f0627}"), // 󰘧 OsString::from("scss") => (204, "\u{e603}"), //  OsString::from("sh") => (59, "\u{e795}"), //  OsString::from("sig") => (173, "\u{3bb}"), // λ OsString::from("slim") => (166, "\u{e60e}"), //  OsString::from("sln") => (98, "\u{e70c}"), //  OsString::from("sml") => (173, "\u{3bb}"), // λ - OsString::from("sol") => (67, "\u{fcb9}"), // ﲹ + OsString::from("sol") => (67, "\u{f086a}"), // 󰡪 OsString::from("sql") => (188, "\u{e706}"), //  OsString::from("sqlite3") => (188, "\u{e706}"), //  OsString::from("sqlite") => (188, "\u{e706}"), //  OsString::from("styl") => (107, "\u{e600}"), //  OsString::from("sublime") => (98, "\u{e7aa}"), //  OsString::from("suo") => (98, "\u{e70c}"), //  - OsString::from("sv") => (29, "\u{f85a}"), //  + OsString::from("sv") => (29, "\u{f035b}"), // 󰍛 OsString::from("svelte") => (202, "\u{f260}"), //  - OsString::from("svg") => (215, "\u{fc1f}"), // ﰟ - OsString::from("svh") => (29, "\u{f85a}"), //  + OsString::from("svg") => (215, "\u{f0721}"), // 󰜡 + OsString::from("svh") => (29, "\u{f035b}"), // 󰍛 OsString::from("swift") => (173, "\u{e755}"), //  - OsString::from("tbc") => (67, "\u{fbd1}"), // ﯑ + OsString::from("tbc") => (67, "\u{f06d3}"), // 󰛓 OsString::from("t") => (67, "\u{e769}"), //  - OsString::from("tcl") => (67, "\u{fbd1}"), // ﯑ + OsString::from("tcl") => (67, "\u{f06d3}"), // 󰛓 OsString::from("terminal") => (71, "\u{f489}"), //  OsString::from("test.js") => (173, "\u{e60c}"), //  - OsString::from("tex") => (58, "\u{fb68}"), // ﭨ + OsString::from("tex") => (58, "\u{f0669}"), // 󰙩 OsString::from("tf") => (57, "\u{e2a6}"), //  OsString::from("tfvars") => (57, "\u{f15b}"), //  OsString::from("toml") => (66, "\u{e615}"), //  OsString::from("tres") => (185, "\u{e706}"), //  OsString::from("ts") => (67, "\u{e628}"), //  - OsString::from("tscn") => (140, "\u{f880}"), //  + OsString::from("tscn") => (140, "\u{f0381}"), // 󰎁 OsString::from("tsx") => (67, "\u{e7ba}"), //  OsString::from("twig") => (107, "\u{e61c}"), //  - OsString::from("txt") => (113, "\u{f718}"), //  + OsString::from("txt") => (113, "\u{f0219}"), // 󰈙 OsString::from("vala") => (5, "\u{e69e}"), //  - OsString::from("v") => (29, "\u{f85a}"), //  - OsString::from("vh") => (29, "\u{f85a}"), //  - OsString::from("vhd") => (29, "\u{f85a}"), //  - OsString::from("vhdl") => (29, "\u{f85a}"), //  + OsString::from("v") => (29, "\u{f035b}"), // 󰍛 + OsString::from("vh") => (29, "\u{f035b}"), // 󰍛 + OsString::from("vhd") => (29, "\u{f035b}"), // 󰍛 + OsString::from("vhdl") => (29, "\u{f035b}"), // 󰍛 OsString::from("vim") => (29, "\u{e62b}"), //  - OsString::from("vue") => (107, "\u{fd42}"), // ﵂ + OsString::from("vue") => (107, "\u{f0844}"), // 󰡄 OsString::from("wasm") => (99, "\u{e6a1}"), //  OsString::from("webmanifest") => (221, "\u{e60b}"), //  - OsString::from("webpack") => (67, "\u{fc29}"), // ﰩ + OsString::from("webpack") => (67, "\u{f072b}"), // 󰜫 OsString::from("webp") => (140, "\u{e60d}"), //  OsString::from("xcplayground") => (173, "\u{e755}"), //  - OsString::from("xls") => (23, "\u{f71a}"), //  + OsString::from("xls") => (23, "\u{f021b}"), // 󰈛 OsString::from("xml") => (173, "\u{8b39}"), // 謹 OsString::from("xul") => (173, "\u{e745}"), //  OsString::from("yaml") => (66, "\u{e615}"), //  diff --git a/src/render/context/config.rs b/src/render/context/config.rs index 3b10929e..6a3e1353 100644 --- a/src/render/context/config.rs +++ b/src/render/context/config.rs @@ -9,12 +9,13 @@ const ERDTREE_DIR: &str = "erdtree"; const CONFIG_DIR: &str = ".config"; const HOME: &str = "HOME"; const XDG_CONFIG_HOME: &str = "XDG_CONFIG_HOME"; +const XDG_CONFIG_NAME: &str = "config"; /// Reads the config file into a `String` if there is one. When `None` is provided then the config /// is looked for in the following locations in order: /// /// - `$ERDTREE_CONFIG_PATH` -/// - `$XDG_CONFIG_HOME/erdtree/.erdtreerc` +/// - `$XDG_CONFIG_HOME/erdtree/config` /// - `$XDG_CONFIG_HOME/.erdtreerc` /// - `$HOME/.config/erdtree/.erdtreerc` /// - `$HOME/.erdtreerc` @@ -24,7 +25,6 @@ pub fn read_config_to_string>(path: Option) -> Option .or_else(config_from_config_path) .or_else(config_from_xdg_path) .or_else(config_from_home) - .map(|e| prepend_arg_prefix(&e)) } /// Parses the config `str`, removing comments and preparing it as a format understood by @@ -75,18 +75,10 @@ fn config_from_home() -> Option { fn config_from_xdg_path() -> Option { let xdg_config = env::var_os(XDG_CONFIG_HOME).map(PathBuf::from)?; - let config_path = xdg_config.join(ERDTREE_DIR).join(ERDTREE_CONFIG_NAME); + let config_path = xdg_config.join(ERDTREE_DIR).join(XDG_CONFIG_NAME); fs::read_to_string(config_path).ok().or_else(|| { let config_path = xdg_config.join(ERDTREE_CONFIG_NAME); fs::read_to_string(config_path).ok() }) } - -/// Prepends "--\n" to the config string which is required for proper parsing by -/// [`get_matches_from`]. -/// -/// [`get_matches_from`]: clap::builder::Command::get_matches_from -fn prepend_arg_prefix(config: &str) -> String { - format!("--\n{config}") -} diff --git a/src/render/context/mod.rs b/src/render/context/mod.rs index d18af56e..fc14b18c 100644 --- a/src/render/context/mod.rs +++ b/src/render/context/mod.rs @@ -1,13 +1,11 @@ use super::disk_usage::{file_size::DiskUsage, units::PrefixKind}; use crate::tty; -use clap::{ - parser::ValueSource, ArgMatches, CommandFactory, Error as ClapError, FromArgMatches, Id, Parser, -}; +use clap::{CommandFactory, Error as ClapError, FromArgMatches, Parser}; use ignore::overrides::{Override, OverrideBuilder}; use sort::SortType; use std::{ convert::From, - ffi::{OsStr, OsString}, + ffi::OsString, io::{stdin, BufRead}, path::{Path, PathBuf}, }; @@ -101,7 +99,7 @@ pub struct Context { pub sort: SortType, /// Always sorts directories above files - #[arg(long)] + #[arg(short = 'D', long)] pub dirs_first: bool, /// Traverse symlink directories and consider their disk usage @@ -166,56 +164,20 @@ impl Context { return Self::from_arg_matches(&user_args).map_err(Error::ArgParse); } - if let Some(ref config) = config::read_config_to_string::<&str>(None) { - let raw_config_args = config::parse(config); - let config_args = Self::command().get_matches_from(raw_config_args); - - // If the user did not provide any arguments just read from config. - if !user_args.args_present() { - return Self::from_arg_matches(&config_args).map_err(Error::Config); - } - - // If the user did provide arguments we need to reconcile between config and - // user arguments. - let mut args = vec![OsString::from("--")]; - - let mut ids = user_args.ids().map(Id::as_str).collect::>(); - - ids.extend(config_args.ids().map(Id::as_str).collect::>()); - - ids = crate::utils::uniq(ids); - - for id in ids { - if id == "Context" { - continue; - } - if id == "dir" { - if let Ok(Some(raw)) = user_args.try_get_raw(id) { - let raw_args = raw.map(OsStr::to_owned).collect::>(); - - args.extend(raw_args); - continue; - } - } - - if let Some(user_arg) = user_args.value_source(id) { - match user_arg { - // prioritize the user arg if user provided a command line argument - ValueSource::CommandLine => Self::pick_args_from(id, &user_args, &mut args), - - // otherwise prioritize argument from the config - _ => Self::pick_args_from(id, &config_args, &mut args), - } - } else { - Self::pick_args_from(id, &config_args, &mut args); - } - } - - let clargs = Self::command().get_matches_from(args); - return Self::from_arg_matches(&clargs).map_err(Error::Config); - } - - Self::from_arg_matches(&user_args).map_err(Error::ArgParse) + config::read_config_to_string::<&str>(None) + .as_ref() + .map_or_else( + || Self::from_arg_matches(&user_args).map_err(Error::ArgParse), + |config| { + let raw_config_args = config::parse(config); + let mut args: Vec<_> = std::env::args_os().collect(); + args.splice(1..1, raw_config_args.iter().map(OsString::from)); + let config_args = Self::command() + .args_override_self(true) + .get_matches_from(args); + Self::from_arg_matches(&config_args).map_err(Error::Config) + }, + ) } /// Returns reference to the path of the root directory to be traversed. @@ -269,23 +231,6 @@ impl Context { builder.build() } - - /// Used to pick either from config or user args when constructing [Context]. - fn pick_args_from(id: &str, matches: &ArgMatches, args: &mut Vec) { - if let Ok(Some(raw)) = matches.try_get_raw(id) { - let kebap = id.replace('_', "-"); - - let raw_args = raw - .map(OsStr::to_owned) - .map(|s| vec![OsString::from(format!("--{kebap}")), s]) - .filter(|pair| pair[1] != "false") - .flatten() - .filter(|s| s != "true") - .collect::>(); - - args.extend(raw_args); - } - } } #[derive(Debug, thiserror::Error)] diff --git a/src/render/context/test.rs b/src/render/context/test.rs index f1337a89..4731c8f3 100644 --- a/src/render/context/test.rs +++ b/src/render/context/test.rs @@ -30,7 +30,8 @@ fn context_from_config() -> Option { config::read_config_to_string(Some(TEST_CONFIG)) .as_ref() .and_then(|config| { - let raw_config_args = config::parse(config); + let mut raw_config_args = config::parse(config); + raw_config_args.insert(0, "--"); let config_args = Context::command().get_matches_from(raw_config_args); Context::from_arg_matches(&config_args).ok() }) diff --git a/src/render/styles/mod.rs b/src/render/styles/mod.rs index a879a21a..83bb6ccf 100644 --- a/src/render/styles/mod.rs +++ b/src/render/styles/mod.rs @@ -83,31 +83,31 @@ fn init_ls_colors() { /// Initializes all color themes. fn init_themes() { let theme = hash! { - "vt" => format!("{}", Color::Purple.paint(VT)), - "uprt" => format!("{}", Color::Purple.paint(UPRT)), - "vtrt" => format!("{}", Color::Purple.paint(VTRT)) + "vt" => format!("{}", Color::White.paint(VT)), + "uprt" => format!("{}", Color::White.paint(UPRT)), + "vtrt" => format!("{}", Color::White.paint(VTRT)) }; TREE_THEME.set(theme).unwrap(); let link_theme = hash! { - "vt" => format!("{}", Color::Red.paint(VT)), - "uprt" => format!("{}", Color::Red.paint(UPRT)), - "vtrt" => format!("{}", Color::Red.paint(VTRT)) + "vt" => format!("{}", Color::White.paint(VT)), + "uprt" => format!("{}", Color::White.paint(UPRT)), + "vtrt" => format!("{}", Color::White.paint(VTRT)) }; LINK_THEME.set(link_theme).unwrap(); let du_theme = hash! { - "B" => Color::Cyan, - "KB" => Color::Yellow, - "KiB" => Color::Yellow, - "MB" => Color::Green, - "MiB" => Color::Green, - "GB" => Color::Red, - "GiB" => Color::Red, - "TB" => Color::Blue, - "TiB" => Color::Blue + "B" => Color::RGB(0xc0, 0xc0 ,0xc0), + "KB" => Color::RGB(0x90, 0xee, 0x90), + "KiB" => Color::RGB(0x90, 0xee, 0x90), + "MB" => Color::RGB(0xf0, 0xe6, 0x8c), + "MiB" => Color::RGB(0xf0, 0xe6, 0x8c), + "GB" => Color::RGB(0xff, 0x7f, 0x50), + "GiB" => Color::RGB(0xff, 0x7f, 0x50), + "TB" => Color::Red, + "TiB" => Color::Red }; DU_THEME.set(du_theme).unwrap(); diff --git a/src/render/tree/node/mod.rs b/src/render/tree/node/mod.rs index eb57ceca..3c63d92f 100644 --- a/src/render/tree/node/mod.rs +++ b/src/render/tree/node/mod.rs @@ -9,7 +9,7 @@ use crate::{ }, tty, }; -use ansi_term::{ANSIGenericString, Color, Style}; +use ansi_term::{ANSIGenericString, Style}; use ignore::DirEntry; use layout::SizeLocation; use lscolors::Style as LS_Style; @@ -41,6 +41,7 @@ pub struct Node { style: Option