v0.2.0 #7

Merged
PlexSheep merged 15 commits from devel into master 2024-05-24 09:31:17 +02:00
2 changed files with 11 additions and 11 deletions
Showing only changes of commit 03188c8416 - Show all commits

View File

@ -9,7 +9,7 @@ use libpt::log::{debug, error, trace, warn};
pub const BYTES_PER_LINE: usize = 16; pub const BYTES_PER_LINE: usize = 16;
pub const LINE_SEP_HORIZ: char = '─'; pub const LINE_SEP_HORIZ: char = '─';
pub const LINE_SEP_VERT: char = '│'; pub const LINE_SEP_VERT: char = '│';
pub const CHAR_BORDER: &'static str = "|"; pub const CHAR_BORDER: &str = "|";
pub trait DataSource: Read { pub trait DataSource: Read {
fn skip(&mut self, length: usize) -> std::io::Result<()>; fn skip(&mut self, length: usize) -> std::io::Result<()>;
@ -93,16 +93,16 @@ impl Hedu {
self.display_buf += &format!("{:08X} {LINE_SEP_VERT} ", self.data_idx); self.display_buf += &format!("{:08X} {LINE_SEP_VERT} ", self.data_idx);
if self.len != 0 { if self.len != 0 {
for i in 0..self.len { for i in 0..self.len {
if i as usize % BYTES_PER_LINE == BYTES_PER_LINE / 2 { if i % BYTES_PER_LINE == BYTES_PER_LINE / 2 {
self.display_buf += " "; self.display_buf += " ";
} }
self.display_buf += &format!("{:02X} ", self.buf[self.alt_buf][i]); self.display_buf += &format!("{:02X} ", self.buf[self.alt_buf][i]);
} }
if self.len == BYTES_PER_LINE / 2 { if self.len == BYTES_PER_LINE / 2 {
self.display_buf += " " self.display_buf += " ";
} }
for i in 0..(BYTES_PER_LINE - self.len) { for i in 0..(BYTES_PER_LINE - self.len) {
if i as usize % BYTES_PER_LINE == BYTES_PER_LINE / 2 { if i % BYTES_PER_LINE == BYTES_PER_LINE / 2 {
self.display_buf += " "; self.display_buf += " ";
} }
self.display_buf += " "; self.display_buf += " ";
@ -237,7 +237,7 @@ impl Hedu {
/// interpret characters for the --chars option /// interpret characters for the --chars option
fn mask_chars(c: char) -> char { fn mask_chars(c: char) -> char {
if c.is_ascii_graphic() { if c.is_ascii_graphic() {
return c; c
} else if c == '\n' { } else if c == '\n' {
return '↩'; return '↩';
} else if c == ' ' { } else if c == ' ' {

View File

@ -5,13 +5,13 @@
use std::{fs::File, io::IsTerminal, path::PathBuf}; use std::{fs::File, io::IsTerminal, path::PathBuf};
use libpt::log::*; use libpt::log::{error, trace, warn, Level, Logger};
use clap::Parser; use clap::Parser;
use clap_verbosity_flag::{InfoLevel, Verbosity}; use clap_verbosity_flag::{InfoLevel, Verbosity};
mod dumper; mod dumper;
use dumper::*; use dumper::{DataSource, Hedu};
#[derive(Debug, Clone, Parser)] #[derive(Debug, Clone, Parser)]
#[command( #[command(
@ -63,7 +63,7 @@ pub struct Cli {
fn main() { fn main() {
let mut cli = cli_parse(); let mut cli = cli_parse();
let mut sources: Vec<Box<dyn DataSource>> = Vec::new(); let mut sources: Vec<Box<dyn DataSource>> = Vec::new();
if cli.data_source.len() > 0 && cli.data_source[0] != "-" { if !cli.data_source.is_empty() && cli.data_source[0] != "-" {
for data_source in &cli.data_source { for data_source in &cli.data_source {
let data_source: PathBuf = PathBuf::from(data_source); let data_source: PathBuf = PathBuf::from(data_source);
if data_source.is_dir() { if data_source.is_dir() {
@ -89,7 +89,7 @@ fn main() {
} }
// just for the little header // just for the little header
cli.data_source = Vec::new(); cli.data_source = Vec::new();
cli.data_source.push(format!("stdin")); cli.data_source.push("stdin".to_string());
sources.push(Box::new(stdin)); sources.push(Box::new(stdin));
} }
for (i, source) in sources.iter_mut().enumerate() { for (i, source) in sources.iter_mut().enumerate() {
@ -105,7 +105,7 @@ fn main() {
} }
} }
match config.dump(&mut **source) { match config.dump(&mut **source) {
Ok(_) => (), Ok(()) => (),
Err(err) => { Err(err) => {
error!("Could not dump data of file: {err}"); error!("Could not dump data of file: {err}");
std::process::exit(3); std::process::exit(3);
@ -135,5 +135,5 @@ fn cli_parse() -> Cli {
// less verbose version // less verbose version
Logger::init_mini(Some(ll)).expect("could not initialize Logger"); Logger::init_mini(Some(ll)).expect("could not initialize Logger");
} }
return cli; cli
} }