Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more formatting options #149

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions examples/simple.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::io;

use hexyl::{BorderStyle, Printer};
use hexyl::{BorderType, InnerSeparatorStyle, OuterBorderStyle, Printer};

fn main() {
let input = vec![
Expand All @@ -13,8 +13,11 @@ fn main() {

let show_color = true;
let use_squeezing = false;
let border_style = BorderStyle::Unicode;
let border_type = BorderType::Unicode;
let hex_inner_separator_style = InnerSeparatorStyle::Visible;
let text_inner_separator_style = InnerSeparatorStyle::Visible;
let outer_border_style = OuterBorderStyle::Visible;

let mut printer = Printer::new(&mut handle, show_color, border_style, use_squeezing);
let mut printer = Printer::new(&mut handle, show_color, border_type, hex_inner_separator_style, text_inner_separator_style, outer_border_style, use_squeezing);
printer.print_all(&input[..]).unwrap();
}
63 changes: 57 additions & 6 deletions src/bin/hexyl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use const_format::formatcp;

use thiserror::Error as ThisError;

use hexyl::{BorderStyle, Input, Printer};
use hexyl::{BorderType, InnerSeparatorStyle, Input, OuterBorderStyle, Printer};

const DEFAULT_BLOCK_SIZE: i64 = 512;

Expand Down Expand Up @@ -110,6 +110,7 @@ fn run() -> Result<(), AnyhowError> {
goes to an interactive terminal",
),
)
// TODO: Revisit name, value_name of border, {hex,text}_inner_separator
.arg(
Arg::with_name("border")
.long("border")
Expand All @@ -122,6 +123,39 @@ fn run() -> Result<(), AnyhowError> {
or none at all",
),
)
.arg(
Arg::with_name("hex_inner_separator")
.long("hex-inner-separator")
.takes_value(true)
.value_name("STYLE")
.possible_values(&["visible", "none"])
.default_value("visible")
.help(
"Whether or not to draw the inner separator for the hex display", // TODO: Rephrase this
),
)
.arg(
Arg::with_name("text_inner_separator")
.long("text-inner-separator")
.takes_value(true)
.value_name("STYLE")
.possible_values(&["visible", "none"])
.default_value("visible")
.help(
"Whether or not to draw the inner separator for the text display", // TODO: Rephrase this
),
)
.arg(
Arg::with_name("outer_border")
.long("outer-border")
.takes_value(true)
.value_name("STYLE")
.possible_values(&["visible", "none"])
.default_value("visible")
.help(
"Whether or not to draw the outer border", // TODO: Rephrase this
),
)
.arg(
Arg::with_name("display_offset")
.short("o")
Expand Down Expand Up @@ -228,11 +262,28 @@ fn run() -> Result<(), AnyhowError> {
Some("auto") => atty::is(Stream::Stdout),
_ => true,
};

// TODO: Revisit name of border_type, {hex,text}_inner_separator_style

let border_style = match matches.value_of("border") {
Some("unicode") => BorderStyle::Unicode,
Some("ascii") => BorderStyle::Ascii,
_ => BorderStyle::None,
let border_type = match matches.value_of("border") {
Some("unicode") => BorderType::Unicode,
Some("ascii") => BorderType::Ascii,
_ => BorderType::None,
};

let hex_inner_separator_style = match matches.value_of("hex_inner_separator") {
Some("visible") => InnerSeparatorStyle::Visible,
_ => InnerSeparatorStyle::None
};

let text_inner_separator_style = match matches.value_of("text_inner_separator") {
Some("visible") => InnerSeparatorStyle::Visible,
_ => InnerSeparatorStyle::None
};

let outer_border_style = match matches.value_of("outer_border") {
Some("visible") => OuterBorderStyle::Visible,
_ => OuterBorderStyle::None
};

let squeeze = !matches.is_present("nosqueezing");
Expand All @@ -251,7 +302,7 @@ fn run() -> Result<(), AnyhowError> {
let stdout = io::stdout();
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_type, hex_inner_separator_style, text_inner_separator_style, outer_border_style, squeeze);
printer.display_offset(skip_offset + display_offset);
printer.print_all(&mut reader).map_err(|e| anyhow!(e))?;

Expand Down
Loading