mirror of
https://github.com/sharkdp/hexyl.git
synced 2026-10-26 20:16:34 +00:00
bin: offset should add to skip, not override it
This commit is contained in:
1 parent
d69a7d8e04
commit
524a6c607f
3 files changed
+25
-4
No files matched your search
@@ -1,5 +1,9 @@
|
|||||||
# unreleased
|
# 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
|
## Features
|
||||||
|
|
||||||
- Allow relative and negative byte offsets (e.g. `hexyl --skip=-1block`), see #99 (@ErichDonGubler)
|
- Allow relative and negative byte offsets (e.g. `hexyl --skip=-1block`), see #99 (@ErichDonGubler)
|
||||||
|
|||||||
+4
-4
@@ -155,7 +155,7 @@ fn run() -> Result<(), AnyhowError> {
|
|||||||
})
|
})
|
||||||
.transpose()?;
|
.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();
|
let value = value.into_inner();
|
||||||
reader.seek(match kind {
|
reader.seek(match kind {
|
||||||
ByteOffsetKind::ForwardFromBeginning | ByteOffsetKind::ForwardFromLastOffset => {
|
ByteOffsetKind::ForwardFromBeginning | ByteOffsetKind::ForwardFromLastOffset => {
|
||||||
@@ -203,7 +203,7 @@ fn run() -> Result<(), AnyhowError> {
|
|||||||
|
|
||||||
let squeeze = !matches.is_present("nosqueezing");
|
let squeeze = !matches.is_present("nosqueezing");
|
||||||
|
|
||||||
let display_offset = matches
|
let display_offset: u64 = matches
|
||||||
.value_of("display_offset")
|
.value_of("display_offset")
|
||||||
.map(|s| {
|
.map(|s| {
|
||||||
parse_byte_count(s).context(anyhow!(
|
parse_byte_count(s).context(anyhow!(
|
||||||
@@ -212,14 +212,14 @@ fn run() -> Result<(), AnyhowError> {
|
|||||||
))
|
))
|
||||||
})
|
})
|
||||||
.transpose()?
|
.transpose()?
|
||||||
.unwrap_or(default_display_offset)
|
.unwrap_or(0)
|
||||||
.into();
|
.into();
|
||||||
|
|
||||||
let stdout = io::stdout();
|
let stdout = io::stdout();
|
||||||
let mut stdout_lock = stdout.lock();
|
let mut stdout_lock = stdout.lock();
|
||||||
|
|
||||||
let mut printer = Printer::new(&mut stdout_lock, show_color, border_style, squeeze);
|
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))?;
|
printer.print_all(&mut reader).map_err(|e| anyhow!(e))?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -94,3 +94,20 @@ fn display_offset() {
|
|||||||
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n",
|
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\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",
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user