diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bd1666..c625950 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # unreleased +## Changes + +- Breaking change (binary): setting the `-o/--display-offset` flag no longer overrides the value set by `--skip` [#115](https://github.com/sharkdp/hexyl/issues/115). The first displayed address is now the sum of the two values - this matches the behaviour of `xxd`. + ## Features - Allow relative and negative byte offsets (e.g. `hexyl --skip=-1block`), see #99 (@ErichDonGubler) diff --git a/src/bin/hexyl.rs b/src/bin/hexyl.rs index 597e5cd..71042dd 100644 --- a/src/bin/hexyl.rs +++ b/src/bin/hexyl.rs @@ -155,7 +155,7 @@ fn run() -> Result<(), AnyhowError> { }) .transpose()?; - let default_display_offset = if let Some(ByteOffset { kind, value }) = skip_arg { + let skip_offset = if let Some(ByteOffset { kind, value }) = skip_arg { let value = value.into_inner(); reader.seek(match kind { ByteOffsetKind::ForwardFromBeginning | ByteOffsetKind::ForwardFromLastOffset => { @@ -203,7 +203,7 @@ fn run() -> Result<(), AnyhowError> { let squeeze = !matches.is_present("nosqueezing"); - let display_offset = matches + let display_offset: u64 = matches .value_of("display_offset") .map(|s| { parse_byte_count(s).context(anyhow!( @@ -212,14 +212,14 @@ fn run() -> Result<(), AnyhowError> { )) }) .transpose()? - .unwrap_or(default_display_offset) + .unwrap_or(0) .into(); let stdout = io::stdout(); let mut stdout_lock = stdout.lock(); let mut printer = Printer::new(&mut stdout_lock, show_color, border_style, squeeze); - printer.display_offset(display_offset); + printer.display_offset(skip_offset + display_offset); printer.print_all(&mut reader).map_err(|e| anyhow!(e))?; Ok(()) diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index b7d642e..78e6e5d 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -94,3 +94,20 @@ fn display_offset() { └────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n", ); } + +#[test] +fn display_offset_and_skip() { + hexyl() + .arg("hello_world_elf64") + .arg("--color=never") + .arg("--display-offset=0x20") + .arg("--skip=0x10") + .arg("--length=0x10") + .assert() + .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\ + └────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n", + ); +}