Skip to content

Commit

Permalink
Default to context 10 and s/quiet/pipe-mode/
Browse files Browse the repository at this point in the history
  • Loading branch information
John Baber-Lucero committed Feb 20, 2022
1 parent 6efb4e1 commit 66af0af
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
6 changes: 6 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
- BUG
- ? past the beginning of the file causes a panic
- Show context even on first print when opening file

- Handle things like "$-10"
- docs.rs documentation
- Implement printing only a screenful at a time (real ed doesn't bother to do this)
- Allow placing of breaks at random places in the bytes (to help indicate
protocol things.
- Allow placing notes are locations in the bytes.
- Use cross platform colors so when compiled with mingw, still get terminal colors
- vihex may handle this
13 changes: 7 additions & 6 deletions src/bin/edhex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,17 @@ fn main() {
"If given -p, those preferences will take precedence\n",
"over preferences in <state-filename.json>"))
)
.arg(Arg::with_name("quiet").short("q").long("quiet")
.arg(Arg::with_name("pipe-mode").short("P").long("pipe-mode")
.takes_value(false).help("Don't print prompts or initial \
help text and state\ne.g. for clean output when \
piping commands in"))
help text and state\nOnly print one line at a time \
until updated with 't' or 'T'\nThis is for clean output \
when piping commands in"))
.arg(Arg::with_name("filename").required(false).help("Name of file to \
be edited. If not given, a new file will be \
created on write"))
.get_matches();

let quiet = matches.is_present("quiet");
let pipe_mode = matches.is_present("pipe-mode");
let color = !matches.is_present("nocolor");
let filename_given = matches.is_present("filename");
let filename = match matches.value_of("filename") {
Expand Down Expand Up @@ -91,6 +92,6 @@ fn main() {
std::process::exit(1);
}

std::process::exit(edhex::actual_runtime(&filename, quiet, color, readonly,
prefs_path.to_path_buf(), state_path.to_path_buf()))
std::process::exit(edhex::actual_runtime(&filename, pipe_mode, color,
readonly, prefs_path.to_path_buf(), state_path.to_path_buf()))
}
19 changes: 11 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use ansi_term::Color;
use ec::hex_unless_dec;
use ec::State;
use regex::Regex;
Expand Down Expand Up @@ -763,11 +764,13 @@ pub fn write_out(state: &mut ec::State) {


/// If `filename` is "", open an empty buffer
pub fn actual_runtime(filename:&str, quiet:bool, color:bool, readonly:bool,
pub fn actual_runtime(filename:&str, pipe_mode:bool, color:bool, readonly:bool,
prefs_path: PathBuf, state_path: PathBuf) -> i32 {
let default_prefs = ec::Preferences {
show_prompt: !quiet,
show_prompt: !pipe_mode,
color: color,
before_context: if pipe_mode {0} else {10},
after_context: if pipe_mode {0} else {10},
..ec::Preferences::default()
};

Expand Down Expand Up @@ -816,9 +819,9 @@ pub fn actual_runtime(filename:&str, quiet:bool, color:bool, readonly:bool,
state.prefs = prefs;
}

if !quiet {
println!("h for help\n");
println!("{}", state);
if !pipe_mode {
println!("{}", Color::Yellow.paint("h for help"));
println!("\n{}", state);
println!();
state.print_bytes_sans_context(state.range(), false);
}
Expand Down Expand Up @@ -963,23 +966,23 @@ pub fn actual_runtime(filename:&str, quiet:bool, color:bool, readonly:bool,
/* Toggle showing char representations of bytes */
'm' => {
state.prefs.show_chars = !state.prefs.show_chars;
if !quiet {
if !pipe_mode {
println!("{}", state.prefs.show_chars);
}
},

/* Toggle showing byte number */
'n' => {
state.prefs.show_byte_numbers = !state.prefs.show_byte_numbers;
if !quiet {
if !pipe_mode {
println!("{}", state.prefs.show_byte_numbers);
}
},

/* Toggle color */
'o' => {
state.prefs.color = !state.prefs.color;
if !quiet {
if !pipe_mode {
if state.prefs.color {
println!("{} mode on", state.pretty_color_state());
}
Expand Down

0 comments on commit 66af0af

Please sign in to comment.