mirror of
https://github.com/sharkdp/hexyl.git
synced 2026-10-27 21:28:18 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bfa2726e05 | ||
|
|
d6af232691 | ||
|
|
cc6987e270 | ||
|
|
ee56a3396d | ||
|
|
4833c2afe4 | ||
|
|
dfd7bdef49 | ||
|
|
fd4aee2b85 | ||
|
|
cf8e7ec079 | ||
|
|
faa9866d11 | ||
|
|
1df35eeb63 | ||
|
|
437a15f3d6 | ||
|
|
70fa092df1 | ||
|
|
b2f0e75ed2 | ||
|
|
4fc0c1f1b0 | ||
|
|
4ce6e9d799 | ||
|
|
5bd76fd11b | ||
|
|
c7e2235293 | ||
|
|
421bd73ec1 | ||
|
|
e888021a48 | ||
|
|
7d38f70918 | ||
|
|
c6af2edda8 | ||
|
|
a7fadfaaf2 | ||
|
|
8577a17b14 | ||
|
|
2d8b600c48 | ||
|
|
f8601e5bc9 | ||
|
|
9770b89cf4 | ||
|
|
571312dd6e | ||
|
|
fcd09fffac | ||
|
|
188e753675 | ||
|
|
030235afb7 | ||
|
|
7847e8cd33 | ||
|
|
32f4ce9987 | ||
|
|
2a4b17a162 | ||
|
|
5e3c49f933 | ||
|
|
fc794b290c | ||
|
|
e6000a56f4 | ||
|
|
2861cd51ac | ||
|
|
a8cffbb6df | ||
|
|
7bb6343d2a | ||
|
|
7de17c4f35 | ||
|
|
ec61c2a789 | ||
|
|
7f7b88a914 | ||
|
|
85fa75ba67 | ||
|
|
d5d645fc48 | ||
|
|
8d3aa65134 | ||
|
|
252b4e84c3 | ||
|
|
3dc118d0ad | ||
|
|
b1ff8b6ce4 | ||
|
|
fe65792b96 | ||
|
|
31c0bcfeae | ||
|
|
c0f94ad6aa | ||
|
|
55fed5e3c0 | ||
|
|
aeee0a1033 | ||
|
|
179c8f40a2 | ||
|
|
fb2500d7d6 | ||
|
|
ad9ecda952 | ||
|
|
c43effefd6 | ||
|
|
0b6454ed9d | ||
|
|
557ae66ed5 | ||
|
|
df1afdc73f | ||
|
|
9106b899b2 | ||
|
|
df1c36e5a7 | ||
|
|
ac610f7bad | ||
|
|
767740865f | ||
|
|
1fb324f411 | ||
|
|
3d0bc3d0eb | ||
|
|
8a52261a50 | ||
|
|
ccc4fb9ba9 | ||
|
|
0baa22f152 | ||
|
|
165ced9307 | ||
|
|
3888a20dfe | ||
|
|
75b37fa125 | ||
|
|
794e1935e3 | ||
|
|
c49aa079b4 | ||
|
|
675ef6d4a8 | ||
|
|
eade38c94a | ||
|
|
98ceec18cd | ||
|
|
a49f295acc | ||
|
|
0caab15255 | ||
|
|
828fb210ce | ||
|
|
1e43783616 | ||
|
|
6b7cfefec6 | ||
|
|
5f82942f98 | ||
|
|
f6a1c4e8e3 | ||
|
|
b4fb1b079c | ||
|
|
f9f59d653d | ||
|
|
c82695f0a9 | ||
|
|
9d938b11ed | ||
|
|
d5982c0eb0 | ||
|
|
1502419ad4 | ||
|
|
f5be845d70 | ||
|
|
664025477b | ||
|
|
074bc791c2 | ||
|
|
77a4ad25f1 | ||
|
|
ca31d466ba | ||
|
|
945e7a3472 | ||
|
|
75d612ff11 | ||
|
|
15e8abfc9a | ||
|
|
b36d74ed9d | ||
|
|
094bf63f02 | ||
|
|
e0e870de27 | ||
|
|
966421c522 | ||
|
|
166c2cc46b | ||
|
|
74a5e4bc84 | ||
|
|
363ea0a586 | ||
|
|
1c4c7ed9a5 | ||
|
|
b5c224c119 | ||
|
|
d6e34d9dd2 | ||
|
|
1cb346bd13 | ||
|
|
daa40900bd | ||
|
|
d98c6edb55 | ||
|
|
73bfc68cd0 | ||
|
|
5d3f36d066 | ||
|
|
d214bc63f1 | ||
|
|
a6aeabfde4 | ||
|
|
9602667991 | ||
|
|
9ccf18f4c0 | ||
|
|
aa921ca184 | ||
|
|
4823523b7d | ||
|
|
4569c8f871 | ||
|
|
80163764c3 | ||
|
|
9bc81820e7 | ||
|
|
273ef0c045 | ||
|
|
ac1a67e90c | ||
|
|
12324d615a | ||
|
|
6b062ba127 | ||
|
|
8c7c3a073c | ||
|
|
0565901fad | ||
|
|
41b3241718 | ||
|
|
975a406d20 | ||
|
|
aa43c20f39 | ||
|
|
1fdd770093 | ||
|
|
a3fde45c18 | ||
|
|
85659a9cd6 | ||
|
|
2a4a22c9cb | ||
|
|
b820bdfeca | ||
|
|
b9348ffb1d |
No files matched your search
+112
-120
@@ -1,8 +1,8 @@
|
||||
name: CICD
|
||||
|
||||
env:
|
||||
MIN_SUPPORTED_RUST_VERSION: "1.56.0"
|
||||
CICD_INTERMEDIATES_DIR: "_cicd-intermediates"
|
||||
MSRV_FEATURES: ""
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
@@ -14,84 +14,102 @@ 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-18.04
|
||||
runs-on: ubuntu-20.04
|
||||
needs: crate_metadata
|
||||
steps:
|
||||
- name: Checkout source code
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install rust toolchain (v${{ env.MIN_SUPPORTED_RUST_VERSION }})
|
||||
uses: actions-rs/toolchain@v1
|
||||
- name: Install rust toolchain (v${{ needs.crate_metadata.outputs.msrv }})
|
||||
uses: dtolnay/rust-toolchain@master
|
||||
with:
|
||||
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
|
||||
|
||||
toolchain: ${{ needs.crate_metadata.outputs.msrv }}
|
||||
components: clippy
|
||||
- name: Run clippy (on minimum supported rust version to prevent warnings we can't fix)
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: clippy
|
||||
args: --locked --all-targets
|
||||
|
||||
run: cargo clippy --locked --all-targets ${{ env.MSRV_FEATURES }}
|
||||
- name: Run tests
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: test
|
||||
args: --locked
|
||||
run: cargo test --locked ${{ env.MSRV_FEATURES }}
|
||||
|
||||
build:
|
||||
name: ${{ matrix.job.os }} (${{ matrix.job.target }})
|
||||
name: ${{ matrix.job.target }} (${{ matrix.job.os }})
|
||||
runs-on: ${{ matrix.job.os }}
|
||||
needs: crate_metadata
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
job:
|
||||
- { 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 }
|
||||
- { 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
|
||||
steps:
|
||||
- name: Checkout source code
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install prerequisites
|
||||
shell: bash
|
||||
run: |
|
||||
case ${{ matrix.job.target }} in
|
||||
arm-unknown-linux-gnueabihf) sudo apt-get -y update ; sudo apt-get -y install gcc-arm-linux-gnueabihf ;;
|
||||
arm-unknown-linux-*) 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: Extract crate information
|
||||
shell: bash
|
||||
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
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
toolchain: stable
|
||||
target: ${{ matrix.job.target }}
|
||||
override: true
|
||||
profile: minimal # minimal component installation (ie, no documentation)
|
||||
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
|
||||
shell: bash
|
||||
run: echo "BUILD_CMD=cross" >> $GITHUB_ENV
|
||||
|
||||
- name: Show version information (Rust, cargo, GCC)
|
||||
shell: bash
|
||||
@@ -104,21 +122,16 @@ jobs:
|
||||
rustc -V
|
||||
|
||||
- name: Build
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
use-cross: ${{ matrix.job.use-cross }}
|
||||
command: build
|
||||
args: --release --target=${{ matrix.job.target }}
|
||||
shell: bash
|
||||
run: $BUILD_CMD build --locked --release --target=${{ matrix.job.target }}
|
||||
|
||||
- name: Run example
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
use-cross: ${{ matrix.job.use-cross }}
|
||||
command: run
|
||||
args: --release --target=${{ matrix.job.target }} --example=simple
|
||||
if: ${{ !matrix.job.use-cross }}
|
||||
shell: bash
|
||||
run: $BUILD_CMD run --release --target=${{ matrix.job.target }} --example=simple
|
||||
|
||||
- name: Strip debug information from executable
|
||||
id: strip
|
||||
- name: Set binary name & path
|
||||
id: bin
|
||||
shell: bash
|
||||
run: |
|
||||
# Figure out suffix of binary
|
||||
@@ -127,31 +140,13 @@ jobs:
|
||||
*-pc-windows-*) EXE_suffix=".exe" ;;
|
||||
esac;
|
||||
|
||||
# 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;
|
||||
|
||||
# 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}"
|
||||
BIN_NAME="${{ needs.crate_metadata.outputs.name }}${EXE_suffix}"
|
||||
BIN_PATH="target/${{ matrix.job.target }}/release/${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}
|
||||
# Let subsequent steps know where to find the binary
|
||||
echo "BIN_PATH=${BIN_PATH}" >> $GITHUB_OUTPUT
|
||||
echo "BIN_NAME=${BIN_NAME}" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Set testing options
|
||||
id: test-options
|
||||
@@ -159,44 +154,41 @@ 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 ${PROJECT_NAME}" ;; esac;
|
||||
echo ::set-output name=CARGO_TEST_OPTIONS::${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
|
||||
|
||||
- name: Run tests
|
||||
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}}
|
||||
shell: bash
|
||||
run: $BUILD_CMD test --locked --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/${{ env.PROJECT_NAME }}.1" "doc/${{ env.PROJECT_NAME }}.1.md"
|
||||
run: pandoc -s -f markdown -t man -o "doc/${{ needs.crate_metadata.outputs.name }}.1" "doc/${{ needs.crate_metadata.outputs.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=${PROJECT_NAME}-v${PROJECT_VERSION}-${{ matrix.job.target }}
|
||||
PKG_BASENAME=${{ needs.crate_metadata.outputs.name }}-v${{ needs.crate_metadata.outputs.version }}-${{ matrix.job.target }}
|
||||
PKG_NAME=${PKG_BASENAME}${PKG_suffix}
|
||||
echo ::set-output name=PKG_NAME::${PKG_NAME}
|
||||
echo "PKG_NAME=${PKG_NAME}" >> $GITHUB_OUTPUT
|
||||
|
||||
PKG_STAGING="${{ env.CICD_INTERMEDIATES_DIR }}/package"
|
||||
ARCHIVE_DIR="${PKG_STAGING}/${PKG_BASENAME}/"
|
||||
mkdir -p "${ARCHIVE_DIR}"
|
||||
|
||||
# Binary
|
||||
cp "${{ steps.strip.outputs.BIN_PATH }}" "$ARCHIVE_DIR"
|
||||
|
||||
# Man page
|
||||
cp "doc/${{ env.PROJECT_NAME }}.1" "$ARCHIVE_DIR"
|
||||
cp "${{ steps.bin.outputs.BIN_PATH }}" "$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
|
||||
@@ -206,7 +198,7 @@ jobs:
|
||||
popd >/dev/null
|
||||
|
||||
# Let subsequent steps know where to find the compressed package
|
||||
echo ::set-output name=PKG_PATH::"${PKG_STAGING}/${PKG_NAME}"
|
||||
echo "PKG_PATH=${PKG_STAGING}/${PKG_NAME}" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Create Debian package
|
||||
id: debian-package
|
||||
@@ -218,10 +210,10 @@ jobs:
|
||||
DPKG_DIR="${DPKG_STAGING}/dpkg"
|
||||
mkdir -p "${DPKG_DIR}"
|
||||
|
||||
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}
|
||||
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 }}
|
||||
|
||||
unset DPKG_ARCH
|
||||
case ${{ matrix.job.target }} in
|
||||
@@ -233,14 +225,14 @@ jobs:
|
||||
esac;
|
||||
|
||||
DPKG_NAME="${DPKG_BASENAME}_${DPKG_VERSION}_${DPKG_ARCH}.deb"
|
||||
echo ::set-output name=DPKG_NAME::${DPKG_NAME}
|
||||
echo "DPKG_NAME=${DPKG_NAME}" >> $GITHUB_OUTPUT
|
||||
|
||||
# Binary
|
||||
install -Dm755 "${{ steps.strip.outputs.BIN_PATH }}" "${DPKG_DIR}/usr/bin/${{ steps.strip.outputs.BIN_NAME }}"
|
||||
install -Dm755 "${{ steps.bin.outputs.BIN_PATH }}" "${DPKG_DIR}/usr/bin/${{ steps.bin.outputs.BIN_NAME }}"
|
||||
|
||||
# Man page
|
||||
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"
|
||||
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"
|
||||
|
||||
# README and LICENSE
|
||||
install -Dm644 "README.md" "${DPKG_DIR}/usr/share/doc/${DPKG_BASENAME}/README.md"
|
||||
@@ -251,12 +243,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: ${{ env.PROJECT_NAME }}
|
||||
Source: ${{ env.PROJECT_HOMEPAGE }}
|
||||
Upstream-Name: ${{ needs.crate_metadata.outputs.name }}
|
||||
Source: ${{ needs.crate_metadata.outputs.homepage }}
|
||||
|
||||
Files: *
|
||||
Copyright: ${{ env.PROJECT_MAINTAINER }}
|
||||
Copyright: $COPYRIGHT_YEARS ${{ env.PROJECT_MAINTAINER }}
|
||||
Copyright: ${{ needs.crate_metadata.outputs.maintainer }}
|
||||
Copyright: $COPYRIGHT_YEARS ${{ needs.crate_metadata.outputs.maintainer }}
|
||||
License: Apache-2.0 or MIT
|
||||
|
||||
License: Apache-2.0
|
||||
@@ -297,16 +289,16 @@ jobs:
|
||||
Version: ${DPKG_VERSION}
|
||||
Section: utils
|
||||
Priority: optional
|
||||
Maintainer: ${{ env.PROJECT_MAINTAINER }}
|
||||
Homepage: ${{ env.PROJECT_HOMEPAGE }}
|
||||
Maintainer: ${{ needs.crate_metadata.outputs.maintainer }}
|
||||
Homepage: ${{ needs.crate_metadata.outputs.homepage }}
|
||||
Architecture: ${DPKG_ARCH}
|
||||
Provides: ${{ env.PROJECT_NAME }}
|
||||
Provides: ${{ needs.crate_metadata.outputs.name }}
|
||||
Conflicts: ${DPKG_CONFLICTS}
|
||||
Description: colorized hex viewer for the terminal.
|
||||
Description: A command-line benchmarking tool
|
||||
EOF
|
||||
|
||||
DPKG_PATH="${DPKG_STAGING}/${DPKG_NAME}"
|
||||
echo ::set-output name=DPKG_PATH::${DPKG_PATH}
|
||||
echo "DPKG_PATH=${DPKG_PATH}" >> $GITHUB_OUTPUT
|
||||
|
||||
# build dpkg
|
||||
fakeroot dpkg-deb --build "${DPKG_DIR}" "${DPKG_PATH}"
|
||||
@@ -329,7 +321,7 @@ jobs:
|
||||
shell: bash
|
||||
run: |
|
||||
unset IS_RELEASE ; if [[ $GITHUB_REF =~ ^refs/tags/v[0-9].* ]]; then IS_RELEASE='true' ; fi
|
||||
echo ::set-output name=IS_RELEASE::${IS_RELEASE}
|
||||
echo "IS_RELEASE=${IS_RELEASE}" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Publish archives and packages
|
||||
uses: softprops/action-gh-release@v1
|
||||
|
||||
+33
-5
@@ -1,19 +1,47 @@
|
||||
# unreleased
|
||||
|
||||
## Changes
|
||||
|
||||
# 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)
|
||||
|
||||
## Packaging
|
||||
## Thank you
|
||||
|
||||
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
+274
-101
@@ -4,33 +4,24 @@ version = 3
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.7.18"
|
||||
version = "0.7.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f"
|
||||
checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ansi_term"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.57"
|
||||
version = "1.0.66"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc"
|
||||
checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6"
|
||||
|
||||
[[package]]
|
||||
name = "assert_cmd"
|
||||
version = "2.0.4"
|
||||
version = "2.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "93ae1ddd39efd67689deb1979d80bad3bf7f2b09c6e6117c8d1f2443b5e2f83e"
|
||||
checksum = "fa3d466004a8b4cb1bc34044240a2fd29d17607e2e3bd613eb44fd48e8100da3"
|
||||
dependencies = [
|
||||
"bstr",
|
||||
"doc-comment",
|
||||
@@ -46,7 +37,7 @@ version = "0.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"hermit-abi 0.1.19",
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
@@ -65,61 +56,82 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "bstr"
|
||||
version = "0.2.17"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223"
|
||||
checksum = "fca0852af221f458706eb0725c03e4ed6c46af9ac98e6a689d5e634215d594dd"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"memchr",
|
||||
"once_cell",
|
||||
"regex-automata",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "3.1.18"
|
||||
name = "cc"
|
||||
version = "1.0.77"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d2dbdf4bdacb33466e854ce889eee8dfd5729abf7ccd7664d0a2d60cd384440b"
|
||||
checksum = "e9f73505338f7d905b19d18738976aae232eb46b8efc15554ffc56deb5d9ebe4"
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.0.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4d63b9e9c07271b9957ad22c173bae2a4d9a81127680962039296abcd2f8251d"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"bitflags",
|
||||
"clap_lex",
|
||||
"indexmap",
|
||||
"lazy_static",
|
||||
"is-terminal",
|
||||
"once_cell",
|
||||
"strsim",
|
||||
"termcolor",
|
||||
"terminal_size",
|
||||
"textwrap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a37c35f1112dad5e6e0b1adaff798507497a18fceeb30cceb3bae7d1427b9213"
|
||||
checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8"
|
||||
dependencies = [
|
||||
"os_str_bytes",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "const_format"
|
||||
version = "0.2.23"
|
||||
version = "0.2.30"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0936ffe6d0c8d6a51b3b0a73b2acbe925d786f346cf45bfddc8341d79fb7dc8a"
|
||||
checksum = "7309d9b4d3d2c0641e018d449232f2e28f1b22933c137f157d3dbc14228b8c0e"
|
||||
dependencies = [
|
||||
"const_format_proc_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "const_format_proc_macros"
|
||||
version = "0.2.22"
|
||||
version = "0.2.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ef196d5d972878a48da7decb7686eded338b4858fbabeed513d63a7c98b2b82d"
|
||||
checksum = "d897f47bf7270cf70d370f8f98c1abb6d2d4cf60a6845d30e05bfb90c6568650"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ctor"
|
||||
version = "0.1.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[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"
|
||||
@@ -134,9 +146,30 @@ checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.6.1"
|
||||
version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
|
||||
checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797"
|
||||
|
||||
[[package]]
|
||||
name = "errno"
|
||||
version = "0.2.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1"
|
||||
dependencies = [
|
||||
"errno-dragonfly",
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "errno-dragonfly"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "float-cmp"
|
||||
@@ -147,12 +180,6 @@ dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.11.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.19"
|
||||
@@ -163,50 +190,79 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hexyl"
|
||||
version = "0.10.0"
|
||||
version = "0.12.0"
|
||||
dependencies = [
|
||||
"ansi_term",
|
||||
"anyhow",
|
||||
"assert_cmd",
|
||||
"atty",
|
||||
"clap",
|
||||
"const_format",
|
||||
"libc",
|
||||
"owo-colors",
|
||||
"predicates",
|
||||
"pretty_assertions",
|
||||
"supports-color",
|
||||
"terminal_size",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.8.1"
|
||||
name = "io-lifetimes"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0f647032dfaa1f8b6dc29bd3edb7bbef4861b8b8007ebb118d6db284fd59f6ee"
|
||||
checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"hashbrown",
|
||||
"libc",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.10.3"
|
||||
name = "is-terminal"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3"
|
||||
checksum = "927609f78c2913a6f6ac3c27a4fe87f43e2a35367c0c4b0f8265e8f49a104330"
|
||||
dependencies = [
|
||||
"hermit-abi 0.2.6",
|
||||
"io-lifetimes",
|
||||
"rustix",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "is_ci"
|
||||
version = "1.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "616cde7c720bb2bb5824a224687d8f77bfd38922027f01d825cd7453be5099fb"
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.10.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
name = "libc"
|
||||
version = "0.2.138"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.126"
|
||||
name = "linux-raw-sys"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836"
|
||||
checksum = "8f9f08d8963a6c613f4b1a78f4f4a4dbfadf8e6545b2d72861731e4858b8b47f"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
@@ -230,16 +286,37 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "os_str_bytes"
|
||||
version = "6.0.1"
|
||||
name = "once_cell"
|
||||
version = "1.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "029d8d0b2f198229de29dca79676f2738ff952edf3fde542eb8bf94d8c21b435"
|
||||
checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860"
|
||||
|
||||
[[package]]
|
||||
name = "os_str_bytes"
|
||||
version = "6.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee"
|
||||
|
||||
[[package]]
|
||||
name = "output_vt100"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "628223faebab4e3e40667ee0b2336d34a5b960ff60ea743ddfdbcf7770bcfb66"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "owo-colors"
|
||||
version = "3.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
|
||||
|
||||
[[package]]
|
||||
name = "predicates"
|
||||
version = "2.1.1"
|
||||
version = "2.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a5aab5be6e4732b473071984b3164dbbfb7a3674d30ea5ff44410b6bcd960c3c"
|
||||
checksum = "f54fc5dc63ed3bbf19494623db4f3af16842c0d975818e469022d09e53f0aa05"
|
||||
dependencies = [
|
||||
"difflib",
|
||||
"float-cmp",
|
||||
@@ -251,43 +328,55 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "predicates-core"
|
||||
version = "1.0.3"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da1c2388b1513e1b605fcec39a95e0a9e8ef088f71443ef37099fa9ae6673fcb"
|
||||
checksum = "72f883590242d3c6fc5bf50299011695fa6590c2c70eac95ee1bdb9a733ad1a2"
|
||||
|
||||
[[package]]
|
||||
name = "predicates-tree"
|
||||
version = "1.0.5"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4d86de6de25020a36c6d3643a86d9a6a9f552107c0559c60ea03551b5e16c032"
|
||||
checksum = "54ff541861505aabf6ea722d2131ee980b8276e10a1297b94e896dd8b621850d"
|
||||
dependencies = [
|
||||
"predicates-core",
|
||||
"termtree",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.39"
|
||||
name = "pretty_assertions"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f"
|
||||
checksum = "a25e9bcb20aa780fd0bb16b72403a9064d6b3f22f026946029acb941a50af755"
|
||||
dependencies = [
|
||||
"ctor",
|
||||
"diff",
|
||||
"output_vt100",
|
||||
"yansi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.47"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.18"
|
||||
version = "1.0.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1"
|
||||
checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.5.6"
|
||||
version = "1.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d83f127d94bdbcda4c8cc2e50f6f84f4b611f69c902699ca385a39c3a75f9ff1"
|
||||
checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
@@ -302,9 +391,29 @@ checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.6.26"
|
||||
version = "0.6.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64"
|
||||
checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848"
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "0.36.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a3807b5d10909833d3e9acd1eb5fb988f79376ff10fce42937de71a449c4c588"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"errno",
|
||||
"io-lifetimes",
|
||||
"libc",
|
||||
"linux-raw-sys",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.149"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "256b9932320c590e707b94576e3cc1f7c9024d0ee6612dfbcf1cb106cbe8e055"
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
@@ -313,10 +422,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.95"
|
||||
name = "supports-color"
|
||||
version = "1.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fbaf6116ab8924f39d52792136fb74fd60a80194cf1b1c6ffa6453eef1c3f942"
|
||||
checksum = "8ba6faf2ca7ee42fdd458f4347ae0a9bd6bcc445ad7cb57ad82b383f18870d6f"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"is_ci",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.105"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "60b9b43d45702de4c839cb9b51d9f529c5dd26a4aff255b42b1ebc03e88ee908"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -334,43 +453,34 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "terminal_size"
|
||||
version = "0.1.17"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df"
|
||||
checksum = "cb20089a8ba2b69debd491f8d2d023761cbf196e999218c591fa1e7e15a21907"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"winapi",
|
||||
"rustix",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termtree"
|
||||
version = "0.2.4"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "507e9898683b6c43a9aa55b64259b721b52ba226e0f3779137e50ad114a4c90b"
|
||||
|
||||
[[package]]
|
||||
name = "textwrap"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb"
|
||||
dependencies = [
|
||||
"terminal_size",
|
||||
]
|
||||
checksum = "95059e91184749cb66be6dc994f67f182b6d897cb3df74a5bf66b5e709295fd8"
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.31"
|
||||
version = "1.0.37"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a"
|
||||
checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.31"
|
||||
version = "1.0.37"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a"
|
||||
checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -379,15 +489,15 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.0"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee"
|
||||
checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.3"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04"
|
||||
checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
|
||||
|
||||
[[package]]
|
||||
name = "wait-timeout"
|
||||
@@ -428,3 +538,66 @@ 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.42.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
|
||||
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.42.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.42.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.42.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.42.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.42.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.42.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.42.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5"
|
||||
|
||||
[[package]]
|
||||
name = "yansi"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec"
|
||||
+8
-5
@@ -7,25 +7,28 @@ license = "MIT/Apache-2.0"
|
||||
name = "hexyl"
|
||||
readme = "README.md"
|
||||
repository = "https://github.com/sharkdp/hexyl"
|
||||
version = "0.10.0"
|
||||
version = "0.12.0"
|
||||
edition = "2021"
|
||||
rust-version = "1.60"
|
||||
|
||||
[dependencies]
|
||||
ansi_term = "0.12"
|
||||
anyhow = "1.0"
|
||||
atty = "0.2"
|
||||
const_format = "0.2"
|
||||
libc = "0.2"
|
||||
owo-colors = "3"
|
||||
supports-color = "1"
|
||||
thiserror = "1.0"
|
||||
terminal_size = "0.2"
|
||||
|
||||
[dependencies.clap]
|
||||
version = "3"
|
||||
version = "4"
|
||||
default-features = false
|
||||
features = ["std", "suggestions", "color", "wrap_help", "cargo"]
|
||||
features = ["std", "suggestions", "color", "wrap_help", "cargo", "help", "usage", "error-context"]
|
||||
|
||||
[dev-dependencies]
|
||||
assert_cmd = "2.0"
|
||||
predicates = "2.0"
|
||||
pretty_assertions = "1.3.0"
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
|
||||
@@ -31,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.10.0_amd64.deb # adapt version number and architecture
|
||||
sudo dpkg -i hexyl_0.12.0_amd64.deb # adapt version number and architecture
|
||||
```
|
||||
|
||||
### On Debian
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
% HEXYL(1) hexyl 0.10.0 | General Commands Manual
|
||||
% HEXYL(1) hexyl 0.12.0 | General Commands Manual
|
||||
%
|
||||
% 2022-03-23
|
||||
% 2022-12-05
|
||||
|
||||
<!--
|
||||
This man page is written in Pandoc's Markdown.
|
||||
|
||||
+10
-15
@@ -1,6 +1,6 @@
|
||||
use std::io;
|
||||
|
||||
use hexyl::{BorderStyle, Printer};
|
||||
use hexyl::{BorderStyle, PrinterBuilder};
|
||||
|
||||
fn main() {
|
||||
let input = vec![
|
||||
@@ -11,19 +11,14 @@ fn main() {
|
||||
let stdout = io::stdout();
|
||||
let mut handle = stdout.lock();
|
||||
|
||||
let show_color = true;
|
||||
let show_char_panel = true;
|
||||
let show_position_panel = true;
|
||||
let use_squeezing = false;
|
||||
let border_style = BorderStyle::Unicode;
|
||||
|
||||
let mut printer = Printer::new(
|
||||
&mut handle,
|
||||
show_color,
|
||||
show_char_panel,
|
||||
show_position_panel,
|
||||
border_style,
|
||||
use_squeezing,
|
||||
);
|
||||
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();
|
||||
printer.print_all(&input[..]).unwrap();
|
||||
}
|
||||
+216
-55
@@ -3,26 +3,26 @@ extern crate clap;
|
||||
|
||||
use std::convert::TryFrom;
|
||||
use std::fs::File;
|
||||
use std::io::{self, prelude::*, SeekFrom};
|
||||
use std::num::NonZeroI64;
|
||||
use std::io::{self, prelude::*, BufWriter, SeekFrom};
|
||||
use std::num::{NonZeroI64, NonZeroU64, NonZeroU8};
|
||||
|
||||
use clap::{crate_name, crate_version, AppSettings, Arg, ColorChoice, Command};
|
||||
use clap::builder::ArgPredicate;
|
||||
use clap::{crate_name, crate_version, Arg, ArgAction, ColorChoice, Command};
|
||||
|
||||
use atty::Stream;
|
||||
|
||||
use anyhow::{anyhow, Context, Error as AnyhowError};
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
|
||||
use const_format::formatcp;
|
||||
|
||||
use thiserror::Error as ThisError;
|
||||
|
||||
use hexyl::{BorderStyle, Input, Printer};
|
||||
use terminal_size::terminal_size;
|
||||
|
||||
use hexyl::{Base, BorderStyle, Input, PrinterBuilder};
|
||||
|
||||
const DEFAULT_BLOCK_SIZE: i64 = 512;
|
||||
|
||||
fn run() -> Result<(), AnyhowError> {
|
||||
fn run() -> Result<()> {
|
||||
let command = Command::new(crate_name!())
|
||||
.setting(AppSettings::DeriveDisplayOrder)
|
||||
.color(ColorChoice::Auto)
|
||||
.max_term_width(90)
|
||||
.version(crate_version!())
|
||||
@@ -35,7 +35,7 @@ fn run() -> Result<(), AnyhowError> {
|
||||
Arg::new("length")
|
||||
.short('n')
|
||||
.long("length")
|
||||
.takes_value(true)
|
||||
.num_args(1)
|
||||
.value_name("N")
|
||||
.help(
|
||||
"Only read N bytes from the input. The N argument can also include a \
|
||||
@@ -49,7 +49,7 @@ fn run() -> Result<(), AnyhowError> {
|
||||
Arg::new("bytes")
|
||||
.short('c')
|
||||
.long("bytes")
|
||||
.takes_value(true)
|
||||
.num_args(1)
|
||||
.value_name("N")
|
||||
.conflicts_with("length")
|
||||
.help("An alias for -n/--length"),
|
||||
@@ -57,9 +57,9 @@ fn run() -> Result<(), AnyhowError> {
|
||||
.arg(
|
||||
Arg::new("count")
|
||||
.short('l')
|
||||
.takes_value(true)
|
||||
.num_args(1)
|
||||
.value_name("N")
|
||||
.conflicts_with_all(&["length", "bytes"])
|
||||
.conflicts_with_all(["length", "bytes"])
|
||||
.hide(true)
|
||||
.help("Yet another alias for -n/--length"),
|
||||
)
|
||||
@@ -67,7 +67,7 @@ fn run() -> Result<(), AnyhowError> {
|
||||
Arg::new("skip")
|
||||
.short('s')
|
||||
.long("skip")
|
||||
.takes_value(true)
|
||||
.num_args(1)
|
||||
.value_name("N")
|
||||
.help(
|
||||
"Skip the first N bytes of the input. The N argument can also include \
|
||||
@@ -78,7 +78,7 @@ fn run() -> Result<(), AnyhowError> {
|
||||
.arg(
|
||||
Arg::new("block_size")
|
||||
.long("block-size")
|
||||
.takes_value(true)
|
||||
.num_args(1)
|
||||
.value_name("SIZE")
|
||||
.help(formatcp!(
|
||||
"Sets the size of the `block` unit to SIZE (default is {}).\n\
|
||||
@@ -90,6 +90,7 @@ fn run() -> Result<(), AnyhowError> {
|
||||
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 \
|
||||
@@ -99,49 +100,51 @@ fn run() -> Result<(), AnyhowError> {
|
||||
.arg(
|
||||
Arg::new("color")
|
||||
.long("color")
|
||||
.takes_value(true)
|
||||
.num_args(1)
|
||||
.value_name("WHEN")
|
||||
.possible_values(&["always", "auto", "never"])
|
||||
.default_value_if("plain", None, Some("never"))
|
||||
.value_parser(["always", "auto", "never"])
|
||||
.default_value_if("plain", ArgPredicate::IsPresent, Some("never"))
|
||||
.default_value("always")
|
||||
.help(
|
||||
"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")
|
||||
.takes_value(true)
|
||||
.num_args(1)
|
||||
.value_name("STYLE")
|
||||
.possible_values(&["unicode", "ascii", "none"])
|
||||
.default_value_if("plain", None, Some("none"))
|
||||
.value_parser(["unicode", "ascii", "none"])
|
||||
.default_value_if("plain", ArgPredicate::IsPresent, 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")
|
||||
.short('C')
|
||||
.long("no-characters")
|
||||
.action(ArgAction::SetFalse)
|
||||
.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")
|
||||
.takes_value(true)
|
||||
.num_args(1)
|
||||
.value_name("N")
|
||||
.help(
|
||||
"Add N bytes to the displayed file position. The N argument can also \
|
||||
@@ -149,19 +152,70 @@ fn run() -> Result<(), AnyhowError> {
|
||||
A negative value is valid and calculates an offset relative to the \
|
||||
end of the file.",
|
||||
),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("panels")
|
||||
.long("panels")
|
||||
.num_args(1)
|
||||
.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.",
|
||||
),
|
||||
)
|
||||
.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. \
|
||||
'--groupsize can be used as an alias (xxd-compatibility).",
|
||||
),
|
||||
)
|
||||
.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")
|
||||
.long("terminal-width")
|
||||
.num_args(1)
|
||||
.value_name("N")
|
||||
.conflicts_with("panels")
|
||||
.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 \
|
||||
width but still leave some space to the right.\nCannot be used with other \
|
||||
width-setting options.",
|
||||
),
|
||||
);
|
||||
|
||||
let matches = command.get_matches();
|
||||
|
||||
let stdin = io::stdin();
|
||||
|
||||
let mut reader = match matches.value_of("FILE") {
|
||||
let mut reader = match matches.get_one::<String>("FILE") {
|
||||
Some(filename) => Input::File(File::open(filename)?),
|
||||
None => Input::Stdin(stdin.lock()),
|
||||
};
|
||||
|
||||
let block_size = matches
|
||||
.value_of("block_size")
|
||||
.get_one::<String>("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| {
|
||||
@@ -186,7 +240,7 @@ fn run() -> Result<(), AnyhowError> {
|
||||
.unwrap_or_else(|| PositiveI64::new(DEFAULT_BLOCK_SIZE).unwrap());
|
||||
|
||||
let skip_arg = matches
|
||||
.value_of("skip")
|
||||
.get_one::<String>("skip")
|
||||
.map(|s| {
|
||||
parse_byte_offset(s, block_size).context(anyhow!(
|
||||
"failed to parse `--skip` arg {:?} as byte count",
|
||||
@@ -215,16 +269,16 @@ fn run() -> Result<(), AnyhowError> {
|
||||
0
|
||||
};
|
||||
|
||||
let parse_byte_count = |s| -> Result<u64, AnyhowError> {
|
||||
let parse_byte_count = |s| -> Result<u64> {
|
||||
Ok(parse_byte_offset(s, block_size)?
|
||||
.assume_forward_offset_from_start()?
|
||||
.into())
|
||||
};
|
||||
|
||||
let mut reader = if let Some(length) = matches
|
||||
.value_of("length")
|
||||
.or_else(|| matches.value_of("bytes"))
|
||||
.or_else(|| matches.value_of("count"))
|
||||
.get_one::<String>("length")
|
||||
.or_else(|| matches.get_one::<String>("bytes"))
|
||||
.or_else(|| matches.get_one::<String>("count"))
|
||||
.map(|s| {
|
||||
parse_byte_count(s).context(anyhow!(
|
||||
"failed to parse `--length` arg {:?} as byte count",
|
||||
@@ -238,26 +292,30 @@ fn run() -> Result<(), AnyhowError> {
|
||||
reader.into_inner()
|
||||
};
|
||||
|
||||
let show_color = match matches.value_of("color") {
|
||||
let show_color = match matches.get_one::<String>("color").map(String::as_ref) {
|
||||
Some("never") => false,
|
||||
Some("auto") => atty::is(Stream::Stdout),
|
||||
_ => true,
|
||||
Some("always") => true,
|
||||
_ => supports_color::on(supports_color::Stream::Stdout)
|
||||
.map(|level| level.has_basic)
|
||||
.unwrap_or(false),
|
||||
};
|
||||
|
||||
let border_style = match matches.value_of("border") {
|
||||
let border_style = match matches.get_one::<String>("border").map(String::as_ref) {
|
||||
Some("unicode") => BorderStyle::Unicode,
|
||||
Some("ascii") => BorderStyle::Ascii,
|
||||
_ => BorderStyle::None,
|
||||
};
|
||||
|
||||
let squeeze = !matches.is_present("nosqueezing");
|
||||
let &squeeze = matches.get_one::<bool>("nosqueezing").unwrap_or(&true);
|
||||
|
||||
let show_char_panel = !matches.is_present("no_chars") && !matches.is_present("plain");
|
||||
let show_char_panel = *matches.get_one::<bool>("no_chars").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 show_position_panel = *matches.get_one::<bool>("no_position").unwrap_or(&true)
|
||||
&& !matches.get_one::<bool>("plain").unwrap_or(&false);
|
||||
|
||||
let display_offset: u64 = matches
|
||||
.value_of("display_offset")
|
||||
.get_one::<String>("display_offset")
|
||||
.map(|s| {
|
||||
parse_byte_count(s).context(anyhow!(
|
||||
"failed to parse `--display-offset` arg {:?} as byte count",
|
||||
@@ -267,17 +325,119 @@ fn run() -> Result<(), AnyhowError> {
|
||||
.transpose()?
|
||||
.unwrap_or(0);
|
||||
|
||||
let stdout = io::stdout();
|
||||
let mut stdout_lock = stdout.lock();
|
||||
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
|
||||
} else {
|
||||
((8 / group_size) * (base_digits * group_size + 1)) + 2
|
||||
};
|
||||
if (terminal_width - offset) / col_width < 1 {
|
||||
1
|
||||
} else {
|
||||
(terminal_width - offset) / col_width
|
||||
}
|
||||
};
|
||||
|
||||
let mut printer = Printer::new(
|
||||
&mut stdout_lock,
|
||||
show_color,
|
||||
show_char_panel,
|
||||
show_position_panel,
|
||||
border_style,
|
||||
squeeze,
|
||||
);
|
||||
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.")),
|
||||
}
|
||||
} 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\"."))
|
||||
}
|
||||
}
|
||||
}).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 stdout = io::stdout();
|
||||
let mut stdout_lock = BufWriter::new(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)
|
||||
.build();
|
||||
printer.display_offset(skip_offset + display_offset);
|
||||
printer.print_all(&mut reader).map_err(|e| anyhow!(e))?;
|
||||
|
||||
@@ -285,14 +445,15 @@ fn run() -> Result<(), AnyhowError> {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Enable ANSI support for Windows
|
||||
#[cfg(windows)]
|
||||
let _ = ansi_term::enable_ansi_support();
|
||||
|
||||
let result = run();
|
||||
|
||||
if let Err(err) = result {
|
||||
eprintln!("Error: {:?}", err);
|
||||
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:?}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
+566
-268
@@ -1,23 +1,25 @@
|
||||
pub(crate) mod input;
|
||||
pub mod squeezer;
|
||||
|
||||
pub use input::*;
|
||||
|
||||
use std::io::{self, Read, Write};
|
||||
use std::io::{self, BufReader, Read, Write};
|
||||
|
||||
use ansi_term::Color;
|
||||
use ansi_term::Color::Fixed;
|
||||
use owo_colors::{colors, Color};
|
||||
|
||||
use crate::squeezer::{SqueezeAction, Squeezer};
|
||||
pub enum Base {
|
||||
Binary,
|
||||
Octal,
|
||||
Decimal,
|
||||
Hexadecimal,
|
||||
}
|
||||
|
||||
const BUFFER_SIZE: usize = 256;
|
||||
|
||||
const COLOR_NULL: Color = Fixed(242); // grey
|
||||
const COLOR_OFFSET: Color = Fixed(242); // grey
|
||||
const COLOR_ASCII_PRINTABLE: Color = Color::Cyan;
|
||||
const COLOR_ASCII_WHITESPACE: Color = Color::Green;
|
||||
const COLOR_ASCII_OTHER: Color = Color::Purple;
|
||||
const COLOR_NONASCII: Color = Color::Yellow;
|
||||
const COLOR_NULL: &[u8] = colors::BrightBlack::ANSI_FG.as_bytes();
|
||||
const COLOR_OFFSET: &[u8] = colors::BrightBlack::ANSI_FG.as_bytes();
|
||||
const COLOR_ASCII_PRINTABLE: &[u8] = colors::Cyan::ANSI_FG.as_bytes();
|
||||
const COLOR_ASCII_WHITESPACE: &[u8] = colors::Green::ANSI_FG.as_bytes();
|
||||
const COLOR_ASCII_OTHER: &[u8] = colors::Green::ANSI_FG.as_bytes();
|
||||
const COLOR_NONASCII: &[u8] = colors::Yellow::ANSI_FG.as_bytes();
|
||||
const COLOR_RESET: &[u8] = colors::Default::ANSI_FG.as_bytes();
|
||||
|
||||
pub enum ByteCategory {
|
||||
Null,
|
||||
@@ -27,6 +29,14 @@ pub enum ByteCategory {
|
||||
NonAscii,
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
enum Squeezer {
|
||||
Print,
|
||||
Delete,
|
||||
Ignore,
|
||||
Disabled,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
struct Byte(u8);
|
||||
|
||||
@@ -45,15 +55,15 @@ impl Byte {
|
||||
}
|
||||
}
|
||||
|
||||
fn color(self) -> &'static Color {
|
||||
fn color(self) -> &'static [u8] {
|
||||
use crate::ByteCategory::*;
|
||||
|
||||
match self.category() {
|
||||
Null => &COLOR_NULL,
|
||||
AsciiPrintable => &COLOR_ASCII_PRINTABLE,
|
||||
AsciiWhitespace => &COLOR_ASCII_WHITESPACE,
|
||||
AsciiOther => &COLOR_ASCII_OTHER,
|
||||
NonAscii => &COLOR_NONASCII,
|
||||
Null => COLOR_NULL,
|
||||
AsciiPrintable => COLOR_ASCII_PRINTABLE,
|
||||
AsciiWhitespace => COLOR_ASCII_WHITESPACE,
|
||||
AsciiOther => COLOR_ASCII_OTHER,
|
||||
NonAscii => COLOR_NONASCII,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +71,7 @@ impl Byte {
|
||||
use crate::ByteCategory::*;
|
||||
|
||||
match self.category() {
|
||||
Null => '0',
|
||||
Null => '⋄',
|
||||
AsciiPrintable => self.0 as char,
|
||||
AsciiWhitespace if self.0 == 0x20 => ' ',
|
||||
AsciiWhitespace => '_',
|
||||
@@ -78,6 +88,7 @@ struct BorderElements {
|
||||
right_corner: char,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum BorderStyle {
|
||||
Unicode,
|
||||
Ascii,
|
||||
@@ -138,69 +149,161 @@ impl BorderStyle {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Printer<'a, Writer: Write> {
|
||||
idx: u64,
|
||||
/// The raw bytes used as input for the current line.
|
||||
raw_line: Vec<u8>,
|
||||
/// The buffered line built with each byte, ready to print to writer.
|
||||
buffer_line: Vec<u8>,
|
||||
pub struct PrinterBuilder<'a, Writer: Write> {
|
||||
writer: &'a mut Writer,
|
||||
show_color: bool,
|
||||
show_char_panel: bool,
|
||||
show_position_panel: bool,
|
||||
border_style: BorderStyle,
|
||||
header_was_printed: bool,
|
||||
use_squeeze: bool,
|
||||
panels: u64,
|
||||
group_size: u8,
|
||||
base: Base,
|
||||
}
|
||||
|
||||
impl<'a, Writer: Write> PrinterBuilder<'a, Writer> {
|
||||
pub fn new(writer: &'a mut Writer) -> Self {
|
||||
PrinterBuilder {
|
||||
writer,
|
||||
show_color: true,
|
||||
show_char_panel: true,
|
||||
show_position_panel: true,
|
||||
border_style: BorderStyle::Unicode,
|
||||
use_squeeze: true,
|
||||
panels: 2,
|
||||
group_size: 1,
|
||||
base: Base::Hexadecimal,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn show_color(mut self, show_color: bool) -> Self {
|
||||
self.show_color = show_color;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn show_char_panel(mut self, show_char_panel: bool) -> Self {
|
||||
self.show_char_panel = show_char_panel;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn show_position_panel(mut self, show_position_panel: bool) -> Self {
|
||||
self.show_position_panel = show_position_panel;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_border_style(mut self, border_style: BorderStyle) -> Self {
|
||||
self.border_style = border_style;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn enable_squeezing(mut self, enable: bool) -> Self {
|
||||
self.use_squeeze = enable;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn num_panels(mut self, num: u64) -> Self {
|
||||
self.panels = num;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn group_size(mut self, num: u8) -> Self {
|
||||
self.group_size = num;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_base(mut self, base: Base) -> Self {
|
||||
self.base = base;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build(self) -> Printer<'a, Writer> {
|
||||
Printer::new(
|
||||
self.writer,
|
||||
self.show_color,
|
||||
self.show_char_panel,
|
||||
self.show_position_panel,
|
||||
self.border_style,
|
||||
self.use_squeeze,
|
||||
self.panels,
|
||||
self.group_size,
|
||||
self.base,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Printer<'a, Writer: Write> {
|
||||
idx: u64,
|
||||
/// the buffer containing all the bytes in a line for character printing
|
||||
line_buf: Vec<u8>,
|
||||
writer: &'a mut Writer,
|
||||
show_char_panel: bool,
|
||||
show_position_panel: bool,
|
||||
show_color: bool,
|
||||
curr_color: Option<&'static [u8]>,
|
||||
border_style: BorderStyle,
|
||||
byte_hex_panel: Vec<String>,
|
||||
byte_char_panel: Vec<String>,
|
||||
// same as previous but in Fixed(242) gray color, for position panel
|
||||
byte_hex_panel_g: Vec<String>,
|
||||
squeezer: Squeezer,
|
||||
display_offset: u64,
|
||||
/// The number of panels to draw.
|
||||
panels: u64,
|
||||
squeeze_byte: usize,
|
||||
/// The number of octets per group.
|
||||
group_size: u8,
|
||||
/// The number of digits used to write the base.
|
||||
base_digits: u8,
|
||||
}
|
||||
|
||||
impl<'a, Writer: Write> Printer<'a, Writer> {
|
||||
pub fn new(
|
||||
fn new(
|
||||
writer: &'a mut Writer,
|
||||
show_color: bool,
|
||||
show_char_panel: bool,
|
||||
show_position_panel: bool,
|
||||
border_style: BorderStyle,
|
||||
use_squeeze: bool,
|
||||
panels: u64,
|
||||
group_size: u8,
|
||||
base: Base,
|
||||
) -> Printer<'a, Writer> {
|
||||
Printer {
|
||||
idx: 1,
|
||||
raw_line: vec![],
|
||||
buffer_line: vec![],
|
||||
idx: 0,
|
||||
line_buf: vec![0x0; 8 * panels as usize],
|
||||
writer,
|
||||
show_color,
|
||||
show_char_panel,
|
||||
show_position_panel,
|
||||
show_color,
|
||||
curr_color: None,
|
||||
border_style,
|
||||
header_was_printed: false,
|
||||
byte_hex_panel: (0u8..=u8::max_value())
|
||||
.map(|i| {
|
||||
let byte_hex = format!("{:02x} ", i);
|
||||
if show_color {
|
||||
Byte(i).color().paint(byte_hex).to_string()
|
||||
} else {
|
||||
byte_hex
|
||||
}
|
||||
byte_hex_panel: (0u8..=u8::MAX)
|
||||
.map(|i| match base {
|
||||
Base::Binary => format!("{i:08b}"),
|
||||
Base::Octal => format!("{i:03o}"),
|
||||
Base::Decimal => format!("{i:03}"),
|
||||
Base::Hexadecimal => format!("{i:02x}"),
|
||||
})
|
||||
.collect(),
|
||||
byte_char_panel: show_char_panel
|
||||
.then(|| {
|
||||
(0u8..=u8::max_value())
|
||||
.map(|i| {
|
||||
let byte_char = format!("{}", Byte(i).as_char());
|
||||
if show_color {
|
||||
Byte(i).color().paint(byte_char).to_string()
|
||||
} else {
|
||||
byte_char
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default(),
|
||||
squeezer: Squeezer::new(use_squeeze),
|
||||
byte_char_panel: (0u8..=u8::MAX)
|
||||
.map(|i| format!("{}", Byte(i).as_char()))
|
||||
.collect(),
|
||||
byte_hex_panel_g: (0u8..=u8::MAX).map(|i| format!("{i:02x}")).collect(),
|
||||
squeezer: if use_squeeze {
|
||||
Squeezer::Ignore
|
||||
} else {
|
||||
Squeezer::Disabled
|
||||
},
|
||||
display_offset: 0,
|
||||
panels,
|
||||
squeeze_byte: 0x00,
|
||||
group_size,
|
||||
base_digits: match base {
|
||||
Base::Binary => 8,
|
||||
Base::Octal => 3,
|
||||
Base::Decimal => 3,
|
||||
Base::Hexadecimal => 2,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,267 +312,352 @@ impl<'a, Writer: Write> Printer<'a, Writer> {
|
||||
self
|
||||
}
|
||||
|
||||
fn write_border(&mut self, border_elements: BorderElements) {
|
||||
fn panel_sz(&self) -> usize {
|
||||
// add one to include the trailing space of a group
|
||||
let group_sz = self.base_digits as usize * self.group_size as usize + 1;
|
||||
let group_per_panel = 8 / self.group_size as usize;
|
||||
// add one to include the leading space
|
||||
1 + group_sz * group_per_panel
|
||||
}
|
||||
|
||||
fn write_border(&mut self, border_elements: BorderElements) -> io::Result<()> {
|
||||
let h = border_elements.horizontal_line;
|
||||
let c = border_elements.column_separator;
|
||||
let l = border_elements.left_corner;
|
||||
let r = border_elements.right_corner;
|
||||
let h8 = h.to_string().repeat(8);
|
||||
let h25 = h.to_string().repeat(25);
|
||||
let h_repeat = h.to_string().repeat(self.panel_sz());
|
||||
|
||||
if self.show_position_panel {
|
||||
write!(self.writer, "{l}{h8}{c}", l = l, c = c, h8 = h8).ok();
|
||||
write!(self.writer, "{l}{h8}{c}")?;
|
||||
} else {
|
||||
write!(self.writer, "{}", l).ok();
|
||||
write!(self.writer, "{l}")?;
|
||||
}
|
||||
|
||||
write!(self.writer, "{h25}{c}{h25}", c = c, h25 = h25).ok();
|
||||
for _ in 0..self.panels - 1 {
|
||||
write!(self.writer, "{h_repeat}{c}")?;
|
||||
}
|
||||
if self.show_char_panel {
|
||||
write!(self.writer, "{h_repeat}{c}")?;
|
||||
} else {
|
||||
write!(self.writer, "{h_repeat}")?;
|
||||
}
|
||||
|
||||
if self.show_char_panel {
|
||||
writeln!(self.writer, "{c}{h8}{c}{h8}{r}", c = c, h8 = h8, r = r).ok();
|
||||
for _ in 0..self.panels - 1 {
|
||||
write!(self.writer, "{h8}{c}")?;
|
||||
}
|
||||
writeln!(self.writer, "{h8}{r}")?;
|
||||
} else {
|
||||
writeln!(self.writer, "{r}", r = r).ok();
|
||||
writeln!(self.writer, "{r}")?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn print_header(&mut self) {
|
||||
if self.header_was_printed {
|
||||
return;
|
||||
}
|
||||
pub fn print_header(&mut self) -> io::Result<()> {
|
||||
if let Some(e) = self.border_style.header_elems() {
|
||||
self.write_border(e)
|
||||
self.write_border(e)?
|
||||
}
|
||||
self.header_was_printed = true;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn print_footer(&mut self) {
|
||||
pub fn print_footer(&mut self) -> io::Result<()> {
|
||||
if let Some(e) = self.border_style.footer_elems() {
|
||||
self.write_border(e)
|
||||
self.write_border(e)?
|
||||
}
|
||||
}
|
||||
|
||||
fn print_position_panel(&mut self) {
|
||||
if !self.show_position_panel {
|
||||
write!(&mut self.buffer_line, "{} ", self.border_style.outer_sep()).ok();
|
||||
return;
|
||||
}
|
||||
|
||||
let style = COLOR_OFFSET.normal();
|
||||
let byte_index = format!("{:08x}", self.idx - 1 + self.display_offset);
|
||||
let formatted_string = if self.show_color {
|
||||
format!("{}", style.paint(byte_index))
|
||||
} else {
|
||||
byte_index
|
||||
};
|
||||
let _ = write!(
|
||||
&mut self.buffer_line,
|
||||
"{}{}{} ",
|
||||
self.border_style.outer_sep(),
|
||||
formatted_string,
|
||||
self.border_style.outer_sep()
|
||||
);
|
||||
}
|
||||
|
||||
pub fn print_char_panel(&mut self) {
|
||||
if !self.show_char_panel {
|
||||
// just write newline if character panel is hidden
|
||||
writeln!(&mut self.buffer_line).ok();
|
||||
return;
|
||||
}
|
||||
|
||||
let len = self.raw_line.len();
|
||||
|
||||
let mut idx = 1;
|
||||
for &b in self.raw_line.iter() {
|
||||
let _ = write!(
|
||||
&mut self.buffer_line,
|
||||
"{}",
|
||||
self.byte_char_panel[b as usize]
|
||||
);
|
||||
|
||||
if idx == 8 {
|
||||
let _ = write!(&mut self.buffer_line, "{}", self.border_style.inner_sep());
|
||||
}
|
||||
|
||||
idx += 1;
|
||||
}
|
||||
|
||||
if len < 8 {
|
||||
let _ = writeln!(
|
||||
&mut self.buffer_line,
|
||||
"{0:1$}{3}{0:2$}{4}",
|
||||
"",
|
||||
8 - len,
|
||||
8,
|
||||
self.border_style.inner_sep(),
|
||||
self.border_style.outer_sep(),
|
||||
);
|
||||
} else {
|
||||
let _ = writeln!(
|
||||
&mut self.buffer_line,
|
||||
"{0:1$}{2}",
|
||||
"",
|
||||
16 - len,
|
||||
self.border_style.outer_sep()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn print_byte(&mut self, b: u8) -> io::Result<()> {
|
||||
if self.idx % 16 == 1 {
|
||||
self.print_header();
|
||||
self.print_position_panel();
|
||||
}
|
||||
|
||||
write!(&mut self.buffer_line, "{}", self.byte_hex_panel[b as usize])?;
|
||||
self.raw_line.push(b);
|
||||
|
||||
self.squeezer.process(b, self.idx);
|
||||
|
||||
match self.idx % 16 {
|
||||
8 => {
|
||||
let _ = write!(&mut self.buffer_line, "{} ", self.border_style.inner_sep());
|
||||
}
|
||||
0 => {
|
||||
self.print_textline()?;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
self.idx += 1;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn print_textline(&mut self) -> io::Result<()> {
|
||||
let len = self.raw_line.len();
|
||||
|
||||
if len == 0 {
|
||||
if self.squeezer.active() {
|
||||
self.print_position_panel();
|
||||
let _ = writeln!(
|
||||
&mut self.buffer_line,
|
||||
"{0:1$}{4}{0:2$}{5}{0:3$}{4}{0:3$}{5}",
|
||||
"",
|
||||
24,
|
||||
25,
|
||||
8,
|
||||
self.border_style.inner_sep(),
|
||||
self.border_style.outer_sep(),
|
||||
);
|
||||
self.writer.write_all(&self.buffer_line)?;
|
||||
}
|
||||
return Ok(());
|
||||
fn print_position_panel(&mut self) -> io::Result<()> {
|
||||
self.writer.write_all(
|
||||
self.border_style
|
||||
.outer_sep()
|
||||
.encode_utf8(&mut [0; 4])
|
||||
.as_bytes(),
|
||||
)?;
|
||||
if self.show_color {
|
||||
self.writer.write_all(COLOR_OFFSET)?;
|
||||
}
|
||||
|
||||
let squeeze_action = self.squeezer.action();
|
||||
|
||||
if squeeze_action != SqueezeAction::Delete {
|
||||
if len < 8 {
|
||||
let _ = write!(
|
||||
&mut self.buffer_line,
|
||||
"{0:1$}{3}{0:2$}{4}",
|
||||
"",
|
||||
3 * (8 - len),
|
||||
1 + 3 * 8,
|
||||
self.border_style.inner_sep(),
|
||||
self.border_style.outer_sep(),
|
||||
);
|
||||
} else {
|
||||
let _ = write!(
|
||||
&mut self.buffer_line,
|
||||
"{0:1$}{2}",
|
||||
"",
|
||||
3 * (16 - len),
|
||||
self.border_style.outer_sep()
|
||||
);
|
||||
if self.show_position_panel {
|
||||
match self.squeezer {
|
||||
Squeezer::Print => {
|
||||
self.writer
|
||||
.write_all(self.byte_char_panel[b'*' as usize].as_bytes())?;
|
||||
if self.show_color {
|
||||
self.writer.write_all(COLOR_RESET)?;
|
||||
}
|
||||
self.writer.write_all(b" ")?;
|
||||
}
|
||||
Squeezer::Ignore | Squeezer::Disabled | Squeezer::Delete => {
|
||||
let byte_index: [u8; 8] = (self.idx + self.display_offset).to_be_bytes();
|
||||
let mut i = 0;
|
||||
while byte_index[i] == 0x0 && i < 4 {
|
||||
i += 1;
|
||||
}
|
||||
for &byte in byte_index.iter().skip(i) {
|
||||
self.writer
|
||||
.write_all(self.byte_hex_panel_g[byte as usize].as_bytes())?;
|
||||
}
|
||||
if self.show_color {
|
||||
self.writer.write_all(COLOR_RESET)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
self.writer.write_all(
|
||||
self.border_style
|
||||
.outer_sep()
|
||||
.encode_utf8(&mut [0; 4])
|
||||
.as_bytes(),
|
||||
)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
self.print_char_panel();
|
||||
|
||||
match squeeze_action {
|
||||
SqueezeAction::Print => {
|
||||
self.buffer_line.clear();
|
||||
let style = COLOR_OFFSET.normal();
|
||||
let asterisk = if self.show_color {
|
||||
format!("{}", style.paint("*"))
|
||||
fn print_char(&mut self, i: u64) -> io::Result<()> {
|
||||
match self.squeezer {
|
||||
Squeezer::Print | Squeezer::Delete => self.writer.write_all(b" ")?,
|
||||
Squeezer::Ignore | Squeezer::Disabled => {
|
||||
if let Some(&b) = self.line_buf.get(i as usize) {
|
||||
if self.show_color && self.curr_color != Some(Byte(b).color()) {
|
||||
self.writer.write_all(Byte(b).color())?;
|
||||
self.curr_color = Some(Byte(b).color());
|
||||
}
|
||||
self.writer
|
||||
.write_all(self.byte_char_panel[b as usize].as_bytes())?;
|
||||
} else {
|
||||
String::from("*")
|
||||
};
|
||||
let _ = writeln!(
|
||||
&mut self.buffer_line,
|
||||
"{5}{0}{1:2$}{5}{1:3$}{6}{1:3$}{5}{1:4$}{6}{1:4$}{5}",
|
||||
asterisk,
|
||||
"",
|
||||
7,
|
||||
25,
|
||||
8,
|
||||
self.border_style.outer_sep(),
|
||||
self.border_style.inner_sep(),
|
||||
);
|
||||
self.squeezer = Squeezer::Print;
|
||||
}
|
||||
}
|
||||
SqueezeAction::Delete => self.buffer_line.clear(),
|
||||
SqueezeAction::Ignore => (),
|
||||
}
|
||||
|
||||
self.writer.write_all(&self.buffer_line)?;
|
||||
|
||||
self.raw_line.clear();
|
||||
self.buffer_line.clear();
|
||||
|
||||
self.squeezer.advance();
|
||||
if i == 8 * self.panels - 1 {
|
||||
if self.show_color {
|
||||
self.writer.write_all(COLOR_RESET)?;
|
||||
self.curr_color = None;
|
||||
}
|
||||
self.writer.write_all(
|
||||
self.border_style
|
||||
.outer_sep()
|
||||
.encode_utf8(&mut [0; 4])
|
||||
.as_bytes(),
|
||||
)?;
|
||||
} else if i % 8 == 7 {
|
||||
if self.show_color {
|
||||
self.writer.write_all(COLOR_RESET)?;
|
||||
self.curr_color = None;
|
||||
}
|
||||
self.writer.write_all(
|
||||
self.border_style
|
||||
.inner_sep()
|
||||
.encode_utf8(&mut [0; 4])
|
||||
.as_bytes(),
|
||||
)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn header_was_printed(&self) -> bool {
|
||||
self.header_was_printed
|
||||
pub fn print_char_panel(&mut self) -> io::Result<()> {
|
||||
for i in 0..self.line_buf.len() {
|
||||
self.print_char(i as u64)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn print_byte(&mut self, i: usize, b: u8) -> io::Result<()> {
|
||||
match self.squeezer {
|
||||
Squeezer::Print => {
|
||||
if !self.show_position_panel && i == 0 {
|
||||
if self.show_color {
|
||||
self.writer.write_all(COLOR_OFFSET)?;
|
||||
}
|
||||
self.writer
|
||||
.write_all(self.byte_char_panel[b'*' as usize].as_bytes())?;
|
||||
if self.show_color {
|
||||
self.writer.write_all(COLOR_RESET)?;
|
||||
}
|
||||
} else if i % (self.group_size as usize) == 0 {
|
||||
self.writer.write_all(b" ")?;
|
||||
}
|
||||
for _ in 0..self.base_digits {
|
||||
self.writer.write_all(b" ")?;
|
||||
}
|
||||
}
|
||||
Squeezer::Delete => self.writer.write_all(b" ")?,
|
||||
Squeezer::Ignore | Squeezer::Disabled => {
|
||||
if i % (self.group_size as usize) == 0 {
|
||||
self.writer.write_all(b" ")?;
|
||||
}
|
||||
if self.show_color && self.curr_color != Some(Byte(b).color()) {
|
||||
self.writer.write_all(Byte(b).color())?;
|
||||
self.curr_color = Some(Byte(b).color());
|
||||
}
|
||||
self.writer
|
||||
.write_all(self.byte_hex_panel[b as usize].as_bytes())?;
|
||||
}
|
||||
}
|
||||
// byte is last in panel
|
||||
if i % 8 == 7 {
|
||||
if self.show_color {
|
||||
self.curr_color = None;
|
||||
self.writer.write_all(COLOR_RESET)?;
|
||||
}
|
||||
self.writer.write_all(b" ")?;
|
||||
// byte is last in last panel
|
||||
if i as u64 % (8 * self.panels) == 8 * self.panels - 1 {
|
||||
self.writer.write_all(
|
||||
self.border_style
|
||||
.outer_sep()
|
||||
.encode_utf8(&mut [0; 4])
|
||||
.as_bytes(),
|
||||
)?;
|
||||
} else {
|
||||
self.writer.write_all(
|
||||
self.border_style
|
||||
.inner_sep()
|
||||
.encode_utf8(&mut [0; 4])
|
||||
.as_bytes(),
|
||||
)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn print_bytes(&mut self) -> io::Result<()> {
|
||||
for (i, &b) in self.line_buf.clone().iter().enumerate() {
|
||||
self.print_byte(i, b)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Loop through the given `Reader`, printing until the `Reader` buffer
|
||||
/// is exhausted.
|
||||
pub fn print_all<Reader: Read>(
|
||||
&mut self,
|
||||
mut reader: Reader,
|
||||
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
let mut buffer = [0; BUFFER_SIZE];
|
||||
'mainloop: loop {
|
||||
let size = reader.read(&mut buffer)?;
|
||||
if size == 0 {
|
||||
break;
|
||||
}
|
||||
pub fn print_all<Reader: Read>(&mut self, reader: Reader) -> io::Result<()> {
|
||||
let mut is_empty = true;
|
||||
|
||||
for b in &buffer[..size] {
|
||||
let res = self.print_byte(*b);
|
||||
let mut buf = BufReader::new(reader);
|
||||
|
||||
if res.is_err() {
|
||||
// Broken pipe
|
||||
break 'mainloop;
|
||||
let leftover = loop {
|
||||
// read a maximum of 8 * self.panels bytes from the reader
|
||||
if let Ok(n) = buf.read(&mut self.line_buf) {
|
||||
if n > 0 && n < 8 * self.panels as usize {
|
||||
// if less are read, that indicates end of file after
|
||||
if is_empty {
|
||||
self.print_header()?;
|
||||
is_empty = false;
|
||||
}
|
||||
|
||||
// perform second check on read
|
||||
if let Ok(0) = buf.read(&mut self.line_buf[n..]) {
|
||||
self.line_buf.resize(n, 0);
|
||||
break Some(n);
|
||||
};
|
||||
} else if n == 0 {
|
||||
// if no bytes are read, that indicates end of file
|
||||
if self.squeezer == Squeezer::Delete {
|
||||
// empty the last line when ending is squeezed
|
||||
self.line_buf.clear();
|
||||
break Some(0);
|
||||
}
|
||||
break None;
|
||||
}
|
||||
}
|
||||
}
|
||||
if is_empty {
|
||||
self.print_header()?;
|
||||
is_empty = false;
|
||||
}
|
||||
|
||||
// Finish last line
|
||||
self.print_textline().ok();
|
||||
// squeeze is active, check if the line is the same
|
||||
// skip print if still squeezed, otherwise print and deactivate squeeze
|
||||
if matches!(self.squeezer, Squeezer::Print | Squeezer::Delete) {
|
||||
if self
|
||||
.line_buf
|
||||
.chunks_exact(std::mem::size_of::<usize>())
|
||||
.all(|w| usize::from_ne_bytes(w.try_into().unwrap()) == self.squeeze_byte)
|
||||
{
|
||||
if self.squeezer == Squeezer::Delete {
|
||||
self.idx += 8 * self.panels;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
self.squeezer = Squeezer::Ignore;
|
||||
}
|
||||
}
|
||||
|
||||
if !self.header_was_printed() {
|
||||
self.print_header();
|
||||
// print the line
|
||||
self.print_position_panel()?;
|
||||
self.print_bytes()?;
|
||||
if self.show_char_panel {
|
||||
self.print_char_panel()?;
|
||||
}
|
||||
self.writer.write_all(b"\n")?;
|
||||
|
||||
// increment index to next line
|
||||
self.idx += 8 * self.panels;
|
||||
|
||||
// change from print to delete if squeeze is still active
|
||||
if self.squeezer == Squeezer::Print {
|
||||
self.squeezer = Squeezer::Delete;
|
||||
}
|
||||
|
||||
// repeat the first byte in the line until it's a usize
|
||||
// compare that usize with each usize chunk in the line
|
||||
// if they are all the same, change squeezer to print
|
||||
let repeat_byte = (self.line_buf[0] as usize) * (usize::MAX / 255);
|
||||
if !matches!(self.squeezer, Squeezer::Disabled | Squeezer::Delete)
|
||||
&& self
|
||||
.line_buf
|
||||
.chunks_exact(std::mem::size_of::<usize>())
|
||||
.all(|w| usize::from_ne_bytes(w.try_into().unwrap()) == repeat_byte)
|
||||
{
|
||||
self.squeezer = Squeezer::Print;
|
||||
self.squeeze_byte = repeat_byte;
|
||||
};
|
||||
};
|
||||
|
||||
// special ending
|
||||
|
||||
if is_empty {
|
||||
self.base_digits = 2;
|
||||
self.print_header()?;
|
||||
if self.show_position_panel {
|
||||
write!(self.writer, "{0:9}", "│").ok();
|
||||
write!(self.writer, "{0:9}", "│")?;
|
||||
}
|
||||
write!(
|
||||
self.writer,
|
||||
"{0:2}{1:24}{0}{0:>26}",
|
||||
"│", "No content to print"
|
||||
)
|
||||
.ok();
|
||||
"{0:2}{1:2$}{0}{0:>3$}",
|
||||
"│",
|
||||
"No content",
|
||||
self.panel_sz() - 1,
|
||||
self.panel_sz() + 1,
|
||||
)?;
|
||||
if self.show_char_panel {
|
||||
write!(self.writer, "{0:>9}{0:>9}", "│").ok();
|
||||
write!(self.writer, "{0:>9}{0:>9}", "│")?;
|
||||
}
|
||||
writeln!(self.writer).ok();
|
||||
writeln!(self.writer)?;
|
||||
} else if let Some(n) = leftover {
|
||||
// last line is incomplete
|
||||
self.print_position_panel()?;
|
||||
self.squeezer = Squeezer::Ignore;
|
||||
self.print_bytes()?;
|
||||
self.squeezer = Squeezer::Print;
|
||||
for i in n..8 * self.panels as usize {
|
||||
self.print_byte(i, 0)?;
|
||||
}
|
||||
if self.show_char_panel {
|
||||
self.squeezer = Squeezer::Ignore;
|
||||
self.print_char_panel()?;
|
||||
self.squeezer = Squeezer::Print;
|
||||
for i in n..8 * self.panels as usize {
|
||||
self.print_char(i as u64)?;
|
||||
}
|
||||
}
|
||||
self.writer.write_all(b"\n")?;
|
||||
}
|
||||
self.print_footer();
|
||||
|
||||
self.print_footer()?;
|
||||
|
||||
self.writer.flush()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -484,7 +672,17 @@ mod tests {
|
||||
|
||||
fn assert_print_all_output<Reader: Read>(input: Reader, expected_string: String) {
|
||||
let mut output = vec![];
|
||||
let mut printer = Printer::new(&mut output, false, true, true, BorderStyle::Unicode, true);
|
||||
let mut printer = Printer::new(
|
||||
&mut output,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
BorderStyle::Unicode,
|
||||
true,
|
||||
2,
|
||||
1,
|
||||
Base::Hexadecimal,
|
||||
);
|
||||
|
||||
printer.print_all(input).unwrap();
|
||||
|
||||
@@ -497,7 +695,7 @@ mod tests {
|
||||
let input = io::empty();
|
||||
let expected_string = "\
|
||||
┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐
|
||||
│ │ No content to print │ │ │ │
|
||||
│ │ No content │ │ │ │
|
||||
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘
|
||||
"
|
||||
.to_owned();
|
||||
@@ -528,8 +726,17 @@ mod tests {
|
||||
.to_owned();
|
||||
|
||||
let mut output = vec![];
|
||||
let mut printer: Printer<Vec<u8>> =
|
||||
Printer::new(&mut output, false, true, true, BorderStyle::Unicode, true);
|
||||
let mut printer: Printer<Vec<u8>> = Printer::new(
|
||||
&mut output,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
BorderStyle::Unicode,
|
||||
true,
|
||||
2,
|
||||
1,
|
||||
Base::Hexadecimal,
|
||||
);
|
||||
printer.display_offset(0xdeadbeef);
|
||||
|
||||
printer.print_all(input).unwrap();
|
||||
@@ -537,4 +744,95 @@ mod tests {
|
||||
let actual_string: &str = str::from_utf8(&output).unwrap();
|
||||
assert_eq!(actual_string, expected_string)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multiple_panels() {
|
||||
let input = io::Cursor::new(b"supercalifragilisticexpialidocioussupercalifragilisticexpialidocioussupercalifragilisticexpialidocious");
|
||||
let expected_string = "\
|
||||
┌────────┬─────────────────────────┬─────────────────────────┬─────────────────────────┬─────────────────────────┬────────┬────────┬────────┬────────┐
|
||||
│00000000│ 73 75 70 65 72 63 61 6c ┊ 69 66 72 61 67 69 6c 69 ┊ 73 74 69 63 65 78 70 69 ┊ 61 6c 69 64 6f 63 69 6f │supercal┊ifragili┊sticexpi┊alidocio│
|
||||
│00000020│ 75 73 73 75 70 65 72 63 ┊ 61 6c 69 66 72 61 67 69 ┊ 6c 69 73 74 69 63 65 78 ┊ 70 69 61 6c 69 64 6f 63 │ussuperc┊alifragi┊listicex┊pialidoc│
|
||||
│00000040│ 69 6f 75 73 73 75 70 65 ┊ 72 63 61 6c 69 66 72 61 ┊ 67 69 6c 69 73 74 69 63 ┊ 65 78 70 69 61 6c 69 64 │ioussupe┊rcalifra┊gilistic┊expialid│
|
||||
│00000060│ 6f 63 69 6f 75 73 ┊ ┊ ┊ │ocious ┊ ┊ ┊ │
|
||||
└────────┴─────────────────────────┴─────────────────────────┴─────────────────────────┴─────────────────────────┴────────┴────────┴────────┴────────┘
|
||||
"
|
||||
.to_owned();
|
||||
|
||||
let mut output = vec![];
|
||||
let mut printer: Printer<Vec<u8>> = Printer::new(
|
||||
&mut output,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
BorderStyle::Unicode,
|
||||
true,
|
||||
4,
|
||||
1,
|
||||
Base::Hexadecimal,
|
||||
);
|
||||
|
||||
printer.print_all(input).unwrap();
|
||||
|
||||
let actual_string: &str = str::from_utf8(&output).unwrap();
|
||||
assert_eq!(actual_string, expected_string)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn squeeze_works() {
|
||||
let input = io::Cursor::new(b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00");
|
||||
let expected_string = "\
|
||||
┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐
|
||||
│00000000│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄┊⋄⋄⋄⋄⋄⋄⋄⋄│
|
||||
│* │ ┊ │ ┊ │
|
||||
│00000020│ 00 ┊ │⋄ ┊ │
|
||||
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘
|
||||
"
|
||||
.to_owned();
|
||||
assert_print_all_output(input, expected_string);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn squeeze_nonzero() {
|
||||
let input = io::Cursor::new(b"000000000000000000000000000000000");
|
||||
let expected_string = "\
|
||||
┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐
|
||||
│00000000│ 30 30 30 30 30 30 30 30 ┊ 30 30 30 30 30 30 30 30 │00000000┊00000000│
|
||||
│* │ ┊ │ ┊ │
|
||||
│00000020│ 30 ┊ │0 ┊ │
|
||||
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘
|
||||
"
|
||||
.to_owned();
|
||||
assert_print_all_output(input, expected_string);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn squeeze_multiple_panels() {
|
||||
let input = io::Cursor::new(b"0000000000000000000000000000000000000000000000000");
|
||||
let expected_string = "\
|
||||
┌────────┬─────────────────────────┬─────────────────────────┬─────────────────────────┬────────┬────────┬────────┐
|
||||
│00000000│ 30 30 30 30 30 30 30 30 ┊ 30 30 30 30 30 30 30 30 ┊ 30 30 30 30 30 30 30 30 │00000000┊00000000┊00000000│
|
||||
│* │ ┊ ┊ │ ┊ ┊ │
|
||||
│00000030│ 30 ┊ ┊ │0 ┊ ┊ │
|
||||
└────────┴─────────────────────────┴─────────────────────────┴─────────────────────────┴────────┴────────┴────────┘
|
||||
"
|
||||
.to_owned();
|
||||
|
||||
let mut output = vec![];
|
||||
let mut printer: Printer<Vec<u8>> = Printer::new(
|
||||
&mut output,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
BorderStyle::Unicode,
|
||||
true,
|
||||
3,
|
||||
1,
|
||||
Base::Hexadecimal,
|
||||
);
|
||||
|
||||
printer.print_all(input).unwrap();
|
||||
|
||||
let actual_string: &str = str::from_utf8(&output).unwrap();
|
||||
assert_eq!(actual_string, expected_string)
|
||||
}
|
||||
}
|
||||
-407
@@ -1,407 +0,0 @@
|
||||
#[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,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum SqueezeAction {
|
||||
Ignore,
|
||||
Print,
|
||||
Delete,
|
||||
}
|
||||
|
||||
/// line size
|
||||
const LSIZE: u64 = 16;
|
||||
|
||||
impl Squeezer {
|
||||
pub fn new(enabled: bool) -> Squeezer {
|
||||
Squeezer {
|
||||
state: if enabled {
|
||||
SqueezeState::Probe
|
||||
} else {
|
||||
SqueezeState::Disabled
|
||||
},
|
||||
byte: 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn process(&mut self, b: u8, i: u64) {
|
||||
use self::SqueezeState::*;
|
||||
if self.state == Disabled {
|
||||
return;
|
||||
}
|
||||
let eq = b == self.byte;
|
||||
|
||||
if i % 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 % LSIZE == 1 {
|
||||
self.state = Probe;
|
||||
} else if i % 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_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);
|
||||
// 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);
|
||||
// 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);
|
||||
// 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);
|
||||
// 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);
|
||||
// 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);
|
||||
// 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);
|
||||
// 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);
|
||||
// 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);
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
+304
-5
@@ -5,6 +5,26 @@ fn hexyl() -> Command {
|
||||
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;
|
||||
@@ -51,7 +71,7 @@ mod basic {
|
||||
.success()
|
||||
.stdout(
|
||||
"┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐\n\
|
||||
│ │ No content to print │ │ │ │\n\
|
||||
│ │ No content │ │ │ │\n\
|
||||
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n",
|
||||
);
|
||||
}
|
||||
@@ -70,8 +90,8 @@ mod length {
|
||||
.success()
|
||||
.stdout(
|
||||
"┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐\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\
|
||||
│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\
|
||||
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n",
|
||||
);
|
||||
}
|
||||
@@ -140,7 +160,7 @@ mod skip {
|
||||
.success()
|
||||
.stdout(
|
||||
"┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐\n\
|
||||
│ │ No content to print │ │ │ │\n\
|
||||
│ │ No content │ │ │ │\n\
|
||||
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n",
|
||||
);
|
||||
}
|
||||
@@ -203,7 +223,7 @@ mod display_offset {
|
||||
.success()
|
||||
.stdout(
|
||||
"┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐\n\
|
||||
│00000030│ 02 00 3e 00 01 00 00 00 ┊ 00 10 40 00 00 00 00 00 │•0>0•000┊0•@00000│\n\
|
||||
│00000030│ 02 00 3e 00 01 00 00 00 ┊ 00 10 40 00 00 00 00 00 │•⋄>⋄•⋄⋄⋄┊⋄•@⋄⋄⋄⋄⋄│\n\
|
||||
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n",
|
||||
);
|
||||
}
|
||||
@@ -271,3 +291,282 @@ mod display_settings {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod group {
|
||||
use super::hexyl;
|
||||
use super::PrettyAssert;
|
||||
|
||||
#[test]
|
||||
fn group_2_bytes() {
|
||||
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_4_bytes() {
|
||||
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_8_bytes() {
|
||||
hexyl()
|
||||
.arg("ascii")
|
||||
.arg("--color=never")
|
||||
.arg("--group-size=8")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(
|
||||
"┌────────┬──────────────────┬──────────────────┬────────┬────────┐\n\
|
||||
│00000000│ 3031323334353637 ┊ 383961626364650a │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",
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user