mirror of
https://github.com/sharkdp/hexyl.git
synced 2026-10-26 20:16:34 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
becc75caf1 | ||
|
|
cc9476d665 | ||
|
|
ab381e88f8 | ||
|
|
361ded43fd | ||
|
|
20056fb4d9 | ||
|
|
34c55b5e55 | ||
|
|
f4c4b22c57 | ||
|
|
98c65d94e7 | ||
|
|
d74520fbab | ||
|
|
c8b05ff96f | ||
|
|
734365723b |
No files matched your search
+122
-114
@@ -1,8 +1,8 @@
|
||||
name: CICD
|
||||
|
||||
env:
|
||||
MIN_SUPPORTED_RUST_VERSION: "1.56.1"
|
||||
CICD_INTERMEDIATES_DIR: "_cicd-intermediates"
|
||||
MSRV_FEATURES: ""
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
@@ -14,102 +14,84 @@ on:
|
||||
- '*'
|
||||
|
||||
jobs:
|
||||
crate_metadata:
|
||||
name: Extract crate metadata
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Extract crate information
|
||||
id: crate_metadata
|
||||
run: |
|
||||
cargo metadata --no-deps --format-version 1 | jq -r '"name=" + .packages[0].name' | tee -a $GITHUB_OUTPUT
|
||||
cargo metadata --no-deps --format-version 1 | jq -r '"version=" + .packages[0].version' | tee -a $GITHUB_OUTPUT
|
||||
cargo metadata --no-deps --format-version 1 | jq -r '"maintainer=" + .packages[0].authors[0]' | tee -a $GITHUB_OUTPUT
|
||||
cargo metadata --no-deps --format-version 1 | jq -r '"homepage=" + .packages[0].homepage' | tee -a $GITHUB_OUTPUT
|
||||
cargo metadata --no-deps --format-version 1 | jq -r '"msrv=" + .packages[0].rust_version' | tee -a $GITHUB_OUTPUT
|
||||
outputs:
|
||||
name: ${{ steps.crate_metadata.outputs.name }}
|
||||
version: ${{ steps.crate_metadata.outputs.version }}
|
||||
maintainer: ${{ steps.crate_metadata.outputs.maintainer }}
|
||||
homepage: ${{ steps.crate_metadata.outputs.homepage }}
|
||||
msrv: ${{ steps.crate_metadata.outputs.msrv }}
|
||||
|
||||
ensure_cargo_fmt:
|
||||
name: Ensure 'cargo fmt' has been run
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
components: rustfmt
|
||||
- uses: actions/checkout@v3
|
||||
- run: cargo fmt -- --check
|
||||
|
||||
min_version:
|
||||
name: Minimum supported rust version
|
||||
runs-on: ubuntu-20.04
|
||||
needs: crate_metadata
|
||||
runs-on: ubuntu-18.04
|
||||
steps:
|
||||
- name: Checkout source code
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Install rust toolchain (v${{ needs.crate_metadata.outputs.msrv }})
|
||||
uses: dtolnay/rust-toolchain@master
|
||||
- name: Install rust toolchain (v${{ env.MIN_SUPPORTED_RUST_VERSION }})
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ needs.crate_metadata.outputs.msrv }}
|
||||
components: clippy
|
||||
toolchain: ${{ env.MIN_SUPPORTED_RUST_VERSION }}
|
||||
default: true
|
||||
profile: minimal # minimal component installation (ie, no documentation)
|
||||
components: clippy, rustfmt
|
||||
|
||||
- name: Ensure `cargo fmt` has been run
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: fmt
|
||||
args: -- --check
|
||||
|
||||
- name: Run clippy (on minimum supported rust version to prevent warnings we can't fix)
|
||||
run: cargo clippy --locked --all-targets ${{ env.MSRV_FEATURES }}
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: clippy
|
||||
args: --locked --all-targets
|
||||
|
||||
- name: Run tests
|
||||
run: cargo test --locked ${{ env.MSRV_FEATURES }}
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: test
|
||||
args: --locked
|
||||
|
||||
build:
|
||||
name: ${{ matrix.job.target }} (${{ matrix.job.os }})
|
||||
name: ${{ matrix.job.os }} (${{ matrix.job.target }})
|
||||
runs-on: ${{ matrix.job.os }}
|
||||
needs: crate_metadata
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
job:
|
||||
- { target: aarch64-unknown-linux-gnu , os: ubuntu-20.04, use-cross: true }
|
||||
- { target: arm-unknown-linux-gnueabihf , os: ubuntu-20.04, use-cross: true }
|
||||
- { target: arm-unknown-linux-musleabihf, os: ubuntu-20.04, use-cross: true }
|
||||
- { target: i686-pc-windows-msvc , os: windows-2019 }
|
||||
- { target: i686-unknown-linux-gnu , os: ubuntu-20.04, use-cross: true }
|
||||
- { target: i686-unknown-linux-musl , os: ubuntu-20.04, use-cross: true }
|
||||
- { target: x86_64-apple-darwin , os: macos-12 }
|
||||
- { target: x86_64-pc-windows-gnu , os: windows-2019 }
|
||||
- { target: x86_64-pc-windows-msvc , os: windows-2019 }
|
||||
- { target: x86_64-unknown-linux-gnu , os: ubuntu-20.04, use-cross: true }
|
||||
- { target: x86_64-unknown-linux-musl , os: ubuntu-20.04, use-cross: true }
|
||||
env:
|
||||
BUILD_CMD: cargo
|
||||
- { os: ubuntu-18.04, target: arm-unknown-linux-gnueabihf , use-cross: true }
|
||||
- { os: ubuntu-18.04, target: aarch64-unknown-linux-gnu , use-cross: true }
|
||||
- { os: ubuntu-18.04, target: i686-unknown-linux-gnu , use-cross: true }
|
||||
- { os: ubuntu-18.04, target: i686-unknown-linux-musl , use-cross: true }
|
||||
- { os: ubuntu-18.04, target: x86_64-unknown-linux-gnu }
|
||||
- { os: ubuntu-18.04, target: x86_64-unknown-linux-musl , use-cross: true }
|
||||
- { os: macos-10.15 , target: x86_64-apple-darwin }
|
||||
# - { os: windows-2019, target: i686-pc-windows-gnu } ## disabled; error: linker `i686-w64-mingw32-gcc` not found
|
||||
- { os: windows-2019, target: i686-pc-windows-msvc }
|
||||
- { os: windows-2019, target: x86_64-pc-windows-gnu }
|
||||
- { os: windows-2019, target: x86_64-pc-windows-msvc }
|
||||
steps:
|
||||
- name: Checkout source code
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Install prerequisites
|
||||
shell: bash
|
||||
run: |
|
||||
case ${{ matrix.job.target }} in
|
||||
arm-unknown-linux-*) sudo apt-get -y update ; sudo apt-get -y install gcc-arm-linux-gnueabihf ;;
|
||||
arm-unknown-linux-gnueabihf) sudo apt-get -y update ; sudo apt-get -y install gcc-arm-linux-gnueabihf ;;
|
||||
aarch64-unknown-linux-gnu) sudo apt-get -y update ; sudo apt-get -y install gcc-aarch64-linux-gnu ;;
|
||||
esac
|
||||
|
||||
- name: Install Rust toolchain
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
targets: ${{ matrix.job.target }}
|
||||
|
||||
- name: Install cross
|
||||
if: matrix.job.use-cross
|
||||
uses: taiki-e/install-action@v2
|
||||
with:
|
||||
tool: cross
|
||||
|
||||
- name: Overwrite build command env variable
|
||||
if: matrix.job.use-cross
|
||||
- name: Extract crate information
|
||||
shell: bash
|
||||
run: echo "BUILD_CMD=cross" >> $GITHUB_ENV
|
||||
run: |
|
||||
echo "PROJECT_NAME=$(sed -n 's/^name = "\(.*\)"/\1/p' Cargo.toml | head -n1)" >> $GITHUB_ENV
|
||||
echo "PROJECT_VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n1)" >> $GITHUB_ENV
|
||||
echo "PROJECT_MAINTAINER=$(sed -n 's/^authors = \["\(.*\)"\]/\1/p' Cargo.toml)" >> $GITHUB_ENV
|
||||
echo "PROJECT_HOMEPAGE=$(sed -n 's/^homepage = "\(.*\)"/\1/p' Cargo.toml)" >> $GITHUB_ENV
|
||||
|
||||
- name: Install Rust toolchain
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
target: ${{ matrix.job.target }}
|
||||
override: true
|
||||
profile: minimal # minimal component installation (ie, no documentation)
|
||||
|
||||
- name: Show version information (Rust, cargo, GCC)
|
||||
shell: bash
|
||||
@@ -122,16 +104,21 @@ jobs:
|
||||
rustc -V
|
||||
|
||||
- name: Build
|
||||
shell: bash
|
||||
run: $BUILD_CMD build --locked --release --target=${{ matrix.job.target }}
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
use-cross: ${{ matrix.job.use-cross }}
|
||||
command: build
|
||||
args: --release --target=${{ matrix.job.target }}
|
||||
|
||||
- name: Run example
|
||||
if: ${{ !matrix.job.use-cross }}
|
||||
shell: bash
|
||||
run: $BUILD_CMD run --release --target=${{ matrix.job.target }} --example=simple
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
use-cross: ${{ matrix.job.use-cross }}
|
||||
command: run
|
||||
args: --release --target=${{ matrix.job.target }} --example=simple
|
||||
|
||||
- name: Set binary name & path
|
||||
id: bin
|
||||
- name: Strip debug information from executable
|
||||
id: strip
|
||||
shell: bash
|
||||
run: |
|
||||
# Figure out suffix of binary
|
||||
@@ -140,13 +127,31 @@ jobs:
|
||||
*-pc-windows-*) EXE_suffix=".exe" ;;
|
||||
esac;
|
||||
|
||||
# Setup paths
|
||||
BIN_NAME="${{ needs.crate_metadata.outputs.name }}${EXE_suffix}"
|
||||
BIN_PATH="target/${{ matrix.job.target }}/release/${BIN_NAME}"
|
||||
# Figure out what strip tool to use if any
|
||||
STRIP="strip"
|
||||
case ${{ matrix.job.target }} in
|
||||
arm-unknown-linux-gnueabihf) STRIP="arm-linux-gnueabihf-strip" ;;
|
||||
aarch64-unknown-linux-gnu) STRIP="aarch64-linux-gnu-strip" ;;
|
||||
*-pc-windows-msvc) STRIP="" ;;
|
||||
esac;
|
||||
|
||||
# Let subsequent steps know where to find the binary
|
||||
echo "BIN_PATH=${BIN_PATH}" >> $GITHUB_OUTPUT
|
||||
echo "BIN_NAME=${BIN_NAME}" >> $GITHUB_OUTPUT
|
||||
# Setup paths
|
||||
BIN_DIR="${{ env.CICD_INTERMEDIATES_DIR }}/stripped-release-bin/"
|
||||
mkdir -p "${BIN_DIR}"
|
||||
BIN_NAME="${{ env.PROJECT_NAME }}${EXE_suffix}"
|
||||
BIN_PATH="${BIN_DIR}/${BIN_NAME}"
|
||||
|
||||
# Copy the release build binary to the result location
|
||||
cp "target/${{ matrix.job.target }}/release/${BIN_NAME}" "${BIN_DIR}"
|
||||
|
||||
# Also strip if possible
|
||||
if [ -n "${STRIP}" ]; then
|
||||
"${STRIP}" "${BIN_PATH}"
|
||||
fi
|
||||
|
||||
# Let subsequent steps know where to find the (stripped) bin
|
||||
echo ::set-output name=BIN_PATH::${BIN_PATH}
|
||||
echo ::set-output name=BIN_NAME::${BIN_NAME}
|
||||
|
||||
- name: Set testing options
|
||||
id: test-options
|
||||
@@ -154,41 +159,44 @@ jobs:
|
||||
run: |
|
||||
# test only library unit tests and binary for arm-type targets
|
||||
unset CARGO_TEST_OPTIONS
|
||||
unset CARGO_TEST_OPTIONS ; case ${{ matrix.job.target }} in arm-* | aarch64-*) CARGO_TEST_OPTIONS="--lib --bin ${{ needs.crate_metadata.outputs.name }}" ;; esac;
|
||||
echo "CARGO_TEST_OPTIONS=${CARGO_TEST_OPTIONS}" >> $GITHUB_OUTPUT
|
||||
unset CARGO_TEST_OPTIONS ; case ${{ matrix.job.target }} in arm-* | aarch64-*) CARGO_TEST_OPTIONS="--lib --bin ${PROJECT_NAME}" ;; esac;
|
||||
echo ::set-output name=CARGO_TEST_OPTIONS::${CARGO_TEST_OPTIONS}
|
||||
|
||||
- name: Run tests
|
||||
shell: bash
|
||||
run: $BUILD_CMD test --locked --target=${{ matrix.job.target }} ${{ steps.test-options.outputs.CARGO_TEST_OPTIONS}}
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
use-cross: ${{ matrix.job.use-cross }}
|
||||
command: test
|
||||
args: --target=${{ matrix.job.target }} ${{ steps.test-options.outputs.CARGO_TEST_OPTIONS}}
|
||||
|
||||
- name: Setup Pandoc
|
||||
uses: r-lib/actions/setup-pandoc@v2
|
||||
|
||||
- name: Generate man page
|
||||
run: pandoc -s -f markdown -t man -o "doc/${{ needs.crate_metadata.outputs.name }}.1" "doc/${{ needs.crate_metadata.outputs.name }}.1.md"
|
||||
run: pandoc -s -f markdown -t man -o "doc/${{ env.PROJECT_NAME }}.1" "doc/${{ env.PROJECT_NAME }}.1.md"
|
||||
|
||||
- name: Create tarball
|
||||
id: package
|
||||
shell: bash
|
||||
run: |
|
||||
PKG_suffix=".tar.gz" ; case ${{ matrix.job.target }} in *-pc-windows-*) PKG_suffix=".zip" ;; esac;
|
||||
PKG_BASENAME=${{ needs.crate_metadata.outputs.name }}-v${{ needs.crate_metadata.outputs.version }}-${{ matrix.job.target }}
|
||||
PKG_BASENAME=${PROJECT_NAME}-v${PROJECT_VERSION}-${{ matrix.job.target }}
|
||||
PKG_NAME=${PKG_BASENAME}${PKG_suffix}
|
||||
echo "PKG_NAME=${PKG_NAME}" >> $GITHUB_OUTPUT
|
||||
echo ::set-output name=PKG_NAME::${PKG_NAME}
|
||||
|
||||
PKG_STAGING="${{ env.CICD_INTERMEDIATES_DIR }}/package"
|
||||
ARCHIVE_DIR="${PKG_STAGING}/${PKG_BASENAME}/"
|
||||
mkdir -p "${ARCHIVE_DIR}"
|
||||
|
||||
# Binary
|
||||
cp "${{ steps.bin.outputs.BIN_PATH }}" "$ARCHIVE_DIR"
|
||||
cp "${{ steps.strip.outputs.BIN_PATH }}" "$ARCHIVE_DIR"
|
||||
|
||||
# Man page
|
||||
cp "doc/${{ env.PROJECT_NAME }}.1" "$ARCHIVE_DIR"
|
||||
|
||||
# README, LICENSE and CHANGELOG files
|
||||
cp "README.md" "LICENSE-MIT" "LICENSE-APACHE" "CHANGELOG.md" "$ARCHIVE_DIR"
|
||||
|
||||
# Man page
|
||||
cp "doc/${{ needs.crate_metadata.outputs.name }}.1" "$ARCHIVE_DIR"
|
||||
|
||||
# base compressed package
|
||||
pushd "${PKG_STAGING}/" >/dev/null
|
||||
case ${{ matrix.job.target }} in
|
||||
@@ -198,7 +206,7 @@ jobs:
|
||||
popd >/dev/null
|
||||
|
||||
# Let subsequent steps know where to find the compressed package
|
||||
echo "PKG_PATH=${PKG_STAGING}/${PKG_NAME}" >> $GITHUB_OUTPUT
|
||||
echo ::set-output name=PKG_PATH::"${PKG_STAGING}/${PKG_NAME}"
|
||||
|
||||
- name: Create Debian package
|
||||
id: debian-package
|
||||
@@ -210,10 +218,10 @@ jobs:
|
||||
DPKG_DIR="${DPKG_STAGING}/dpkg"
|
||||
mkdir -p "${DPKG_DIR}"
|
||||
|
||||
DPKG_BASENAME=${{ needs.crate_metadata.outputs.name }}
|
||||
DPKG_CONFLICTS=${{ needs.crate_metadata.outputs.name }}-musl
|
||||
case ${{ matrix.job.target }} in *-musl) DPKG_BASENAME=${{ needs.crate_metadata.outputs.name }}-musl ; DPKG_CONFLICTS=${{ needs.crate_metadata.outputs.name }} ;; esac;
|
||||
DPKG_VERSION=${{ needs.crate_metadata.outputs.version }}
|
||||
DPKG_BASENAME=${PROJECT_NAME}
|
||||
DPKG_CONFLICTS=${PROJECT_NAME}-musl
|
||||
case ${{ matrix.job.target }} in *-musl) DPKG_BASENAME=${PROJECT_NAME}-musl ; DPKG_CONFLICTS=${PROJECT_NAME} ;; esac;
|
||||
DPKG_VERSION=${PROJECT_VERSION}
|
||||
|
||||
unset DPKG_ARCH
|
||||
case ${{ matrix.job.target }} in
|
||||
@@ -225,14 +233,14 @@ jobs:
|
||||
esac;
|
||||
|
||||
DPKG_NAME="${DPKG_BASENAME}_${DPKG_VERSION}_${DPKG_ARCH}.deb"
|
||||
echo "DPKG_NAME=${DPKG_NAME}" >> $GITHUB_OUTPUT
|
||||
echo ::set-output name=DPKG_NAME::${DPKG_NAME}
|
||||
|
||||
# Binary
|
||||
install -Dm755 "${{ steps.bin.outputs.BIN_PATH }}" "${DPKG_DIR}/usr/bin/${{ steps.bin.outputs.BIN_NAME }}"
|
||||
install -Dm755 "${{ steps.strip.outputs.BIN_PATH }}" "${DPKG_DIR}/usr/bin/${{ steps.strip.outputs.BIN_NAME }}"
|
||||
|
||||
# Man page
|
||||
install -Dm644 'doc/${{ needs.crate_metadata.outputs.name }}.1' "${DPKG_DIR}/usr/share/man/man1/${{ needs.crate_metadata.outputs.name }}.1"
|
||||
gzip -n --best "${DPKG_DIR}/usr/share/man/man1/${{ needs.crate_metadata.outputs.name }}.1"
|
||||
install -Dm644 "doc/${{ env.PROJECT_NAME }}.1" "${DPKG_DIR}/usr/share/man/man1/${{ env.PROJECT_NAME }}.1"
|
||||
gzip -n --best "${DPKG_DIR}/usr/share/man/man1/${{ env.PROJECT_NAME }}.1"
|
||||
|
||||
# README and LICENSE
|
||||
install -Dm644 "README.md" "${DPKG_DIR}/usr/share/doc/${DPKG_BASENAME}/README.md"
|
||||
@@ -243,12 +251,12 @@ jobs:
|
||||
|
||||
cat > "${DPKG_DIR}/usr/share/doc/${DPKG_BASENAME}/copyright" <<EOF
|
||||
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
||||
Upstream-Name: ${{ needs.crate_metadata.outputs.name }}
|
||||
Source: ${{ needs.crate_metadata.outputs.homepage }}
|
||||
Upstream-Name: ${{ env.PROJECT_NAME }}
|
||||
Source: ${{ env.PROJECT_HOMEPAGE }}
|
||||
|
||||
Files: *
|
||||
Copyright: ${{ needs.crate_metadata.outputs.maintainer }}
|
||||
Copyright: $COPYRIGHT_YEARS ${{ needs.crate_metadata.outputs.maintainer }}
|
||||
Copyright: ${{ env.PROJECT_MAINTAINER }}
|
||||
Copyright: $COPYRIGHT_YEARS ${{ env.PROJECT_MAINTAINER }}
|
||||
License: Apache-2.0 or MIT
|
||||
|
||||
License: Apache-2.0
|
||||
@@ -289,16 +297,16 @@ jobs:
|
||||
Version: ${DPKG_VERSION}
|
||||
Section: utils
|
||||
Priority: optional
|
||||
Maintainer: ${{ needs.crate_metadata.outputs.maintainer }}
|
||||
Homepage: ${{ needs.crate_metadata.outputs.homepage }}
|
||||
Maintainer: ${{ env.PROJECT_MAINTAINER }}
|
||||
Homepage: ${{ env.PROJECT_HOMEPAGE }}
|
||||
Architecture: ${DPKG_ARCH}
|
||||
Provides: ${{ needs.crate_metadata.outputs.name }}
|
||||
Provides: ${{ env.PROJECT_NAME }}
|
||||
Conflicts: ${DPKG_CONFLICTS}
|
||||
Description: A command-line benchmarking tool
|
||||
Description: colorized hex viewer for the terminal.
|
||||
EOF
|
||||
|
||||
DPKG_PATH="${DPKG_STAGING}/${DPKG_NAME}"
|
||||
echo "DPKG_PATH=${DPKG_PATH}" >> $GITHUB_OUTPUT
|
||||
echo ::set-output name=DPKG_PATH::${DPKG_PATH}
|
||||
|
||||
# build dpkg
|
||||
fakeroot dpkg-deb --build "${DPKG_DIR}" "${DPKG_PATH}"
|
||||
@@ -321,7 +329,7 @@ jobs:
|
||||
shell: bash
|
||||
run: |
|
||||
unset IS_RELEASE ; if [[ $GITHUB_REF =~ ^refs/tags/v[0-9].* ]]; then IS_RELEASE='true' ; fi
|
||||
echo "IS_RELEASE=${IS_RELEASE}" >> $GITHUB_OUTPUT
|
||||
echo ::set-output name=IS_RELEASE::${IS_RELEASE}
|
||||
|
||||
- name: Publish archives and packages
|
||||
uses: softprops/action-gh-release@v1
|
||||
|
||||
+2
-51
@@ -1,68 +1,19 @@
|
||||
# v0.13.1
|
||||
|
||||
## Bugfixes
|
||||
|
||||
- Correctly handle discontinuous input (stdin), see #196 and #197 (@sharifhsn)
|
||||
|
||||
# v0.13.0
|
||||
|
||||
## Features
|
||||
|
||||
- Support both little and big Endian dumps using `--endianness={little,big}`, see #189 and #104 (@RinHizakura)
|
||||
# unreleased
|
||||
|
||||
## Changes
|
||||
|
||||
- **Breaking**: Changed the meaning of the short flag `-C` to be consistent with `hexdump -C`. Previously, this would *hide* the character panel, but now `-C` *shows* the character panel, in case it has been previously (e.g. in an `alias`) disabled with `--no-characters`, see #187 (@sharkdp)
|
||||
|
||||
## `hexyl` as a library
|
||||
|
||||
- New `endianness` method for `PrinterBuilder`
|
||||
|
||||
|
||||
# v0.12.0
|
||||
|
||||
## Features
|
||||
|
||||
- Only show one panel by default if the terminal width is not wide enough for two panels, see #182 (@sharkdp)
|
||||
- Respect the `NO_COLOR` environment variable, see #179 (@sharifhsn)
|
||||
|
||||
## Bugfixes
|
||||
|
||||
- Do not fail with an error if `--panels=auto` is used and the output is piped, see #184 (@sharkdp)
|
||||
|
||||
## Changes
|
||||
|
||||
- Breaking: For `xxd`-compatibility reasons, `--group_bytes` has been renamed to `--group-size` (with an `--groupsize` alias), see #121 (@sharkdp)
|
||||
|
||||
## `hexyl` as a library
|
||||
|
||||
- Breaking: `num_group_bytes` has been renamed to `group_size`.
|
||||
|
||||
|
||||
# v0.11.0
|
||||
|
||||
## Features
|
||||
|
||||
- Significantly improved performance, see #173 and #176 (@sharifhsn)
|
||||
- Added variable panels through the `--panels` and `--terminal-width` flags, see [#13](https://github.com/sharkdp/hexyl/issues/13) and [#164](https://github.com/sharkdp/hexyl/pull/164) (@sharifhsn)
|
||||
- Added new `--group-bytes`/`-g` option, see #104 and #170 (@RinHizakura)
|
||||
- Added new `--base B` option (where `B` can be `binary`, `octal`, `decimal` or `hexadecimal`), see #147 and #178 (@sharifhsn)
|
||||
- Show actual zero bytes as `⋄` in the character panel (previously: `0`), in order not to confuse them with ASCII
|
||||
`0` bytes if colors are deactivated. Closes #166 (@sharkdp)
|
||||
|
||||
## `hexyl` as a library
|
||||
|
||||
- Breaking change: `Printer::new` is deprecated as a part of the public API. Alternatively, you can now construct a `Printer` using the `PrinterBuilder` builder API, see [#168](https://github.com/sharkdp/hexyl/pull/168). (@sharifhsn)
|
||||
|
||||
## Other
|
||||
|
||||
- More tests for the squeezing feature, see #177 (@mkatychev)
|
||||
|
||||
## Thank you
|
||||
## Packaging
|
||||
|
||||
Special thanks go to @sharifhsn, not just for the new features,
|
||||
bugfixes and performance improvements. But also for many internal
|
||||
improvements of the code base and other maintenance tasks.
|
||||
|
||||
|
||||
# v0.10.0
|
||||
|
||||
Generated
+211
-279
@@ -1,86 +1,63 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.0.4"
|
||||
version = "0.7.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6748e8def348ed4d14996fa801f4122cd763fff530258cdc03f64b25f89d3a5a"
|
||||
checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.3.2"
|
||||
name = "ansi_term"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163"
|
||||
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"anstyle-parse",
|
||||
"anstyle-query",
|
||||
"anstyle-wincon",
|
||||
"colorchoice",
|
||||
"is-terminal",
|
||||
"utf8parse",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle"
|
||||
version = "1.0.1"
|
||||
version = "1.0.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3a30da5c5f2d5e72842e00bcb57657162cdabef0931f40e2deb9b4140440cecd"
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-parse"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333"
|
||||
dependencies = [
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-query"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b"
|
||||
dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-wincon"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c677ab05e09154296dd37acecd46420c17b9713e8366facafa8fc0885167cf4c"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"windows-sys",
|
||||
]
|
||||
checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78"
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.75"
|
||||
version = "1.0.57"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
|
||||
checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc"
|
||||
|
||||
[[package]]
|
||||
name = "assert_cmd"
|
||||
version = "2.0.12"
|
||||
version = "2.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "88903cb14723e4d4003335bb7f8a14f27691649105346a0f0957466c096adfe6"
|
||||
checksum = "9c5bcfa8749ac45dd12cb11055aeeb6b27a3895560d60d71e3c23bf979e60514"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"bstr",
|
||||
"doc-comment",
|
||||
"predicates",
|
||||
"libc",
|
||||
"predicates 3.1.4",
|
||||
"predicates-core",
|
||||
"predicates-tree",
|
||||
"wait-timeout",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.1.0"
|
||||
@@ -93,17 +70,11 @@ version = "1.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"
|
||||
|
||||
[[package]]
|
||||
name = "bstr"
|
||||
version = "1.6.0"
|
||||
version = "1.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6798148dccfbff0fae41c7574d2fa8f1ef3492fba0face179de5d8d447d67b05"
|
||||
checksum = "63044e1ae8e69f3b5a92c736ca6269b8d12fa7efe39bf34ddb06d102cf0e2cab"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
@@ -112,101 +83,77 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.83"
|
||||
version = "1.0.73"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.3.23"
|
||||
version = "3.2.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "03aef18ddf7d879c15ce20f04826ef8418101c7e528014c3eeea13321047dca3"
|
||||
checksum = "d646c7ade5eb07c4aa20e907a922750df0c448892513714fd3e4acbc7130829f"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.3.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8ce6fffb678c9b80a70b6b6de0aad31df727623a70fd9a842c30cd573e2fa98"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
"atty",
|
||||
"bitflags",
|
||||
"clap_lex",
|
||||
"indexmap",
|
||||
"once_cell",
|
||||
"strsim",
|
||||
"terminal_size",
|
||||
"termcolor",
|
||||
"terminal_size 0.1.17",
|
||||
"textwrap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "0.5.0"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b"
|
||||
|
||||
[[package]]
|
||||
name = "colorchoice"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
|
||||
checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5"
|
||||
dependencies = [
|
||||
"os_str_bytes",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "const_format"
|
||||
version = "0.2.31"
|
||||
version = "0.2.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c990efc7a285731f9a4378d81aff2f0e85a2c8781a05ef0f8baa8dac54d0ff48"
|
||||
checksum = "0936ffe6d0c8d6a51b3b0a73b2acbe925d786f346cf45bfddc8341d79fb7dc8a"
|
||||
dependencies = [
|
||||
"const_format_proc_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "const_format_proc_macros"
|
||||
version = "0.2.31"
|
||||
version = "0.2.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e026b6ce194a874cb9cf32cd5772d1ef9767cc8fcb5765948d74f37a9d8b2bf6"
|
||||
checksum = "ef196d5d972878a48da7decb7686eded338b4858fbabeed513d63a7c98b2b82d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "diff"
|
||||
version = "0.1.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8"
|
||||
|
||||
[[package]]
|
||||
name = "difflib"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8"
|
||||
|
||||
[[package]]
|
||||
name = "doc-comment"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.9.0"
|
||||
version = "1.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
|
||||
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
|
||||
|
||||
[[package]]
|
||||
name = "errno"
|
||||
version = "0.3.2"
|
||||
version = "0.2.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6b30f669a7961ef1631673d2766cc92f52d64f7ef354d4fe0ddfd30ed52f0f4f"
|
||||
checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1"
|
||||
dependencies = [
|
||||
"errno-dragonfly",
|
||||
"libc",
|
||||
"windows-sys",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -229,88 +176,78 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.3.2"
|
||||
name = "hashbrown"
|
||||
version = "0.11.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b"
|
||||
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hexyl"
|
||||
version = "0.14.0"
|
||||
version = "0.10.0"
|
||||
dependencies = [
|
||||
"ansi_term",
|
||||
"anyhow",
|
||||
"assert_cmd",
|
||||
"atty",
|
||||
"clap",
|
||||
"const_format",
|
||||
"libc",
|
||||
"owo-colors",
|
||||
"predicates",
|
||||
"pretty_assertions",
|
||||
"supports-color",
|
||||
"terminal_size",
|
||||
"predicates 2.1.1",
|
||||
"terminal_size 0.2.1",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0f647032dfaa1f8b6dc29bd3edb7bbef4861b8b8007ebb118d6db284fd59f6ee"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "io-lifetimes"
|
||||
version = "1.0.11"
|
||||
version = "0.7.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"libc",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "is-terminal"
|
||||
version = "0.4.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"rustix 0.38.8",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "is_ci"
|
||||
version = "1.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "616cde7c720bb2bb5824a224687d8f77bfd38922027f01d825cd7453be5099fb"
|
||||
checksum = "24c3f4eff5495aee4c0399d7b6a0dc2b6e81be84242ffbfcf253ebacccc1d0cb"
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.10.5"
|
||||
version = "0.10.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
|
||||
checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.147"
|
||||
version = "0.2.182"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
|
||||
checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112"
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.3.8"
|
||||
version = "0.0.46"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519"
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.4.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57bcfdad1b858c2db7c38303a6d2ad4dfaf5eb53dfeb0910128b2c26d6158503"
|
||||
checksum = "d4d2456c373231a208ad294c33dc5bff30051eafd954cd4caae83a712b12854d"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.5.0"
|
||||
version = "2.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
|
||||
|
||||
[[package]]
|
||||
name = "normalize-line-endings"
|
||||
@@ -320,32 +257,31 @@ checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be"
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.16"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2"
|
||||
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.18.0"
|
||||
version = "1.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
|
||||
checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1"
|
||||
|
||||
[[package]]
|
||||
name = "owo-colors"
|
||||
version = "3.5.0"
|
||||
name = "os_str_bytes"
|
||||
version = "6.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
|
||||
checksum = "029d8d0b2f198229de29dca79676f2738ff952edf3fde542eb8bf94d8c21b435"
|
||||
|
||||
[[package]]
|
||||
name = "predicates"
|
||||
version = "3.0.3"
|
||||
version = "2.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09963355b9f467184c04017ced4a2ba2d75cbcb4e7462690d388233253d4b1a9"
|
||||
checksum = "a5aab5be6e4732b473071984b3164dbbfb7a3674d30ea5ff44410b6bcd960c3c"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"difflib",
|
||||
"float-cmp",
|
||||
"itertools",
|
||||
@@ -355,102 +291,84 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "predicates-core"
|
||||
version = "1.0.6"
|
||||
name = "predicates"
|
||||
version = "3.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b794032607612e7abeb4db69adb4e33590fa6cf1149e95fd7cb00e634b92f174"
|
||||
checksum = "ada8f2932f28a27ee7b70dd6c1c39ea0675c55a36879ab92f3a715eaa1e63cfe"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"difflib",
|
||||
"predicates-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "predicates-core"
|
||||
version = "1.0.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cad38746f3166b4031b1a0d39ad9f954dd291e7854fcc0eed52ee41a0b50d144"
|
||||
|
||||
[[package]]
|
||||
name = "predicates-tree"
|
||||
version = "1.0.9"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "368ba315fb8c5052ab692e68a0eefec6ec57b23a36959c14496f0b0df2c0cecf"
|
||||
checksum = "4d86de6de25020a36c6d3643a86d9a6a9f552107c0559c60ea03551b5e16c032"
|
||||
dependencies = [
|
||||
"predicates-core",
|
||||
"termtree",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pretty_assertions"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af7cee1a6c8a5b9208b3cb1061f10c0cb689087b3d8ce85fb9d2dd7a29b6ba66"
|
||||
dependencies = [
|
||||
"diff",
|
||||
"yansi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.66"
|
||||
version = "1.0.39"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9"
|
||||
checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.33"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
|
||||
checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.9.3"
|
||||
version = "1.5.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "81bc1d4caf89fac26a70747fe603c130093b53c773888797a6329091246d651a"
|
||||
checksum = "d83f127d94bdbcda4c8cc2e50f6f84f4b611f69c902699ca385a39c3a75f9ff1"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.3.6"
|
||||
version = "0.4.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fed1ceff11a1dddaee50c9dc8e4938bd106e9d89ae372f192311e7da498e3b69"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f"
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.7.4"
|
||||
version = "0.6.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2"
|
||||
checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64"
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "0.37.23"
|
||||
version = "0.35.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4d69718bf81c6127a49dc64e44a742e8bb9213c0ff8869a22c308f84c1d4ab06"
|
||||
checksum = "d51cc38aa10f6bbb377ed28197aa052aa4e2b762c22be9d3153d01822587e787"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"bitflags",
|
||||
"errno",
|
||||
"io-lifetimes",
|
||||
"libc",
|
||||
"linux-raw-sys 0.3.8",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "0.38.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "19ed4fa021d81c8392ce04db050a3da9a60299050b7ae1cf482d862b54a7218f"
|
||||
dependencies = [
|
||||
"bitflags 2.4.0",
|
||||
"errno",
|
||||
"libc",
|
||||
"linux-raw-sys 0.4.5",
|
||||
"linux-raw-sys",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
@@ -466,21 +384,11 @@ version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||
|
||||
[[package]]
|
||||
name = "supports-color"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4950e7174bffabe99455511c39707310e7e9b440364a2fcb1cc21521be57b354"
|
||||
dependencies = [
|
||||
"is-terminal",
|
||||
"is_ci",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.29"
|
||||
version = "1.0.95"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c324c494eba9d92503e6f1ef2e6df781e78f6a7705a0202d9801b198807d518a"
|
||||
checksum = "fbaf6116ab8924f39d52792136fb74fd60a80194cf1b1c6ffa6453eef1c3f942"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -488,35 +396,63 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "terminal_size"
|
||||
version = "0.2.6"
|
||||
name = "termcolor"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e6bf6f19e9f8ed8d4048dc22981458ebcf406d67e94cd422e5ecd73d63b3237"
|
||||
checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
|
||||
dependencies = [
|
||||
"rustix 0.37.23",
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "terminal_size"
|
||||
version = "0.1.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "terminal_size"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8440c860cf79def6164e4a0a983bcc2305d82419177a0e0c71930d049e3ac5a1"
|
||||
dependencies = [
|
||||
"rustix",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termtree"
|
||||
version = "0.4.1"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76"
|
||||
checksum = "507e9898683b6c43a9aa55b64259b721b52ba226e0f3779137e50ad114a4c90b"
|
||||
|
||||
[[package]]
|
||||
name = "textwrap"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb"
|
||||
dependencies = [
|
||||
"terminal_size 0.1.17",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.47"
|
||||
version = "1.0.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "97a802ec30afc17eee47b2855fc72e0c4cd62be9b4efe6591edde0ec5bd68d8f"
|
||||
checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.47"
|
||||
version = "1.0.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6bb623b56e39ab7dcd4b1b98bb6c8f8d907ed255b18de254088016b27a8ee19b"
|
||||
checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -525,21 +461,15 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.11"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c"
|
||||
checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.4"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
|
||||
|
||||
[[package]]
|
||||
name = "utf8parse"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
|
||||
checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04"
|
||||
|
||||
[[package]]
|
||||
name = "wait-timeout"
|
||||
@@ -551,73 +481,75 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.48.0"
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
|
||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
"winapi-i686-pc-windows-gnu",
|
||||
"winapi-x86_64-pc-windows-gnu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.48.5"
|
||||
name = "winapi-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-util"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.36.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
"windows_i686_msvc",
|
||||
"windows_x86_64_gnu",
|
||||
"windows_x86_64_gnullvm",
|
||||
"windows_x86_64_msvc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.48.5"
|
||||
version = "0.36.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
|
||||
checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.48.5"
|
||||
version = "0.36.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
|
||||
checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.48.5"
|
||||
version = "0.36.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
|
||||
checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.48.5"
|
||||
version = "0.36.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
|
||||
checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.48.5"
|
||||
version = "0.36.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
|
||||
|
||||
[[package]]
|
||||
name = "yansi"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec"
|
||||
checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680"
|
||||
+7
-9
@@ -7,28 +7,26 @@ license = "MIT/Apache-2.0"
|
||||
name = "hexyl"
|
||||
readme = "README.md"
|
||||
repository = "https://github.com/sharkdp/hexyl"
|
||||
version = "0.14.0"
|
||||
version = "0.10.0"
|
||||
edition = "2021"
|
||||
rust-version = "1.66"
|
||||
|
||||
[dependencies]
|
||||
ansi_term = "0.12"
|
||||
anyhow = "1.0"
|
||||
atty = "0.2"
|
||||
const_format = "0.2"
|
||||
libc = "0.2"
|
||||
owo-colors = "3"
|
||||
supports-color = "2"
|
||||
thiserror = "1.0"
|
||||
terminal_size = "0.2"
|
||||
|
||||
[dependencies.clap]
|
||||
version = "4"
|
||||
version = "3"
|
||||
default-features = false
|
||||
features = ["std", "suggestions", "color", "wrap_help", "cargo", "help", "usage", "error-context"]
|
||||
features = ["std", "suggestions", "color", "wrap_help", "cargo"]
|
||||
|
||||
[dev-dependencies]
|
||||
assert_cmd = "2.0"
|
||||
predicates = "3.0"
|
||||
pretty_assertions = "1.3.0"
|
||||
assert_cmd = "2.1"
|
||||
predicates = "2.0"
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
|
||||
@@ -17,20 +17,6 @@ of bytes (NULL bytes, printable ASCII characters, ASCII whitespace characters, o
|
||||
|
||||

|
||||
|
||||
## Color Reference
|
||||
|
||||
|Type of Byte|Color|ANSI Code |
|
||||
|---|---|---|
|
||||
|NULL| Bright Black|90|
|
||||
|OFFSET| Bright Black|90|
|
||||
|ASCII Printable| Cyan|36|
|
||||
|ASCII Whitespace| Green|32|
|
||||
|ASCII Other| Green|32|
|
||||
|Non-ASCII| Yellow|33|
|
||||
|
||||
*Colors taken from the Ubuntu terminal color scheme, they could look different in your terminal*
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
### On Ubuntu
|
||||
@@ -45,7 +31,7 @@ If you use an older version of Ubuntu, you can download
|
||||
the latest `.deb` package from the release page and install it via:
|
||||
|
||||
``` bash
|
||||
sudo dpkg -i hexyl_0.13.1_amd64.deb # adapt version number and architecture
|
||||
sudo dpkg -i hexyl_0.10.0_amd64.deb # adapt version number and architecture
|
||||
```
|
||||
|
||||
### On Debian
|
||||
@@ -68,7 +54,7 @@ sudo dnf install hexyl
|
||||
|
||||
### On Arch Linux
|
||||
|
||||
You can install `hexyl` from [the official package repository](https://archlinux.org/packages/extra/x86_64/hexyl/):
|
||||
You can install `hexyl` from [the official package repository](https://www.archlinux.org/packages/community/x86_64/hexyl/):
|
||||
|
||||
```
|
||||
pacman -S hexyl
|
||||
@@ -110,18 +96,6 @@ sudo port install hexyl
|
||||
pkg install hexyl
|
||||
```
|
||||
|
||||
### On NetBSD
|
||||
|
||||
```
|
||||
pkgin install hexyl
|
||||
```
|
||||
|
||||
### On OpenBSD
|
||||
|
||||
```
|
||||
doas pkg_add hexyl
|
||||
```
|
||||
|
||||
### on Termux
|
||||
```
|
||||
pkg install hexyl
|
||||
|
||||
+7
-2
@@ -1,6 +1,11 @@
|
||||
% HEXYL(1) hexyl 0.12.0 | General Commands Manual
|
||||
% HEXYL(1) hexyl 0.10.0 | General Commands Manual
|
||||
%
|
||||
% 2022-12-05
|
||||
% 2022-03-23
|
||||
|
||||
<!--
|
||||
This man page is written in Pandoc's Markdown.
|
||||
See: https://pandoc.org/MANUAL.html#pandocs-markdown
|
||||
-->
|
||||
|
||||
# NAME
|
||||
|
||||
|
||||
+17
-10
@@ -1,6 +1,6 @@
|
||||
use std::io;
|
||||
|
||||
use hexyl::{BorderStyle, PrinterBuilder};
|
||||
use hexyl::{BorderStyle, Printer};
|
||||
|
||||
fn main() {
|
||||
let input = vec![
|
||||
@@ -11,14 +11,21 @@ fn main() {
|
||||
let stdout = io::stdout();
|
||||
let mut handle = stdout.lock();
|
||||
|
||||
let mut printer = PrinterBuilder::new(&mut handle)
|
||||
.show_color(true)
|
||||
.show_char_panel(true)
|
||||
.show_position_panel(true)
|
||||
.with_border_style(BorderStyle::Unicode)
|
||||
.enable_squeezing(false)
|
||||
.num_panels(2)
|
||||
.group_size(1)
|
||||
.build();
|
||||
let show_color = true;
|
||||
let show_char_panel = true;
|
||||
let show_position_panel = true;
|
||||
let use_squeezing = false;
|
||||
let border_style = BorderStyle::Unicode;
|
||||
let columns = 2;
|
||||
|
||||
let mut printer = Printer::new(
|
||||
&mut handle,
|
||||
show_color,
|
||||
show_char_panel,
|
||||
show_position_panel,
|
||||
border_style,
|
||||
use_squeezing,
|
||||
columns,
|
||||
);
|
||||
printer.print_all(&input[..]).unwrap();
|
||||
}
|
||||
+268
-275
@@ -3,13 +3,14 @@ extern crate clap;
|
||||
|
||||
use std::convert::TryFrom;
|
||||
use std::fs::File;
|
||||
use std::io::{self, prelude::*, BufWriter, SeekFrom};
|
||||
use std::num::{NonZeroI64, NonZeroU64, NonZeroU8};
|
||||
use std::io::{self, prelude::*, SeekFrom};
|
||||
use std::num::{NonZeroI64, NonZeroU16};
|
||||
|
||||
use clap::builder::ArgPredicate;
|
||||
use clap::{crate_name, crate_version, Arg, ArgAction, ColorChoice, Command};
|
||||
use clap::{crate_name, crate_version, AppSettings, Arg, ColorChoice, Command};
|
||||
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use atty::Stream;
|
||||
|
||||
use anyhow::{anyhow, Context, Error as AnyhowError};
|
||||
|
||||
use const_format::formatcp;
|
||||
|
||||
@@ -17,15 +18,13 @@ use thiserror::Error as ThisError;
|
||||
|
||||
use terminal_size::terminal_size;
|
||||
|
||||
use hexyl::{Base, BorderStyle, CharacterTable, Endianness, Input, PrinterBuilder};
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
use hexyl::{BorderStyle, Input, Printer};
|
||||
|
||||
const DEFAULT_BLOCK_SIZE: i64 = 512;
|
||||
|
||||
fn run() -> Result<()> {
|
||||
fn run() -> Result<(), AnyhowError> {
|
||||
let command = Command::new(crate_name!())
|
||||
.setting(AppSettings::DeriveDisplayOrder)
|
||||
.color(ColorChoice::Auto)
|
||||
.max_term_width(90)
|
||||
.version(crate_version!())
|
||||
@@ -38,7 +37,7 @@ fn run() -> Result<()> {
|
||||
Arg::new("length")
|
||||
.short('n')
|
||||
.long("length")
|
||||
.num_args(1)
|
||||
.takes_value(true)
|
||||
.value_name("N")
|
||||
.help(
|
||||
"Only read N bytes from the input. The N argument can also include a \
|
||||
@@ -52,7 +51,7 @@ fn run() -> Result<()> {
|
||||
Arg::new("bytes")
|
||||
.short('c')
|
||||
.long("bytes")
|
||||
.num_args(1)
|
||||
.takes_value(true)
|
||||
.value_name("N")
|
||||
.conflicts_with("length")
|
||||
.help("An alias for -n/--length"),
|
||||
@@ -60,9 +59,9 @@ fn run() -> Result<()> {
|
||||
.arg(
|
||||
Arg::new("count")
|
||||
.short('l')
|
||||
.num_args(1)
|
||||
.takes_value(true)
|
||||
.value_name("N")
|
||||
.conflicts_with_all(["length", "bytes"])
|
||||
.conflicts_with_all(&["length", "bytes"])
|
||||
.hide(true)
|
||||
.help("Yet another alias for -n/--length"),
|
||||
)
|
||||
@@ -70,7 +69,7 @@ fn run() -> Result<()> {
|
||||
Arg::new("skip")
|
||||
.short('s')
|
||||
.long("skip")
|
||||
.num_args(1)
|
||||
.takes_value(true)
|
||||
.value_name("N")
|
||||
.help(
|
||||
"Skip the first N bytes of the input. The N argument can also include \
|
||||
@@ -81,7 +80,7 @@ fn run() -> Result<()> {
|
||||
.arg(
|
||||
Arg::new("block_size")
|
||||
.long("block-size")
|
||||
.num_args(1)
|
||||
.takes_value(true)
|
||||
.value_name("SIZE")
|
||||
.help(formatcp!(
|
||||
"Sets the size of the `block` unit to SIZE (default is {}).\n\
|
||||
@@ -93,7 +92,6 @@ fn run() -> Result<()> {
|
||||
Arg::new("nosqueezing")
|
||||
.short('v')
|
||||
.long("no-squeezing")
|
||||
.action(ArgAction::SetFalse)
|
||||
.help(
|
||||
"Displays all input data. Otherwise any number of groups of output \
|
||||
lines which would be identical to the preceding group of lines, are \
|
||||
@@ -103,74 +101,49 @@ fn run() -> Result<()> {
|
||||
.arg(
|
||||
Arg::new("color")
|
||||
.long("color")
|
||||
.num_args(1)
|
||||
.takes_value(true)
|
||||
.value_name("WHEN")
|
||||
.value_parser(["always", "auto", "never", "force"])
|
||||
.default_value_if("plain", ArgPredicate::IsPresent, Some("never"))
|
||||
.possible_values(&["always", "auto", "never"])
|
||||
.default_value_if("plain", None, Some("never"))
|
||||
.default_value("always")
|
||||
.help(
|
||||
"When to use colors. The 'auto' mode only displays colors if the output \
|
||||
goes to an interactive terminal. 'force' can be used to override the \
|
||||
NO_COLOR environment variable.",
|
||||
"When to use colors. The auto-mode only displays colors if the output \
|
||||
goes to an interactive terminal",
|
||||
),
|
||||
)
|
||||
.arg(Arg::new("plain").short('p').long("plain").help(
|
||||
"Display output with --no-characters, --no-position, --border=none, and --color=never.",
|
||||
))
|
||||
.arg(
|
||||
Arg::new("border")
|
||||
.long("border")
|
||||
.num_args(1)
|
||||
.takes_value(true)
|
||||
.value_name("STYLE")
|
||||
.value_parser(["unicode", "ascii", "none"])
|
||||
.default_value_if("plain", ArgPredicate::IsPresent, Some("none"))
|
||||
.possible_values(&["unicode", "ascii", "none"])
|
||||
.default_value_if("plain", None, Some("none"))
|
||||
.default_value("unicode")
|
||||
.help(
|
||||
"Whether to draw a border with Unicode characters, ASCII characters, \
|
||||
or none at all",
|
||||
),
|
||||
)
|
||||
.arg(Arg::new("plain").short('p').long("plain").action(ArgAction::SetTrue).help(
|
||||
"Display output with --no-characters, --no-position, --border=none, and --color=never.",
|
||||
))
|
||||
.arg(
|
||||
Arg::new("no_chars")
|
||||
.long("no-characters")
|
||||
.action(ArgAction::SetFalse)
|
||||
.help("Do not show the character panel on the right."),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("chars")
|
||||
.short('C')
|
||||
.long("characters")
|
||||
.overrides_with("no_chars")
|
||||
.action(ArgAction::SetTrue)
|
||||
.help("Show the character panel on the right. This is the default, unless --no-characters has been specified."),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("character-table")
|
||||
.long("character-table")
|
||||
.value_name("FORMAT")
|
||||
.value_parser(["default", "ascii", "codepage-437"])
|
||||
.default_value("default")
|
||||
.help(
|
||||
"Defines how bytes are mapped to characters:\n \
|
||||
\"default\": show printable ASCII characters as-is, '⋄' for NULL bytes, \
|
||||
' ' for space, '_' for other ASCII whitespace, \
|
||||
'•' for other ASCII characters, and '×' for non-ASCII bytes.\n \
|
||||
\"ascii\": show printable ASCII as-is, ' ' for space, '.' for everything else.\n \
|
||||
\"codepage-437\": uses code page 437 (for non-ASCII bytes).\n"
|
||||
),
|
||||
.long("no-characters")
|
||||
.help("Whether to display the character panel on the right."),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("no_position")
|
||||
.short('P')
|
||||
.long("no-position")
|
||||
.action(ArgAction::SetFalse)
|
||||
.help("Whether to display the position panel on the left."),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("display_offset")
|
||||
.short('o')
|
||||
.long("display-offset")
|
||||
.num_args(1)
|
||||
.takes_value(true)
|
||||
.value_name("N")
|
||||
.help(
|
||||
"Add N bytes to the displayed file position. The N argument can also \
|
||||
@@ -180,92 +153,53 @@ fn run() -> Result<()> {
|
||||
),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("panels")
|
||||
.long("panels")
|
||||
.num_args(1)
|
||||
Arg::new("columns")
|
||||
.short('w')
|
||||
.long("columns")
|
||||
.takes_value(true)
|
||||
.value_name("N")
|
||||
.help(
|
||||
"Sets the number of hex data panels to be displayed. \
|
||||
`--panels=auto` will display the maximum number of hex data panels \
|
||||
based on the current terminal width. By default, hexyl will show \
|
||||
two panels, unless the terminal is not wide enough for that.",
|
||||
"Sets the number of hex data columns to be displayed. \
|
||||
Cannot be used with other width-setting options.",
|
||||
),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("group_size")
|
||||
.short('g')
|
||||
.long("group-size")
|
||||
.alias("groupsize")
|
||||
.num_args(1)
|
||||
.value_name("N")
|
||||
.help(
|
||||
"Number of bytes/octets that should be grouped together. \
|
||||
Possible group sizes are 1, 2, 4, 8. The default is 1. You \
|
||||
can use the '--endianness' option to control the ordering of \
|
||||
the bytes within a group. '--groupsize' can be used as an \
|
||||
alias (xxd-compatibility).",
|
||||
),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("endianness")
|
||||
.long("endianness")
|
||||
.num_args(1)
|
||||
.value_name("FORMAT")
|
||||
.value_parser(["big", "little"])
|
||||
.default_value("big")
|
||||
.help(
|
||||
"Whether to print out groups in little-endian or big-endian \
|
||||
format. This option only has an effect if the '--group-size' \
|
||||
is larger than 1. '-e' can be used as an alias for \
|
||||
'--endianness=little'.",
|
||||
),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("little_endian_format")
|
||||
.short('e')
|
||||
.action(ArgAction::SetTrue)
|
||||
.overrides_with("endianness")
|
||||
.hide(true)
|
||||
.help("An alias for '--endianness=little'."),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("base")
|
||||
.short('b')
|
||||
.long("base")
|
||||
.num_args(1)
|
||||
.value_name("B")
|
||||
.help(
|
||||
"Sets the base used for the bytes. The possible options are \
|
||||
binary, octal, decimal, and hexadecimal. The default base \
|
||||
is hexadecimal."
|
||||
)
|
||||
)
|
||||
.arg(
|
||||
Arg::new("terminal_width")
|
||||
.short('t')
|
||||
.long("terminal-width")
|
||||
.num_args(1)
|
||||
.takes_value(true)
|
||||
.value_name("N")
|
||||
.conflicts_with("panels")
|
||||
.conflicts_with("columns")
|
||||
.help(
|
||||
"Sets the number of terminal columns to be displayed.\nSince the terminal \
|
||||
width may not be an evenly divisible by the width per hex data column, this \
|
||||
will use the greatest number of hex data panels that can fit in the requested \
|
||||
will use the greatest number of hex data columns that can fit in the requested \
|
||||
width but still leave some space to the right.\nCannot be used with other \
|
||||
width-setting options.",
|
||||
),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("auto_width")
|
||||
.short('a')
|
||||
.long("auto-width")
|
||||
.conflicts_with_all(&["columns", "terminal_width"])
|
||||
.help(
|
||||
"Sets the number of hex data columns to be adjusted according to the \
|
||||
detected terminal width.\nCannot be used with other width-setting options.",
|
||||
),
|
||||
);
|
||||
|
||||
let matches = command.get_matches();
|
||||
|
||||
let stdin = io::stdin();
|
||||
|
||||
let mut reader = match matches.get_one::<String>("FILE") {
|
||||
let mut reader = match matches.value_of("FILE") {
|
||||
Some(filename) => Input::File(File::open(filename)?),
|
||||
None => Input::Stdin(stdin.lock()),
|
||||
};
|
||||
|
||||
let block_size = matches
|
||||
.get_one::<String>("block_size")
|
||||
.value_of("block_size")
|
||||
.map(|bs| {
|
||||
if let Some(hex_number) = try_parse_as_hex_number(bs) {
|
||||
return hex_number.map_err(|e| anyhow!(e)).and_then(|x| {
|
||||
@@ -290,7 +224,7 @@ fn run() -> Result<()> {
|
||||
.unwrap_or_else(|| PositiveI64::new(DEFAULT_BLOCK_SIZE).unwrap());
|
||||
|
||||
let skip_arg = matches
|
||||
.get_one::<String>("skip")
|
||||
.value_of("skip")
|
||||
.map(|s| {
|
||||
parse_byte_offset(s, block_size).context(anyhow!(
|
||||
"failed to parse `--skip` arg {:?} as byte count",
|
||||
@@ -319,16 +253,16 @@ fn run() -> Result<()> {
|
||||
0
|
||||
};
|
||||
|
||||
let parse_byte_count = |s| -> Result<u64> {
|
||||
let parse_byte_count = |s| -> Result<u64, AnyhowError> {
|
||||
Ok(parse_byte_offset(s, block_size)?
|
||||
.assume_forward_offset_from_start()?
|
||||
.into())
|
||||
};
|
||||
|
||||
let mut reader = if let Some(length) = matches
|
||||
.get_one::<String>("length")
|
||||
.or_else(|| matches.get_one::<String>("bytes"))
|
||||
.or_else(|| matches.get_one::<String>("count"))
|
||||
.value_of("length")
|
||||
.or_else(|| matches.value_of("bytes"))
|
||||
.or_else(|| matches.value_of("count"))
|
||||
.map(|s| {
|
||||
parse_byte_count(s).context(anyhow!(
|
||||
"failed to parse `--length` arg {:?} as byte count",
|
||||
@@ -342,38 +276,26 @@ fn run() -> Result<()> {
|
||||
reader.into_inner()
|
||||
};
|
||||
|
||||
let no_color = std::env::var_os("NO_COLOR").is_some();
|
||||
let show_color = match matches.get_one::<String>("color").map(String::as_ref) {
|
||||
let show_color = match matches.value_of("color") {
|
||||
Some("never") => false,
|
||||
Some("always") => !no_color,
|
||||
Some("force") => true,
|
||||
_ => {
|
||||
if no_color {
|
||||
false
|
||||
} else {
|
||||
supports_color::on(supports_color::Stream::Stdout)
|
||||
.map(|level| level.has_basic)
|
||||
.unwrap_or(false)
|
||||
}
|
||||
}
|
||||
Some("auto") => atty::is(Stream::Stdout),
|
||||
_ => true,
|
||||
};
|
||||
|
||||
let border_style = match matches.get_one::<String>("border").map(String::as_ref) {
|
||||
let border_style = match matches.value_of("border") {
|
||||
Some("unicode") => BorderStyle::Unicode,
|
||||
Some("ascii") => BorderStyle::Ascii,
|
||||
_ => BorderStyle::None,
|
||||
};
|
||||
|
||||
let &squeeze = matches.get_one::<bool>("nosqueezing").unwrap_or(&true);
|
||||
let squeeze = !matches.is_present("nosqueezing");
|
||||
|
||||
let show_char_panel = *matches.get_one::<bool>("no_chars").unwrap_or(&true)
|
||||
&& !matches.get_one::<bool>("plain").unwrap_or(&false);
|
||||
let show_char_panel = !matches.is_present("no_chars") && !matches.is_present("plain");
|
||||
|
||||
let show_position_panel = *matches.get_one::<bool>("no_position").unwrap_or(&true)
|
||||
&& !matches.get_one::<bool>("plain").unwrap_or(&false);
|
||||
let show_position_panel = !matches.is_present("no_position") && !matches.is_present("plain");
|
||||
|
||||
let display_offset: u64 = matches
|
||||
.get_one::<String>("display_offset")
|
||||
.value_of("display_offset")
|
||||
.map(|s| {
|
||||
parse_byte_count(s).context(anyhow!(
|
||||
"failed to parse `--display-offset` arg {:?} as byte count",
|
||||
@@ -383,143 +305,60 @@ fn run() -> Result<()> {
|
||||
.transpose()?
|
||||
.unwrap_or(0);
|
||||
|
||||
let max_panels_fn = |terminal_width: u64, base_digits: u64, group_size: u64| {
|
||||
let offset = if show_position_panel { 10 } else { 1 };
|
||||
let col_width = if show_char_panel {
|
||||
((8 / group_size) * (base_digits * group_size + 1)) + 2 + 8
|
||||
let columns = if let Some(columns) = matches
|
||||
.value_of("columns")
|
||||
.map(|s| {
|
||||
s.parse::<NonZeroU16>().map(u16::from).context(anyhow!(
|
||||
"failed to parse `--columns` arg {:?} as unsigned nonzero integer",
|
||||
s
|
||||
))
|
||||
})
|
||||
.transpose()?
|
||||
{
|
||||
columns
|
||||
} else {
|
||||
let terminal_width = if let Some(terminal_width) = matches
|
||||
.value_of("terminal_width")
|
||||
.map(|s| {
|
||||
s.parse::<NonZeroU16>().map(u16::from).context(anyhow!(
|
||||
"failed to parse `--columns` arg {:?} as unsigned nonzero integer",
|
||||
s
|
||||
))
|
||||
})
|
||||
.transpose()?
|
||||
{
|
||||
Some(terminal_width)
|
||||
} else if matches.is_present("auto_width") {
|
||||
Some(terminal_size().ok_or_else(|| anyhow!("not a TTY"))?.0 .0)
|
||||
} else {
|
||||
((8 / group_size) * (base_digits * group_size + 1)) + 2
|
||||
None
|
||||
};
|
||||
if (terminal_width - offset) / col_width < 1 {
|
||||
1
|
||||
} else {
|
||||
(terminal_width - offset) / col_width
|
||||
}
|
||||
};
|
||||
|
||||
let base = if let Some(base) = matches.get_one::<String>("base")
|
||||
.map(|s| {
|
||||
if let Ok(base_num) = s.parse::<u8>() {
|
||||
match base_num {
|
||||
2 => Ok(Base::Binary),
|
||||
8 => Ok(Base::Octal),
|
||||
10 => Ok(Base::Decimal),
|
||||
16 => Ok(Base::Hexadecimal),
|
||||
_ => Err(anyhow!("The number provided is not a valid base. Valid bases are 2, 8, 10, and 16.")),
|
||||
if let Some(terminal_width) = terminal_width {
|
||||
let offset = if show_position_panel { 10 } else { 1 };
|
||||
let col_width = if show_char_panel { 35 } else { 26 };
|
||||
if (terminal_width - offset) / col_width < 1 {
|
||||
1
|
||||
} else {
|
||||
(terminal_width - offset) / col_width
|
||||
}
|
||||
} else {
|
||||
match s.as_str() {
|
||||
"b" | "bin" | "binary" => Ok(Base::Binary),
|
||||
"o" | "oct" | "octal" => Ok(Base::Octal),
|
||||
"d" | "dec" | "decimal" => Ok(Base::Decimal),
|
||||
"x" | "hex" | "hexadecimal" => Ok(Base::Hexadecimal),
|
||||
_ => Err(anyhow!("The base provided is not valid. Valid bases are \"b\", \"o\", \"d\", and \"x\"."))
|
||||
}
|
||||
2
|
||||
}
|
||||
}).transpose()? {
|
||||
base
|
||||
} else {
|
||||
Base::Hexadecimal
|
||||
};
|
||||
|
||||
let base_digits = match base {
|
||||
Base::Binary => 8,
|
||||
Base::Octal => 3,
|
||||
Base::Decimal => 3,
|
||||
Base::Hexadecimal => 2,
|
||||
};
|
||||
|
||||
let group_size = if let Some(group_size) = matches
|
||||
.get_one::<String>("group_size")
|
||||
.map(|s| {
|
||||
s.parse::<NonZeroU8>().map(u8::from).context(anyhow!(
|
||||
"Failed to parse `--group-size`/`-g` argument {:?} as unsigned nonzero integer",
|
||||
s
|
||||
))
|
||||
})
|
||||
.transpose()?
|
||||
{
|
||||
if (group_size <= 8) && ((group_size & (group_size - 1)) == 0) {
|
||||
group_size
|
||||
} else {
|
||||
return Err(anyhow!(
|
||||
"Possible sizes for the `--group-size`/`-g` option are 1, 2, 4 or 8. "
|
||||
));
|
||||
}
|
||||
} else {
|
||||
1
|
||||
};
|
||||
|
||||
let terminal_width = terminal_size().map(|s| s.0 .0 as u64).unwrap_or(80);
|
||||
|
||||
let panels = if matches.get_one::<String>("panels").map(String::as_ref) == Some("auto") {
|
||||
max_panels_fn(terminal_width, base_digits, group_size.into())
|
||||
} else if let Some(panels) = matches
|
||||
.get_one::<String>("panels")
|
||||
.map(|s| {
|
||||
s.parse::<NonZeroU64>().map(u64::from).context(anyhow!(
|
||||
"failed to parse `--panels` arg {:?} as unsigned nonzero integer",
|
||||
s
|
||||
))
|
||||
})
|
||||
.transpose()?
|
||||
{
|
||||
panels
|
||||
} else if let Some(terminal_width) = matches
|
||||
.get_one::<String>("terminal_width")
|
||||
.map(|s| {
|
||||
s.parse::<NonZeroU64>().map(u64::from).context(anyhow!(
|
||||
"failed to parse `--terminal-width` arg {:?} as unsigned nonzero integer",
|
||||
s
|
||||
))
|
||||
})
|
||||
.transpose()?
|
||||
{
|
||||
max_panels_fn(terminal_width, base_digits, group_size.into())
|
||||
} else {
|
||||
std::cmp::min(
|
||||
2,
|
||||
max_panels_fn(terminal_width, base_digits, group_size.into()),
|
||||
)
|
||||
};
|
||||
|
||||
let little_endian_format = *matches.get_one::<bool>("little_endian_format").unwrap();
|
||||
let endianness = matches.get_one::<String>("endianness");
|
||||
let endianness = match (
|
||||
endianness.map(|s| s.as_ref()).unwrap(),
|
||||
little_endian_format,
|
||||
) {
|
||||
(_, true) | ("little", _) => Endianness::Little,
|
||||
("big", _) => Endianness::Big,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
let character_table = match matches
|
||||
.get_one::<String>("character-table")
|
||||
.unwrap()
|
||||
.as_ref()
|
||||
{
|
||||
"default" => CharacterTable::Default,
|
||||
"ascii" => CharacterTable::Ascii,
|
||||
"codepage-437" => CharacterTable::CP437,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
let stdout = io::stdout();
|
||||
let mut stdout_lock = BufWriter::new(stdout.lock());
|
||||
let mut stdout_lock = stdout.lock();
|
||||
|
||||
let mut printer = PrinterBuilder::new(&mut stdout_lock)
|
||||
.show_color(show_color)
|
||||
.show_char_panel(show_char_panel)
|
||||
.show_position_panel(show_position_panel)
|
||||
.with_border_style(border_style)
|
||||
.enable_squeezing(squeeze)
|
||||
.num_panels(panels)
|
||||
.group_size(group_size)
|
||||
.with_base(base)
|
||||
.endianness(endianness)
|
||||
.character_table(character_table)
|
||||
.build();
|
||||
let mut printer = Printer::new(
|
||||
&mut stdout_lock,
|
||||
show_color,
|
||||
show_char_panel,
|
||||
show_position_panel,
|
||||
border_style,
|
||||
squeeze,
|
||||
columns,
|
||||
);
|
||||
printer.display_offset(skip_offset + display_offset);
|
||||
printer.print_all(&mut reader).map_err(|e| anyhow!(e))?;
|
||||
|
||||
@@ -527,15 +366,14 @@ fn run() -> Result<()> {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Enable ANSI support for Windows
|
||||
#[cfg(windows)]
|
||||
let _ = ansi_term::enable_ansi_support();
|
||||
|
||||
let result = run();
|
||||
|
||||
if let Err(err) = result {
|
||||
if let Some(io_error) = err.downcast_ref::<io::Error>() {
|
||||
if io_error.kind() == ::std::io::ErrorKind::BrokenPipe {
|
||||
std::process::exit(0);
|
||||
}
|
||||
}
|
||||
eprintln!("Error: {err:?}");
|
||||
eprintln!("Error: {:?}", err);
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
@@ -805,3 +643,158 @@ fn try_parse_as_hex_number(n: &str) -> Option<Result<i64, ByteOffsetParseError>>
|
||||
i64::from_str_radix(num, 16).map_err(ParseNum)
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unit_multipliers() {
|
||||
use Unit::*;
|
||||
assert_eq!(Kilobyte.get_multiplier(), 1000 * Byte.get_multiplier());
|
||||
assert_eq!(Megabyte.get_multiplier(), 1000 * Kilobyte.get_multiplier());
|
||||
assert_eq!(Gigabyte.get_multiplier(), 1000 * Megabyte.get_multiplier());
|
||||
assert_eq!(Terabyte.get_multiplier(), 1000 * Gigabyte.get_multiplier());
|
||||
|
||||
assert_eq!(Kibibyte.get_multiplier(), 1024 * Byte.get_multiplier());
|
||||
assert_eq!(Mebibyte.get_multiplier(), 1024 * Kibibyte.get_multiplier());
|
||||
assert_eq!(Gibibyte.get_multiplier(), 1024 * Mebibyte.get_multiplier());
|
||||
assert_eq!(Tebibyte.get_multiplier(), 1024 * Gibibyte.get_multiplier());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_process_sign() {
|
||||
use ByteOffsetKind::*;
|
||||
use ByteOffsetParseError::*;
|
||||
assert_eq!(process_sign_of("123"), Ok(("123", ForwardFromBeginning)));
|
||||
assert_eq!(process_sign_of("+123"), Ok(("123", ForwardFromLastOffset)));
|
||||
assert_eq!(process_sign_of("-123"), Ok(("123", BackwardFromEnd)));
|
||||
assert_eq!(process_sign_of("-"), Err(EmptyAfterSign));
|
||||
assert_eq!(process_sign_of("+"), Err(EmptyAfterSign));
|
||||
assert_eq!(process_sign_of(""), Err(Empty));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_as_hex() {
|
||||
assert_eq!(try_parse_as_hex_number("73"), None);
|
||||
assert_eq!(try_parse_as_hex_number("0x1337"), Some(Ok(0x1337)));
|
||||
assert!(matches!(try_parse_as_hex_number("0xnope"), Some(Err(_))));
|
||||
assert!(matches!(try_parse_as_hex_number("0x-1"), Some(Err(_))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extract_num_and_unit() {
|
||||
use ByteOffsetParseError::*;
|
||||
use Unit::*;
|
||||
// byte is default unit
|
||||
assert_eq!(extract_num_and_unit_from("4"), Ok((4, Byte)));
|
||||
// blocks are returned without customization
|
||||
assert_eq!(
|
||||
extract_num_and_unit_from("2blocks"),
|
||||
Ok((2, Block { custom_size: None }))
|
||||
);
|
||||
// no normalization is performed
|
||||
assert_eq!(extract_num_and_unit_from("1024kb"), Ok((1024, Kilobyte)));
|
||||
|
||||
// unit without number results in error
|
||||
assert_eq!(
|
||||
extract_num_and_unit_from("gib"),
|
||||
Err(EmptyWithUnit("gib".to_string()))
|
||||
);
|
||||
// empty string results in error
|
||||
assert_eq!(extract_num_and_unit_from(""), Err(Empty));
|
||||
// an invalid unit results in an error
|
||||
assert_eq!(
|
||||
extract_num_and_unit_from("25litres"),
|
||||
Err(InvalidUnit("litres".to_string()))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_byte_offset() {
|
||||
use ByteOffsetParseError::*;
|
||||
|
||||
macro_rules! success {
|
||||
($input: expr, $expected_kind: ident $expected_value: expr) => {
|
||||
success!($input, $expected_kind $expected_value; block_size: DEFAULT_BLOCK_SIZE)
|
||||
};
|
||||
($input: expr, $expected_kind: ident $expected_value: expr; block_size: $block_size: expr) => {
|
||||
assert_eq!(
|
||||
parse_byte_offset($input, PositiveI64::new($block_size).unwrap()),
|
||||
Ok(
|
||||
ByteOffset {
|
||||
value: NonNegativeI64::new($expected_value).unwrap(),
|
||||
kind: ByteOffsetKind::$expected_kind,
|
||||
}
|
||||
),
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! error {
|
||||
($input: expr, $expected_err: expr) => {
|
||||
assert_eq!(
|
||||
parse_byte_offset($input, PositiveI64::new(DEFAULT_BLOCK_SIZE).unwrap()),
|
||||
Err($expected_err),
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
success!("0", ForwardFromBeginning 0);
|
||||
success!("1", ForwardFromBeginning 1);
|
||||
success!("1", ForwardFromBeginning 1);
|
||||
success!("100", ForwardFromBeginning 100);
|
||||
success!("+100", ForwardFromLastOffset 100);
|
||||
|
||||
success!("0x0", ForwardFromBeginning 0);
|
||||
success!("0xf", ForwardFromBeginning 15);
|
||||
success!("0xdeadbeef", ForwardFromBeginning 3_735_928_559);
|
||||
|
||||
success!("1KB", ForwardFromBeginning 1000);
|
||||
success!("2MB", ForwardFromBeginning 2000000);
|
||||
success!("3GB", ForwardFromBeginning 3000000000);
|
||||
success!("4TB", ForwardFromBeginning 4000000000000);
|
||||
success!("+4TB", ForwardFromLastOffset 4000000000000);
|
||||
|
||||
success!("1GiB", ForwardFromBeginning 1073741824);
|
||||
success!("2TiB", ForwardFromBeginning 2199023255552);
|
||||
success!("+2TiB", ForwardFromLastOffset 2199023255552);
|
||||
|
||||
success!("0xff", ForwardFromBeginning 255);
|
||||
success!("0xEE", ForwardFromBeginning 238);
|
||||
success!("+0xFF", ForwardFromLastOffset 255);
|
||||
|
||||
success!("1block", ForwardFromBeginning 512; block_size: 512);
|
||||
success!("2block", ForwardFromBeginning 1024; block_size: 512);
|
||||
success!("1block", ForwardFromBeginning 4; block_size: 4);
|
||||
success!("2block", ForwardFromBeginning 8; block_size: 4);
|
||||
|
||||
// empty string is invalid
|
||||
error!("", Empty);
|
||||
// These are also bad.
|
||||
error!("+", EmptyAfterSign);
|
||||
error!("-", EmptyAfterSign);
|
||||
error!("K", InvalidNumAndUnit("K".to_owned()));
|
||||
error!("k", InvalidNumAndUnit("k".to_owned()));
|
||||
error!("m", InvalidNumAndUnit("m".to_owned()));
|
||||
error!("block", EmptyWithUnit("block".to_owned()));
|
||||
// leading/trailing space is invalid
|
||||
error!(" 0", InvalidNumAndUnit(" 0".to_owned()));
|
||||
error!("0 ", InvalidUnit(" ".to_owned()));
|
||||
// Signs after the hex prefix make no sense
|
||||
error!("0x-12", SignFoundAfterHexPrefix('-'));
|
||||
// This was previously accepted but shouldn't be.
|
||||
error!("0x+12", SignFoundAfterHexPrefix('+'));
|
||||
// invalid suffix
|
||||
error!("1234asdf", InvalidUnit("asdf".to_owned()));
|
||||
// bad numbers
|
||||
error!("asdf1234", InvalidNumAndUnit("asdf1234".to_owned()));
|
||||
error!("a1s2d3f4", InvalidNumAndUnit("a1s2d3f4".to_owned()));
|
||||
// multiplication overflows u64
|
||||
error!("20000000TiB", UnitMultiplicationOverflow);
|
||||
|
||||
assert!(
|
||||
match parse_byte_offset("99999999999999999999", PositiveI64::new(512).unwrap()) {
|
||||
// We can't check against the kind of the `ParseIntError`, so we'll just make sure it's the
|
||||
// same as trying to do the parse directly.
|
||||
Err(ParseNum(e)) => e == "99999999999999999999".parse::<i64>().unwrap_err(),
|
||||
_ => false,
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
use owo_colors::{colors, Color};
|
||||
|
||||
pub const COLOR_NULL: &[u8] = colors::BrightBlack::ANSI_FG.as_bytes();
|
||||
pub const COLOR_OFFSET: &[u8] = colors::BrightBlack::ANSI_FG.as_bytes();
|
||||
pub const COLOR_ASCII_PRINTABLE: &[u8] = colors::Cyan::ANSI_FG.as_bytes();
|
||||
pub const COLOR_ASCII_WHITESPACE: &[u8] = colors::Green::ANSI_FG.as_bytes();
|
||||
pub const COLOR_ASCII_OTHER: &[u8] = colors::Green::ANSI_FG.as_bytes();
|
||||
pub const COLOR_NONASCII: &[u8] = colors::Yellow::ANSI_FG.as_bytes();
|
||||
pub const COLOR_RESET: &[u8] = colors::Default::ANSI_FG.as_bytes();
|
||||
|
||||
#[rustfmt::skip]
|
||||
pub const CP437: [char; 256] = [
|
||||
// Copyright (c) 2016, Delan Azabani <delan@azabani.com>
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
//
|
||||
// modified to use the ⋄ character instead of ␀
|
||||
|
||||
// use https://en.wikipedia.org/w/index.php?title=Code_page_437&oldid=978947122
|
||||
// not ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/PC/CP437.TXT
|
||||
// because we want the graphic versions of 01h–1Fh + 7Fh
|
||||
'⋄','☺','☻','♥','♦','♣','♠','•','◘','○','◙','♂','♀','♪','♫','☼',
|
||||
'►','◄','↕','‼','¶','§','▬','↨','↑','↓','→','←','∟','↔','▲','▼',
|
||||
' ','!','"','#','$','%','&','\'','(',')','*','+',',','-','.','/',
|
||||
'0','1','2','3','4','5','6','7','8','9',':',';','<','=','>','?',
|
||||
'@','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O',
|
||||
'P','Q','R','S','T','U','V','W','X','Y','Z','[','\\',']','^','_',
|
||||
'`','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o',
|
||||
'p','q','r','s','t','u','v','w','x','y','z','{','|','}','~','⌂',
|
||||
'Ç','ü','é','â','ä','à','å','ç','ê','ë','è','ï','î','ì','Ä','Å',
|
||||
'É','æ','Æ','ô','ö','ò','û','ù','ÿ','Ö','Ü','¢','£','¥','₧','ƒ',
|
||||
'á','í','ó','ú','ñ','Ñ','ª','º','¿','⌐','¬','½','¼','¡','«','»',
|
||||
'░','▒','▓','│','┤','╡','╢','╖','╕','╣','║','╗','╝','╜','╛','┐',
|
||||
'└','┴','┬','├','─','┼','╞','╟','╚','╔','╩','╦','╠','═','╬','╧',
|
||||
'╨','╤','╥','╙','╘','╒','╓','╫','╪','┘','┌','█','▄','▌','▐','▀',
|
||||
'α','ß','Γ','π','Σ','σ','µ','τ','Φ','Θ','Ω','δ','∞','φ','ε','∩',
|
||||
'≡','±','≥','≤','⌠','⌡','÷','≈','°','∙','·','√','ⁿ','²','■','ff',
|
||||
];
|
||||
+307
-607
File diff suppressed because it is too large.
Load diff
+407
@@ -0,0 +1,407 @@
|
||||
#[derive(Debug, PartialEq)]
|
||||
enum SqueezeState {
|
||||
/// not enabled
|
||||
Disabled,
|
||||
/// Will be set from all states if equal condition can't be hold up.
|
||||
/// Set if previous byte is not equal the current processed byte.
|
||||
NoSqueeze,
|
||||
/// Valid for a whole line to identify if it is candidate for squeezing
|
||||
Probe,
|
||||
/// Squeeze line parsing is active, but EOL is not reached yet
|
||||
SqueezeActive,
|
||||
/// Squeeze line, EOL is reached, will influence the action
|
||||
Squeeze,
|
||||
/// same as Squeeze, however this is only for the first line after
|
||||
/// the squeeze candidate has been set.
|
||||
SqueezeFirstLine,
|
||||
/// same as SqueezeActive, however this is only for the first line after
|
||||
/// the squeeze candidate has been set.
|
||||
SqueezeActiveFirstLine,
|
||||
}
|
||||
|
||||
pub struct Squeezer {
|
||||
state: SqueezeState,
|
||||
byte: u8,
|
||||
lsize: u64,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum SqueezeAction {
|
||||
Ignore,
|
||||
Print,
|
||||
Delete,
|
||||
}
|
||||
|
||||
impl Squeezer {
|
||||
pub fn new(enabled: bool, lsize: u64) -> Squeezer {
|
||||
Squeezer {
|
||||
state: if enabled {
|
||||
SqueezeState::Probe
|
||||
} else {
|
||||
SqueezeState::Disabled
|
||||
},
|
||||
byte: 0,
|
||||
lsize,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn process(&mut self, b: u8, i: u64) {
|
||||
use self::SqueezeState::*;
|
||||
if self.state == Disabled {
|
||||
return;
|
||||
}
|
||||
let eq = b == self.byte;
|
||||
|
||||
if i % self.lsize == 0 {
|
||||
if !eq {
|
||||
self.state = Probe;
|
||||
} else {
|
||||
self.state = match self.state {
|
||||
NoSqueeze => Probe,
|
||||
Probe => SqueezeActiveFirstLine,
|
||||
SqueezeActiveFirstLine => SqueezeFirstLine,
|
||||
SqueezeFirstLine => SqueezeActive,
|
||||
SqueezeActive => Squeeze,
|
||||
Squeeze => SqueezeActive,
|
||||
Disabled => Disabled,
|
||||
};
|
||||
}
|
||||
} else if !eq {
|
||||
if i % self.lsize == 1 {
|
||||
self.state = Probe;
|
||||
} else if i % self.lsize != 1 {
|
||||
self.state = NoSqueeze;
|
||||
}
|
||||
}
|
||||
|
||||
self.byte = b;
|
||||
}
|
||||
|
||||
pub fn active(&self) -> bool {
|
||||
use self::SqueezeState::*;
|
||||
matches!(
|
||||
self.state,
|
||||
Squeeze | SqueezeActive | SqueezeFirstLine | SqueezeActiveFirstLine
|
||||
)
|
||||
}
|
||||
|
||||
pub fn action(&self) -> SqueezeAction {
|
||||
match self.state {
|
||||
SqueezeState::SqueezeFirstLine => SqueezeAction::Print,
|
||||
SqueezeState::Squeeze => SqueezeAction::Delete,
|
||||
_ => SqueezeAction::Ignore,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn advance(&mut self) {
|
||||
match self.state {
|
||||
SqueezeState::SqueezeFirstLine => {
|
||||
self.state = SqueezeState::SqueezeActive;
|
||||
}
|
||||
SqueezeState::Squeeze => {
|
||||
self.state = SqueezeState::SqueezeActive;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
const LSIZE: u64 = 16;
|
||||
const LSIZE_USIZE: usize = LSIZE as usize;
|
||||
|
||||
#[test]
|
||||
fn three_same_lines() {
|
||||
const LINES: usize = 3;
|
||||
let v = vec![0u8; LINES * LSIZE_USIZE];
|
||||
let mut s = Squeezer::new(true, LSIZE);
|
||||
// just initialized
|
||||
assert_eq!(s.action(), SqueezeAction::Ignore);
|
||||
s.advance();
|
||||
|
||||
let exp = vec![
|
||||
SqueezeAction::Ignore, // first line, print as is
|
||||
SqueezeAction::Print, // print squeeze symbol
|
||||
SqueezeAction::Delete, // delete reoccurring line
|
||||
];
|
||||
|
||||
let mut idx = 1;
|
||||
for (line, z) in v.chunks(LSIZE_USIZE).enumerate() {
|
||||
for i in z {
|
||||
s.process(*i, idx);
|
||||
idx += 1;
|
||||
}
|
||||
let action = s.action();
|
||||
s.advance();
|
||||
assert_eq!(action, exp[line]);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn incomplete_while_squeeze() {
|
||||
// fourth line only has 12 bytes and should be printed
|
||||
let v = vec![0u8; 3 * LSIZE_USIZE + 12];
|
||||
let mut s = Squeezer::new(true, LSIZE);
|
||||
// just initialized
|
||||
assert_eq!(s.action(), SqueezeAction::Ignore);
|
||||
s.advance();
|
||||
|
||||
let exp = vec![
|
||||
SqueezeAction::Ignore, // first line, print as is
|
||||
SqueezeAction::Print, // print squeeze symbol
|
||||
SqueezeAction::Delete, // delete reoccurring line
|
||||
SqueezeAction::Ignore, // last line only 12 bytes, print it
|
||||
];
|
||||
|
||||
let mut idx = 1;
|
||||
for (line, z) in v.chunks(LSIZE_USIZE).enumerate() {
|
||||
for i in z {
|
||||
s.process(*i, idx);
|
||||
idx += 1;
|
||||
}
|
||||
assert_eq!(s.action(), exp[line]);
|
||||
s.advance();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
/// all three lines are different, print all
|
||||
fn three_different_lines() {
|
||||
let mut v: Vec<u8> = vec![];
|
||||
v.extend(vec![0u8; 16]);
|
||||
v.extend(vec![1u8; 16]);
|
||||
v.extend(vec![2u8; 16]);
|
||||
|
||||
let mut s = Squeezer::new(true, LSIZE);
|
||||
// just initialized
|
||||
assert_eq!(s.action(), SqueezeAction::Ignore);
|
||||
s.advance();
|
||||
|
||||
let exp = vec![
|
||||
SqueezeAction::Ignore, // first line, print as is
|
||||
SqueezeAction::Ignore, // different
|
||||
SqueezeAction::Ignore, // different
|
||||
];
|
||||
|
||||
let mut idx = 1;
|
||||
for (line, z) in v.chunks(LSIZE_USIZE).enumerate() {
|
||||
for i in z {
|
||||
s.process(*i, idx);
|
||||
idx += 1;
|
||||
}
|
||||
let action = s.action();
|
||||
assert_eq!(action, exp[line]);
|
||||
s.advance();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
/// first two lines same, hence squeeze symbol, third line diff, hence
|
||||
/// print
|
||||
fn one_squeeze_no_delete() {
|
||||
const LINES: usize = 3;
|
||||
let mut v = vec![0u8; (LINES - 1) * LSIZE_USIZE];
|
||||
v.extend(vec![1u8; 16]);
|
||||
|
||||
let mut s = Squeezer::new(true, LSIZE);
|
||||
// just initialized
|
||||
assert_eq!(s.action(), SqueezeAction::Ignore);
|
||||
s.advance();
|
||||
|
||||
let exp = vec![
|
||||
SqueezeAction::Ignore, // first line, print as is
|
||||
SqueezeAction::Print, // print squeeze symbol
|
||||
SqueezeAction::Ignore, // different lines, print again
|
||||
];
|
||||
|
||||
let mut idx = 1;
|
||||
for (line, z) in v.chunks(LSIZE_USIZE).enumerate() {
|
||||
for i in z {
|
||||
s.process(*i, idx);
|
||||
idx += 1;
|
||||
}
|
||||
let action = s.action();
|
||||
s.advance();
|
||||
assert_eq!(action, exp[line]);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
/// First line all eq, 2nd half eq with first line, then change
|
||||
fn second_line_different() {
|
||||
const LINES: usize = 2;
|
||||
let mut v = vec![0u8; (LINES - 1) * LSIZE_USIZE];
|
||||
v.extend(vec![0u8; 8]);
|
||||
v.extend(vec![1u8; 8]);
|
||||
|
||||
let mut s = Squeezer::new(true, LSIZE);
|
||||
// just initialized
|
||||
assert_eq!(s.action(), SqueezeAction::Ignore);
|
||||
s.advance();
|
||||
|
||||
let exp = vec![
|
||||
SqueezeAction::Ignore, // first line, print as is
|
||||
SqueezeAction::Ignore, // print squeeze symbol
|
||||
];
|
||||
|
||||
let mut idx = 1;
|
||||
for (line, z) in v.chunks(LSIZE_USIZE).enumerate() {
|
||||
for i in z {
|
||||
s.process(*i, idx);
|
||||
idx += 1;
|
||||
}
|
||||
let action = s.action();
|
||||
s.advance();
|
||||
assert_eq!(action, exp[line]);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
/// all three lines never become squeeze candidate (diff within line)
|
||||
fn never_squeeze_candidate() {
|
||||
let mut v = vec![];
|
||||
v.extend(vec![0u8; 8]);
|
||||
v.extend(vec![1u8; 8]);
|
||||
v.extend(vec![0u8; 8]);
|
||||
v.extend(vec![1u8; 8]);
|
||||
v.extend(vec![0u8; 8]);
|
||||
v.extend(vec![1u8; 8]);
|
||||
|
||||
let mut s = Squeezer::new(true, LSIZE);
|
||||
// just initialized
|
||||
assert_eq!(s.action(), SqueezeAction::Ignore);
|
||||
s.advance();
|
||||
|
||||
let exp = vec![
|
||||
SqueezeAction::Ignore, // first line, print as is
|
||||
SqueezeAction::Ignore, // print squeeze symbol
|
||||
SqueezeAction::Ignore, // print squeeze symbol
|
||||
];
|
||||
|
||||
let mut idx = 1;
|
||||
for (line, z) in v.chunks(LSIZE_USIZE).enumerate() {
|
||||
for i in z {
|
||||
s.process(*i, idx);
|
||||
idx += 1;
|
||||
}
|
||||
let action = s.action();
|
||||
s.advance();
|
||||
assert_eq!(action, exp[line]);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mix_everything() {
|
||||
let mut v = vec![];
|
||||
v.extend(vec![10u8; 16]); // print
|
||||
v.extend(vec![20u8; 16]); // print
|
||||
v.extend(vec![0u8; 16]); // print
|
||||
v.extend(vec![0u8; 16]); // *
|
||||
v.extend(vec![10u8; 16]); // print
|
||||
v.extend(vec![20u8; 16]); // print
|
||||
v.extend(vec![0u8; 16]); // print
|
||||
v.extend(vec![0u8; 16]); // *
|
||||
v.extend(vec![0u8; 16]); // delete
|
||||
v.extend(vec![0u8; 16]); // delete*
|
||||
v.extend(vec![20u8; 16]); // print
|
||||
v.extend(vec![0u8; 12]); // print, only 12 bytes
|
||||
|
||||
let mut s = Squeezer::new(true, LSIZE);
|
||||
// just initialized
|
||||
assert_eq!(s.action(), SqueezeAction::Ignore);
|
||||
s.advance();
|
||||
|
||||
let exp = vec![
|
||||
SqueezeAction::Ignore,
|
||||
SqueezeAction::Ignore,
|
||||
SqueezeAction::Ignore,
|
||||
SqueezeAction::Print,
|
||||
SqueezeAction::Ignore,
|
||||
SqueezeAction::Ignore,
|
||||
SqueezeAction::Ignore,
|
||||
SqueezeAction::Print,
|
||||
SqueezeAction::Delete,
|
||||
SqueezeAction::Delete,
|
||||
SqueezeAction::Ignore,
|
||||
SqueezeAction::Ignore,
|
||||
];
|
||||
|
||||
let mut idx = 1;
|
||||
for (line, z) in v.chunks(LSIZE_USIZE).enumerate() {
|
||||
for i in z {
|
||||
s.process(*i, idx);
|
||||
idx += 1;
|
||||
}
|
||||
let action = s.action();
|
||||
s.advance();
|
||||
assert_eq!(action, exp[line]);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn last_char_diff() {
|
||||
// see issue #62
|
||||
let mut v = vec![];
|
||||
v.extend(vec![20u8; 16]);
|
||||
v.extend(vec![20u8; 15]);
|
||||
v.push(61);
|
||||
v.extend(vec![20u8; 16]);
|
||||
v.extend(vec![20u8; 16]);
|
||||
|
||||
let mut s = Squeezer::new(true, LSIZE);
|
||||
// just initialized
|
||||
assert_eq!(s.action(), SqueezeAction::Ignore);
|
||||
s.advance();
|
||||
|
||||
let exp = vec![
|
||||
SqueezeAction::Ignore, // print as is
|
||||
SqueezeAction::Ignore, // print as is
|
||||
SqueezeAction::Ignore, // print as is
|
||||
SqueezeAction::Print, // print '*' char
|
||||
];
|
||||
|
||||
let mut idx = 1;
|
||||
for (line, z) in v.chunks(LSIZE_USIZE).enumerate() {
|
||||
for i in z {
|
||||
s.process(*i, idx);
|
||||
idx += 1;
|
||||
}
|
||||
assert_eq!(s.action(), exp[line]);
|
||||
s.advance();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn first_char_diff() {
|
||||
// see issue #62
|
||||
let mut v = vec![];
|
||||
v.extend(vec![20u8; 16]);
|
||||
v.push(61);
|
||||
v.extend(vec![20u8; 15]);
|
||||
v.extend(vec![20u8; 16]);
|
||||
|
||||
let mut s = Squeezer::new(true, LSIZE);
|
||||
// just initialized
|
||||
assert_eq!(s.action(), SqueezeAction::Ignore);
|
||||
s.advance();
|
||||
|
||||
let exp = vec![
|
||||
SqueezeAction::Ignore, // print as is
|
||||
SqueezeAction::Ignore, // print as is
|
||||
SqueezeAction::Ignore, // print as is
|
||||
];
|
||||
|
||||
let mut idx = 1;
|
||||
for (line, z) in v.chunks(LSIZE_USIZE).enumerate() {
|
||||
for i in z {
|
||||
s.process(*i, idx);
|
||||
idx += 1;
|
||||
}
|
||||
assert_eq!(s.action(), exp[line]);
|
||||
s.advance();
|
||||
}
|
||||
}
|
||||
}
|
||||
-156
@@ -1,156 +0,0 @@
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn unit_multipliers() {
|
||||
use Unit::*;
|
||||
assert_eq!(Kilobyte.get_multiplier(), 1000 * Byte.get_multiplier());
|
||||
assert_eq!(Megabyte.get_multiplier(), 1000 * Kilobyte.get_multiplier());
|
||||
assert_eq!(Gigabyte.get_multiplier(), 1000 * Megabyte.get_multiplier());
|
||||
assert_eq!(Terabyte.get_multiplier(), 1000 * Gigabyte.get_multiplier());
|
||||
|
||||
assert_eq!(Kibibyte.get_multiplier(), 1024 * Byte.get_multiplier());
|
||||
assert_eq!(Mebibyte.get_multiplier(), 1024 * Kibibyte.get_multiplier());
|
||||
assert_eq!(Gibibyte.get_multiplier(), 1024 * Mebibyte.get_multiplier());
|
||||
assert_eq!(Tebibyte.get_multiplier(), 1024 * Gibibyte.get_multiplier());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_process_sign() {
|
||||
use ByteOffsetKind::*;
|
||||
use ByteOffsetParseError::*;
|
||||
assert_eq!(process_sign_of("123"), Ok(("123", ForwardFromBeginning)));
|
||||
assert_eq!(process_sign_of("+123"), Ok(("123", ForwardFromLastOffset)));
|
||||
assert_eq!(process_sign_of("-123"), Ok(("123", BackwardFromEnd)));
|
||||
assert_eq!(process_sign_of("-"), Err(EmptyAfterSign));
|
||||
assert_eq!(process_sign_of("+"), Err(EmptyAfterSign));
|
||||
assert_eq!(process_sign_of(""), Err(Empty));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_as_hex() {
|
||||
assert_eq!(try_parse_as_hex_number("73"), None);
|
||||
assert_eq!(try_parse_as_hex_number("0x1337"), Some(Ok(0x1337)));
|
||||
assert!(matches!(try_parse_as_hex_number("0xnope"), Some(Err(_))));
|
||||
assert!(matches!(try_parse_as_hex_number("0x-1"), Some(Err(_))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extract_num_and_unit() {
|
||||
use ByteOffsetParseError::*;
|
||||
use Unit::*;
|
||||
// byte is default unit
|
||||
assert_eq!(extract_num_and_unit_from("4"), Ok((4, Byte)));
|
||||
// blocks are returned without customization
|
||||
assert_eq!(
|
||||
extract_num_and_unit_from("2blocks"),
|
||||
Ok((2, Block { custom_size: None }))
|
||||
);
|
||||
// no normalization is performed
|
||||
assert_eq!(extract_num_and_unit_from("1024kb"), Ok((1024, Kilobyte)));
|
||||
|
||||
// unit without number results in error
|
||||
assert_eq!(
|
||||
extract_num_and_unit_from("gib"),
|
||||
Err(EmptyWithUnit("gib".to_string()))
|
||||
);
|
||||
// empty string results in error
|
||||
assert_eq!(extract_num_and_unit_from(""), Err(Empty));
|
||||
// an invalid unit results in an error
|
||||
assert_eq!(
|
||||
extract_num_and_unit_from("25litres"),
|
||||
Err(InvalidUnit("litres".to_string()))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_byte_offset() {
|
||||
use ByteOffsetParseError::*;
|
||||
|
||||
macro_rules! success {
|
||||
($input: expr, $expected_kind: ident $expected_value: expr) => {
|
||||
success!($input, $expected_kind $expected_value; block_size: DEFAULT_BLOCK_SIZE)
|
||||
};
|
||||
($input: expr, $expected_kind: ident $expected_value: expr; block_size: $block_size: expr) => {
|
||||
assert_eq!(
|
||||
parse_byte_offset($input, PositiveI64::new($block_size).unwrap()),
|
||||
Ok(
|
||||
ByteOffset {
|
||||
value: NonNegativeI64::new($expected_value).unwrap(),
|
||||
kind: ByteOffsetKind::$expected_kind,
|
||||
}
|
||||
),
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! error {
|
||||
($input: expr, $expected_err: expr) => {
|
||||
assert_eq!(
|
||||
parse_byte_offset($input, PositiveI64::new(DEFAULT_BLOCK_SIZE).unwrap()),
|
||||
Err($expected_err),
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
success!("0", ForwardFromBeginning 0);
|
||||
success!("1", ForwardFromBeginning 1);
|
||||
success!("1", ForwardFromBeginning 1);
|
||||
success!("100", ForwardFromBeginning 100);
|
||||
success!("+100", ForwardFromLastOffset 100);
|
||||
|
||||
success!("0x0", ForwardFromBeginning 0);
|
||||
success!("0xf", ForwardFromBeginning 15);
|
||||
success!("0xdeadbeef", ForwardFromBeginning 3_735_928_559);
|
||||
|
||||
success!("1KB", ForwardFromBeginning 1000);
|
||||
success!("2MB", ForwardFromBeginning 2000000);
|
||||
success!("3GB", ForwardFromBeginning 3000000000);
|
||||
success!("4TB", ForwardFromBeginning 4000000000000);
|
||||
success!("+4TB", ForwardFromLastOffset 4000000000000);
|
||||
|
||||
success!("1GiB", ForwardFromBeginning 1073741824);
|
||||
success!("2TiB", ForwardFromBeginning 2199023255552);
|
||||
success!("+2TiB", ForwardFromLastOffset 2199023255552);
|
||||
|
||||
success!("0xff", ForwardFromBeginning 255);
|
||||
success!("0xEE", ForwardFromBeginning 238);
|
||||
success!("+0xFF", ForwardFromLastOffset 255);
|
||||
|
||||
success!("1block", ForwardFromBeginning 512; block_size: 512);
|
||||
success!("2block", ForwardFromBeginning 1024; block_size: 512);
|
||||
success!("1block", ForwardFromBeginning 4; block_size: 4);
|
||||
success!("2block", ForwardFromBeginning 8; block_size: 4);
|
||||
|
||||
// empty string is invalid
|
||||
error!("", Empty);
|
||||
// These are also bad.
|
||||
error!("+", EmptyAfterSign);
|
||||
error!("-", EmptyAfterSign);
|
||||
error!("K", InvalidNumAndUnit("K".to_owned()));
|
||||
error!("k", InvalidNumAndUnit("k".to_owned()));
|
||||
error!("m", InvalidNumAndUnit("m".to_owned()));
|
||||
error!("block", EmptyWithUnit("block".to_owned()));
|
||||
// leading/trailing space is invalid
|
||||
error!(" 0", InvalidNumAndUnit(" 0".to_owned()));
|
||||
error!("0 ", InvalidUnit(" ".to_owned()));
|
||||
// Signs after the hex prefix make no sense
|
||||
error!("0x-12", SignFoundAfterHexPrefix('-'));
|
||||
// This was previously accepted but shouldn't be.
|
||||
error!("0x+12", SignFoundAfterHexPrefix('+'));
|
||||
// invalid suffix
|
||||
error!("1234asdf", InvalidUnit("asdf".to_owned()));
|
||||
// bad numbers
|
||||
error!("asdf1234", InvalidNumAndUnit("asdf1234".to_owned()));
|
||||
error!("a1s2d3f4", InvalidNumAndUnit("a1s2d3f4".to_owned()));
|
||||
// multiplication overflows u64
|
||||
error!("20000000TiB", UnitMultiplicationOverflow);
|
||||
|
||||
assert!(
|
||||
match parse_byte_offset("99999999999999999999", PositiveI64::new(512).unwrap()) {
|
||||
// We can't check against the kind of the `ParseIntError`, so we'll just make sure it's the
|
||||
// same as trying to do the parse directly.
|
||||
Err(ParseNum(e)) => e == "99999999999999999999".parse::<i64>().unwrap_err(),
|
||||
_ => false,
|
||||
}
|
||||
);
|
||||
}
|
||||
+6
-466
@@ -1,30 +1,10 @@
|
||||
use assert_cmd::Command;
|
||||
|
||||
fn hexyl() -> Command {
|
||||
let mut cmd = Command::cargo_bin("hexyl").unwrap();
|
||||
let mut cmd = Command::new(assert_cmd::cargo_bin!("hexyl"));
|
||||
cmd.current_dir("tests/examples");
|
||||
cmd
|
||||
}
|
||||
trait PrettyAssert<S>
|
||||
where
|
||||
S: AsRef<str>,
|
||||
{
|
||||
fn pretty_stdout(self, other: S);
|
||||
}
|
||||
|
||||
// https://github.com/assert-rs/assert_cmd/issues/121#issuecomment-849937376
|
||||
//
|
||||
impl<S> PrettyAssert<S> for assert_cmd::assert::Assert
|
||||
where
|
||||
S: AsRef<str>,
|
||||
{
|
||||
fn pretty_stdout(self, other: S) {
|
||||
println!("{}", other.as_ref().len());
|
||||
let self_str = String::from_utf8(self.get_output().stdout.clone()).unwrap();
|
||||
println!("{}", self_str.len());
|
||||
pretty_assertions::assert_eq!(self_str, other.as_ref());
|
||||
}
|
||||
}
|
||||
|
||||
mod basic {
|
||||
use super::hexyl;
|
||||
@@ -71,7 +51,7 @@ mod basic {
|
||||
.success()
|
||||
.stdout(
|
||||
"┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐\n\
|
||||
│ │ No content │ │ │ │\n\
|
||||
│ │ No content to print │ │ │ │\n\
|
||||
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n",
|
||||
);
|
||||
}
|
||||
@@ -90,8 +70,8 @@ mod length {
|
||||
.success()
|
||||
.stdout(
|
||||
"┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐\n\
|
||||
│00000000│ 7f 45 4c 46 02 01 01 00 ┊ 00 00 00 00 00 00 00 00 │•ELF•••⋄┊⋄⋄⋄⋄⋄⋄⋄⋄│\n\
|
||||
│00000010│ 02 00 3e 00 01 00 00 00 ┊ 00 10 40 00 00 00 00 00 │•⋄>⋄•⋄⋄⋄┊⋄•@⋄⋄⋄⋄⋄│\n\
|
||||
│00000000│ 7f 45 4c 46 02 01 01 00 ┊ 00 00 00 00 00 00 00 00 │•ELF•••0┊00000000│\n\
|
||||
│00000010│ 02 00 3e 00 01 00 00 00 ┊ 00 10 40 00 00 00 00 00 │•0>0•000┊0•@00000│\n\
|
||||
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n",
|
||||
);
|
||||
}
|
||||
@@ -160,7 +140,7 @@ mod skip {
|
||||
.success()
|
||||
.stdout(
|
||||
"┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐\n\
|
||||
│ │ No content │ │ │ │\n\
|
||||
│ │ No content to print │ │ │ │\n\
|
||||
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n",
|
||||
);
|
||||
}
|
||||
@@ -223,7 +203,7 @@ mod display_offset {
|
||||
.success()
|
||||
.stdout(
|
||||
"┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐\n\
|
||||
│00000030│ 02 00 3e 00 01 00 00 00 ┊ 00 10 40 00 00 00 00 00 │•⋄>⋄•⋄⋄⋄┊⋄•@⋄⋄⋄⋄⋄│\n\
|
||||
│00000030│ 02 00 3e 00 01 00 00 00 ┊ 00 10 40 00 00 00 00 00 │•0>0•000┊0•@00000│\n\
|
||||
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n",
|
||||
);
|
||||
}
|
||||
@@ -291,443 +271,3 @@ mod display_settings {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod group_and_endianness {
|
||||
use super::hexyl;
|
||||
use super::PrettyAssert;
|
||||
|
||||
#[test]
|
||||
fn group_2_bytes_be() {
|
||||
hexyl()
|
||||
.arg("ascii")
|
||||
.arg("--color=never")
|
||||
.arg("--group-size=2")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(
|
||||
"┌────────┬─────────────────────┬─────────────────────┬────────┬────────┐\n\
|
||||
│00000000│ 3031 3233 3435 3637 ┊ 3839 6162 6364 650a │01234567┊89abcde_│\n\
|
||||
└────────┴─────────────────────┴─────────────────────┴────────┴────────┘\n",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn group_2_bytes_le() {
|
||||
hexyl()
|
||||
.arg("ascii")
|
||||
.arg("--color=never")
|
||||
.arg("--group-size=2")
|
||||
.arg("--endianness=little")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(
|
||||
"┌────────┬─────────────────────┬─────────────────────┬────────┬────────┐\n\
|
||||
│00000000│ 3130 3332 3534 3736 ┊ 3938 6261 6463 0a65 │01234567┊89abcde_│\n\
|
||||
└────────┴─────────────────────┴─────────────────────┴────────┴────────┘\n",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn group_4_bytes_be() {
|
||||
hexyl()
|
||||
.arg("ascii")
|
||||
.arg("--color=never")
|
||||
.arg("--group-size=4")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(
|
||||
"┌────────┬───────────────────┬───────────────────┬────────┬────────┐\n\
|
||||
│00000000│ 30313233 34353637 ┊ 38396162 6364650a │01234567┊89abcde_│\n\
|
||||
└────────┴───────────────────┴───────────────────┴────────┴────────┘\n",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn group_4_bytes_le() {
|
||||
hexyl()
|
||||
.arg("ascii")
|
||||
.arg("--color=never")
|
||||
.arg("--group-size=4")
|
||||
.arg("--endianness=little")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(
|
||||
"┌────────┬───────────────────┬───────────────────┬────────┬────────┐\n\
|
||||
│00000000│ 33323130 37363534 ┊ 62613938 0a656463 │01234567┊89abcde_│\n\
|
||||
└────────┴───────────────────┴───────────────────┴────────┴────────┘\n",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn group_8_bytes_be() {
|
||||
hexyl()
|
||||
.arg("ascii")
|
||||
.arg("--color=never")
|
||||
.arg("--group-size=8")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(
|
||||
"┌────────┬──────────────────┬──────────────────┬────────┬────────┐\n\
|
||||
│00000000│ 3031323334353637 ┊ 383961626364650a │01234567┊89abcde_│\n\
|
||||
└────────┴──────────────────┴──────────────────┴────────┴────────┘\n",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn group_8_bytes_le() {
|
||||
hexyl()
|
||||
.arg("ascii")
|
||||
.arg("--color=never")
|
||||
.arg("--group-size=8")
|
||||
.arg("--endianness=little")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(
|
||||
"┌────────┬──────────────────┬──────────────────┬────────┬────────┐\n\
|
||||
│00000000│ 3736353433323130 ┊ 0a65646362613938 │01234567┊89abcde_│\n\
|
||||
└────────┴──────────────────┴──────────────────┴────────┴────────┘\n",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn group_size_plain() {
|
||||
hexyl()
|
||||
.arg("ascii")
|
||||
.arg("--color=never")
|
||||
.arg("--plain")
|
||||
.arg("--group-size=2")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(" 3031 3233 3435 3637 3839 6162 6364 650a \n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn group_size_fill_space() {
|
||||
hexyl()
|
||||
.arg("--color=never")
|
||||
.arg("--group-size=2")
|
||||
.write_stdin("abc")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(
|
||||
"┌────────┬─────────────────────┬─────────────────────┬────────┬────────┐\n\
|
||||
│00000000│ 6162 63 ┊ │abc ┊ │\n\
|
||||
└────────┴─────────────────────┴─────────────────────┴────────┴────────┘\n",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn group_size_invalid() {
|
||||
hexyl()
|
||||
.arg("ascii")
|
||||
.arg("--color=never")
|
||||
.arg("--plain")
|
||||
.arg("--group-size=3")
|
||||
.assert()
|
||||
.failure();
|
||||
}
|
||||
#[test]
|
||||
fn squeeze_no_chars() {
|
||||
hexyl()
|
||||
.arg("hello_world_elf64")
|
||||
.arg("--color=never")
|
||||
.arg("--skip=1024")
|
||||
.arg("--length=4096")
|
||||
.arg("--no-characters")
|
||||
.assert()
|
||||
.success()
|
||||
.pretty_stdout(
|
||||
"\
|
||||
┌────────┬─────────────────────────┬─────────────────────────┐
|
||||
│00000400│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │
|
||||
│* │ ┊ │
|
||||
│00001000│ ba 0e 00 00 00 b9 00 20 ┊ 40 00 bb 01 00 00 00 b8 │
|
||||
│00001010│ 04 00 00 00 cd 80 b8 01 ┊ 00 00 00 cd 80 00 00 00 │
|
||||
│00001020│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │
|
||||
│* │ ┊ │
|
||||
│00001400│ ┊ │
|
||||
└────────┴─────────────────────────┴─────────────────────────┘
|
||||
",
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn squeeze_no_chars_one_panel() {
|
||||
hexyl()
|
||||
.arg("hello_world_elf64")
|
||||
.arg("--color=never")
|
||||
.arg("--skip=1024")
|
||||
.arg("--length=4096")
|
||||
.arg("--no-characters")
|
||||
.arg("--panels=1")
|
||||
.assert()
|
||||
.success()
|
||||
.pretty_stdout(
|
||||
"\
|
||||
┌────────┬─────────────────────────┐
|
||||
│00000400│ 00 00 00 00 00 00 00 00 │
|
||||
│* │ │
|
||||
│00001000│ ba 0e 00 00 00 b9 00 20 │
|
||||
│00001008│ 40 00 bb 01 00 00 00 b8 │
|
||||
│00001010│ 04 00 00 00 cd 80 b8 01 │
|
||||
│00001018│ 00 00 00 cd 80 00 00 00 │
|
||||
│00001020│ 00 00 00 00 00 00 00 00 │
|
||||
│* │ │
|
||||
│00001400│ │
|
||||
└────────┴─────────────────────────┘
|
||||
",
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn squeeze_no_position() {
|
||||
hexyl()
|
||||
.arg("hello_world_elf64")
|
||||
.arg("--color=never")
|
||||
.arg("--skip=1024")
|
||||
.arg("--length=4096")
|
||||
.arg("--no-position")
|
||||
.assert()
|
||||
.success()
|
||||
.pretty_stdout(
|
||||
"\
|
||||
┌─────────────────────────┬─────────────────────────┬────────┬────────┐
|
||||
│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄┊⋄⋄⋄⋄⋄⋄⋄⋄│
|
||||
│* ┊ │ ┊ │
|
||||
│ ba 0e 00 00 00 b9 00 20 ┊ 40 00 bb 01 00 00 00 b8 │ו⋄⋄⋄×⋄ ┊@⋄ו⋄⋄⋄×│
|
||||
│ 04 00 00 00 cd 80 b8 01 ┊ 00 00 00 cd 80 00 00 00 │•⋄⋄⋄××ו┊⋄⋄⋄××⋄⋄⋄│
|
||||
│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄┊⋄⋄⋄⋄⋄⋄⋄⋄│
|
||||
│* ┊ │ ┊ │
|
||||
│* ┊ │ ┊ │
|
||||
└─────────────────────────┴─────────────────────────┴────────┴────────┘
|
||||
",
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn squeeze_no_position_one_panel() {
|
||||
hexyl()
|
||||
.arg("hello_world_elf64")
|
||||
.arg("--color=never")
|
||||
.arg("--skip=1024")
|
||||
.arg("--length=4096")
|
||||
.arg("--no-position")
|
||||
.arg("--panels=1")
|
||||
.assert()
|
||||
.success()
|
||||
.pretty_stdout(
|
||||
"\
|
||||
┌─────────────────────────┬────────┐
|
||||
│ 00 00 00 00 00 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄│
|
||||
│* │ │
|
||||
│ ba 0e 00 00 00 b9 00 20 │ו⋄⋄⋄×⋄ │
|
||||
│ 40 00 bb 01 00 00 00 b8 │@⋄ו⋄⋄⋄×│
|
||||
│ 04 00 00 00 cd 80 b8 01 │•⋄⋄⋄××ו│
|
||||
│ 00 00 00 cd 80 00 00 00 │⋄⋄⋄××⋄⋄⋄│
|
||||
│ 00 00 00 00 00 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄│
|
||||
│* │ │
|
||||
│* │ │
|
||||
└─────────────────────────┴────────┘
|
||||
",
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn squeeze_odd_panels_remainder_bytes() {
|
||||
hexyl()
|
||||
.arg("hello_world_elf64")
|
||||
.arg("--color=never")
|
||||
.arg("--skip=1024")
|
||||
.arg("--length=4092") // 4 byte remainder
|
||||
.arg("--panels=3")
|
||||
.assert()
|
||||
.success()
|
||||
.pretty_stdout(
|
||||
"\
|
||||
┌────────┬─────────────────────────┬─────────────────────────┬─────────────────────────┬────────┬────────┬────────┐
|
||||
│00000400│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄┊⋄⋄⋄⋄⋄⋄⋄⋄┊⋄⋄⋄⋄⋄⋄⋄⋄│
|
||||
│* │ ┊ ┊ │ ┊ ┊ │
|
||||
│00001000│ ba 0e 00 00 00 b9 00 20 ┊ 40 00 bb 01 00 00 00 b8 ┊ 04 00 00 00 cd 80 b8 01 │ו⋄⋄⋄×⋄ ┊@⋄ו⋄⋄⋄×┊•⋄⋄⋄××ו│
|
||||
│00001018│ 00 00 00 cd 80 00 00 00 ┊ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │⋄⋄⋄××⋄⋄⋄┊⋄⋄⋄⋄⋄⋄⋄⋄┊⋄⋄⋄⋄⋄⋄⋄⋄│
|
||||
│00001030│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄┊⋄⋄⋄⋄⋄⋄⋄⋄┊⋄⋄⋄⋄⋄⋄⋄⋄│
|
||||
│* │ ┊ ┊ │ ┊ ┊ │
|
||||
│000013f0│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 ┊ │⋄⋄⋄⋄⋄⋄⋄⋄┊⋄⋄⋄⋄ ┊ │
|
||||
└────────┴─────────────────────────┴─────────────────────────┴─────────────────────────┴────────┴────────┴────────┘
|
||||
",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn squeeze_plain() {
|
||||
hexyl()
|
||||
.arg("hello_world_elf64")
|
||||
.arg("--color=never")
|
||||
.arg("--skip=1024")
|
||||
.arg("--length=4096")
|
||||
.arg("--plain")
|
||||
.assert()
|
||||
.success()
|
||||
.pretty_stdout(
|
||||
" \
|
||||
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||
*
|
||||
ba 0e 00 00 00 b9 00 20 40 00 bb 01 00 00 00 b8
|
||||
04 00 00 00 cd 80 b8 01 00 00 00 cd 80 00 00 00
|
||||
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||
*
|
||||
*
|
||||
",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn squeeze_plain_remainder() {
|
||||
hexyl()
|
||||
.arg("hello_world_elf64")
|
||||
.arg("--color=never")
|
||||
.arg("--skip=1024")
|
||||
.arg("--length=4092") // 4 byte remainder
|
||||
.arg("--plain")
|
||||
.assert()
|
||||
.success()
|
||||
.pretty_stdout(
|
||||
" \
|
||||
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||
*
|
||||
ba 0e 00 00 00 b9 00 20 40 00 bb 01 00 00 00 b8
|
||||
04 00 00 00 cd 80 b8 01 00 00 00 cd 80 00 00 00
|
||||
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||
*
|
||||
00 00 00 00 00 00 00 00 00 00 00 00
|
||||
",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod base {
|
||||
use super::hexyl;
|
||||
use super::PrettyAssert;
|
||||
|
||||
#[test]
|
||||
fn base2() {
|
||||
hexyl()
|
||||
.arg("ascii")
|
||||
.arg("--plain")
|
||||
.arg("--base=binary")
|
||||
.assert()
|
||||
.success()
|
||||
.pretty_stdout(
|
||||
" 00110000 00110001 00110010 00110011 00110100 00110101 00110110 00110111 \n \
|
||||
00111000 00111001 01100001 01100010 01100011 01100100 01100101 00001010 \n",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod character_table {
|
||||
use super::hexyl;
|
||||
use super::PrettyAssert;
|
||||
|
||||
#[test]
|
||||
fn ascii() {
|
||||
hexyl()
|
||||
.arg("hello_world_elf64")
|
||||
.arg("--color=never")
|
||||
.arg("--character-table=ascii")
|
||||
.assert()
|
||||
.success()
|
||||
.pretty_stdout(
|
||||
"┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐
|
||||
│00000000│ 7f 45 4c 46 02 01 01 00 ┊ 00 00 00 00 00 00 00 00 │.ELF....┊........│
|
||||
│00000010│ 02 00 3e 00 01 00 00 00 ┊ 00 10 40 00 00 00 00 00 │..>.....┊..@.....│
|
||||
│00000020│ 40 00 00 00 00 00 00 00 ┊ 28 20 00 00 00 00 00 00 │@.......┊( ......│
|
||||
│00000030│ 00 00 00 00 40 00 38 00 ┊ 03 00 40 00 04 00 03 00 │....@.8.┊..@.....│
|
||||
│00000040│ 01 00 00 00 04 00 00 00 ┊ 00 00 00 00 00 00 00 00 │........┊........│
|
||||
│00000050│ 00 00 40 00 00 00 00 00 ┊ 00 00 40 00 00 00 00 00 │..@.....┊..@.....│
|
||||
│00000060│ e8 00 00 00 00 00 00 00 ┊ e8 00 00 00 00 00 00 00 │........┊........│
|
||||
│00000070│ 00 10 00 00 00 00 00 00 ┊ 01 00 00 00 05 00 00 00 │........┊........│
|
||||
│00000080│ 00 10 00 00 00 00 00 00 ┊ 00 10 40 00 00 00 00 00 │........┊..@.....│
|
||||
│00000090│ 00 10 40 00 00 00 00 00 ┊ 1d 00 00 00 00 00 00 00 │..@.....┊........│
|
||||
│000000a0│ 1d 00 00 00 00 00 00 00 ┊ 00 10 00 00 00 00 00 00 │........┊........│
|
||||
│000000b0│ 01 00 00 00 06 00 00 00 ┊ 00 20 00 00 00 00 00 00 │........┊. ......│
|
||||
│000000c0│ 00 20 40 00 00 00 00 00 ┊ 00 20 40 00 00 00 00 00 │. @.....┊. @.....│
|
||||
│000000d0│ 0e 00 00 00 00 00 00 00 ┊ 0e 00 00 00 00 00 00 00 │........┊........│
|
||||
│000000e0│ 00 10 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │........┊........│
|
||||
│000000f0│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │........┊........│
|
||||
│* │ ┊ │ ┊ │
|
||||
│00001000│ ba 0e 00 00 00 b9 00 20 ┊ 40 00 bb 01 00 00 00 b8 │....... ┊@.......│
|
||||
│00001010│ 04 00 00 00 cd 80 b8 01 ┊ 00 00 00 cd 80 00 00 00 │........┊........│
|
||||
│00001020│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │........┊........│
|
||||
│* │ ┊ │ ┊ │
|
||||
│00002000│ 48 65 6c 6c 6f 2c 20 77 ┊ 6f 72 6c 64 21 0a 00 2e │Hello, w┊orld!...│
|
||||
│00002010│ 73 68 73 74 72 74 61 62 ┊ 00 2e 74 65 78 74 00 2e │shstrtab┊..text..│
|
||||
│00002020│ 64 61 74 61 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │data....┊........│
|
||||
│00002030│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │........┊........│
|
||||
│* │ ┊ │ ┊ │
|
||||
│00002060│ 00 00 00 00 00 00 00 00 ┊ 0b 00 00 00 01 00 00 00 │........┊........│
|
||||
│00002070│ 06 00 00 00 00 00 00 00 ┊ 00 10 40 00 00 00 00 00 │........┊..@.....│
|
||||
│00002080│ 00 10 00 00 00 00 00 00 ┊ 1d 00 00 00 00 00 00 00 │........┊........│
|
||||
│00002090│ 00 00 00 00 00 00 00 00 ┊ 10 00 00 00 00 00 00 00 │........┊........│
|
||||
│000020a0│ 00 00 00 00 00 00 00 00 ┊ 11 00 00 00 01 00 00 00 │........┊........│
|
||||
│000020b0│ 03 00 00 00 00 00 00 00 ┊ 00 20 40 00 00 00 00 00 │........┊. @.....│
|
||||
│000020c0│ 00 20 00 00 00 00 00 00 ┊ 0e 00 00 00 00 00 00 00 │. ......┊........│
|
||||
│000020d0│ 00 00 00 00 00 00 00 00 ┊ 04 00 00 00 00 00 00 00 │........┊........│
|
||||
│000020e0│ 00 00 00 00 00 00 00 00 ┊ 01 00 00 00 03 00 00 00 │........┊........│
|
||||
│000020f0│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │........┊........│
|
||||
│00002100│ 0e 20 00 00 00 00 00 00 ┊ 17 00 00 00 00 00 00 00 │. ......┊........│
|
||||
│00002110│ 00 00 00 00 00 00 00 00 ┊ 01 00 00 00 00 00 00 00 │........┊........│
|
||||
│00002120│ 00 00 00 00 00 00 00 00 ┊ │........┊ │
|
||||
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘
|
||||
",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn codepage_437() {
|
||||
hexyl()
|
||||
.arg("hello_world_elf64")
|
||||
.arg("--color=never")
|
||||
.arg("--character-table=codepage-437")
|
||||
.assert()
|
||||
.success()
|
||||
.pretty_stdout(
|
||||
"┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐
|
||||
│00000000│ 7f 45 4c 46 02 01 01 00 ┊ 00 00 00 00 00 00 00 00 │⌂ELF☻☺☺⋄┊⋄⋄⋄⋄⋄⋄⋄⋄│
|
||||
│00000010│ 02 00 3e 00 01 00 00 00 ┊ 00 10 40 00 00 00 00 00 │☻⋄>⋄☺⋄⋄⋄┊⋄►@⋄⋄⋄⋄⋄│
|
||||
│00000020│ 40 00 00 00 00 00 00 00 ┊ 28 20 00 00 00 00 00 00 │@⋄⋄⋄⋄⋄⋄⋄┊( ⋄⋄⋄⋄⋄⋄│
|
||||
│00000030│ 00 00 00 00 40 00 38 00 ┊ 03 00 40 00 04 00 03 00 │⋄⋄⋄⋄@⋄8⋄┊♥⋄@⋄♦⋄♥⋄│
|
||||
│00000040│ 01 00 00 00 04 00 00 00 ┊ 00 00 00 00 00 00 00 00 │☺⋄⋄⋄♦⋄⋄⋄┊⋄⋄⋄⋄⋄⋄⋄⋄│
|
||||
│00000050│ 00 00 40 00 00 00 00 00 ┊ 00 00 40 00 00 00 00 00 │⋄⋄@⋄⋄⋄⋄⋄┊⋄⋄@⋄⋄⋄⋄⋄│
|
||||
│00000060│ e8 00 00 00 00 00 00 00 ┊ e8 00 00 00 00 00 00 00 │Φ⋄⋄⋄⋄⋄⋄⋄┊Φ⋄⋄⋄⋄⋄⋄⋄│
|
||||
│00000070│ 00 10 00 00 00 00 00 00 ┊ 01 00 00 00 05 00 00 00 │⋄►⋄⋄⋄⋄⋄⋄┊☺⋄⋄⋄♣⋄⋄⋄│
|
||||
│00000080│ 00 10 00 00 00 00 00 00 ┊ 00 10 40 00 00 00 00 00 │⋄►⋄⋄⋄⋄⋄⋄┊⋄►@⋄⋄⋄⋄⋄│
|
||||
│00000090│ 00 10 40 00 00 00 00 00 ┊ 1d 00 00 00 00 00 00 00 │⋄►@⋄⋄⋄⋄⋄┊↔⋄⋄⋄⋄⋄⋄⋄│
|
||||
│000000a0│ 1d 00 00 00 00 00 00 00 ┊ 00 10 00 00 00 00 00 00 │↔⋄⋄⋄⋄⋄⋄⋄┊⋄►⋄⋄⋄⋄⋄⋄│
|
||||
│000000b0│ 01 00 00 00 06 00 00 00 ┊ 00 20 00 00 00 00 00 00 │☺⋄⋄⋄♠⋄⋄⋄┊⋄ ⋄⋄⋄⋄⋄⋄│
|
||||
│000000c0│ 00 20 40 00 00 00 00 00 ┊ 00 20 40 00 00 00 00 00 │⋄ @⋄⋄⋄⋄⋄┊⋄ @⋄⋄⋄⋄⋄│
|
||||
│000000d0│ 0e 00 00 00 00 00 00 00 ┊ 0e 00 00 00 00 00 00 00 │♫⋄⋄⋄⋄⋄⋄⋄┊♫⋄⋄⋄⋄⋄⋄⋄│
|
||||
│000000e0│ 00 10 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │⋄►⋄⋄⋄⋄⋄⋄┊⋄⋄⋄⋄⋄⋄⋄⋄│
|
||||
│000000f0│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄┊⋄⋄⋄⋄⋄⋄⋄⋄│
|
||||
│* │ ┊ │ ┊ │
|
||||
│00001000│ ba 0e 00 00 00 b9 00 20 ┊ 40 00 bb 01 00 00 00 b8 │║♫⋄⋄⋄╣⋄ ┊@⋄╗☺⋄⋄⋄╕│
|
||||
│00001010│ 04 00 00 00 cd 80 b8 01 ┊ 00 00 00 cd 80 00 00 00 │♦⋄⋄⋄═Ç╕☺┊⋄⋄⋄═Ç⋄⋄⋄│
|
||||
│00001020│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄┊⋄⋄⋄⋄⋄⋄⋄⋄│
|
||||
│* │ ┊ │ ┊ │
|
||||
│00002000│ 48 65 6c 6c 6f 2c 20 77 ┊ 6f 72 6c 64 21 0a 00 2e │Hello, w┊orld!◙⋄.│
|
||||
│00002010│ 73 68 73 74 72 74 61 62 ┊ 00 2e 74 65 78 74 00 2e │shstrtab┊⋄.text⋄.│
|
||||
│00002020│ 64 61 74 61 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │data⋄⋄⋄⋄┊⋄⋄⋄⋄⋄⋄⋄⋄│
|
||||
│00002030│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄┊⋄⋄⋄⋄⋄⋄⋄⋄│
|
||||
│* │ ┊ │ ┊ │
|
||||
│00002060│ 00 00 00 00 00 00 00 00 ┊ 0b 00 00 00 01 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄┊♂⋄⋄⋄☺⋄⋄⋄│
|
||||
│00002070│ 06 00 00 00 00 00 00 00 ┊ 00 10 40 00 00 00 00 00 │♠⋄⋄⋄⋄⋄⋄⋄┊⋄►@⋄⋄⋄⋄⋄│
|
||||
│00002080│ 00 10 00 00 00 00 00 00 ┊ 1d 00 00 00 00 00 00 00 │⋄►⋄⋄⋄⋄⋄⋄┊↔⋄⋄⋄⋄⋄⋄⋄│
|
||||
│00002090│ 00 00 00 00 00 00 00 00 ┊ 10 00 00 00 00 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄┊►⋄⋄⋄⋄⋄⋄⋄│
|
||||
│000020a0│ 00 00 00 00 00 00 00 00 ┊ 11 00 00 00 01 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄┊◄⋄⋄⋄☺⋄⋄⋄│
|
||||
│000020b0│ 03 00 00 00 00 00 00 00 ┊ 00 20 40 00 00 00 00 00 │♥⋄⋄⋄⋄⋄⋄⋄┊⋄ @⋄⋄⋄⋄⋄│
|
||||
│000020c0│ 00 20 00 00 00 00 00 00 ┊ 0e 00 00 00 00 00 00 00 │⋄ ⋄⋄⋄⋄⋄⋄┊♫⋄⋄⋄⋄⋄⋄⋄│
|
||||
│000020d0│ 00 00 00 00 00 00 00 00 ┊ 04 00 00 00 00 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄┊♦⋄⋄⋄⋄⋄⋄⋄│
|
||||
│000020e0│ 00 00 00 00 00 00 00 00 ┊ 01 00 00 00 03 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄┊☺⋄⋄⋄♥⋄⋄⋄│
|
||||
│000020f0│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄┊⋄⋄⋄⋄⋄⋄⋄⋄│
|
||||
│00002100│ 0e 20 00 00 00 00 00 00 ┊ 17 00 00 00 00 00 00 00 │♫ ⋄⋄⋄⋄⋄⋄┊↨⋄⋄⋄⋄⋄⋄⋄│
|
||||
│00002110│ 00 00 00 00 00 00 00 00 ┊ 01 00 00 00 00 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄┊☺⋄⋄⋄⋄⋄⋄⋄│
|
||||
│00002120│ 00 00 00 00 00 00 00 00 ┊ │⋄⋄⋄⋄⋄⋄⋄⋄┊ │
|
||||
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘
|
||||
",
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user