diff --git a/src/bin/copyrat.rs b/src/bin/copyrat.rs index 5a3f565..b665441 100644 --- a/src/bin/copyrat.rs +++ b/src/bin/copyrat.rs @@ -12,10 +12,11 @@ fn main() { let mut buffer = String::new(); handle.read_to_string(&mut buffer).unwrap(); + let lines = buffer.split('\n').collect::>(); // Execute copyrat over the buffer (will take control over stdout). // This returns the selected matche. - let selection: Option = run(buffer, &opt); + let selection: Option = run(&lines, &opt); // Early exit, signaling no selections were found. if selection.is_none() { diff --git a/src/bin/tmux_copyrat.rs b/src/bin/tmux_copyrat.rs index 2c3375d..bba6f79 100644 --- a/src/bin/tmux_copyrat.rs +++ b/src/bin/tmux_copyrat.rs @@ -17,6 +17,7 @@ fn main() -> Result<(), error::ParseError> { .expect("Exactly one tmux pane should be active in the current window."); let buffer = tmux::capture_pane(&active_pane, &config.capture_region)?; + let lines = buffer.split('\n').collect::>(); // We have to dance a little with Panes, because this process' i/o streams // are connected to the pane in the window newly created for us, instead @@ -24,7 +25,7 @@ fn main() -> Result<(), error::ParseError> { let temp_pane_spec = format!("{}.0", config.window_name); tmux::swap_pane_with(&temp_pane_spec)?; - let selection = copyrat::run(buffer, &config.basic_config); + let selection = copyrat::run(&lines, &config.basic_config); tmux::swap_pane_with(&temp_pane_spec)?; diff --git a/src/lib.rs b/src/lib.rs index 2a23b59..f61e584 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,9 +9,7 @@ pub mod ui; /// # Note /// /// Maybe the decision to take ownership of the buffer is a bit bold. -pub fn run(buffer: String, opt: &config::basic::Config) -> Option { - let lines = buffer.split('\n').collect::>(); - +pub fn run(lines: &[&str], opt: &config::basic::Config) -> Option { let model = textbuf::Model::new( &lines, &opt.alphabet,