mirror of
https://github.com/TECHNOFAB11/tmux-copyrat.git
synced 2025-12-13 00:20:08 +01:00
refactor: refactor
This commit is contained in:
parent
623c66cbba
commit
791aaadd49
10 changed files with 655 additions and 468 deletions
17
src/main.rs
17
src/main.rs
|
|
@ -3,10 +3,10 @@ use std::fs::OpenOptions;
|
|||
use std::io::prelude::*;
|
||||
use std::io::{self, Read};
|
||||
|
||||
use copyrat::{run, Opt};
|
||||
use copyrat::{run, CliOpt};
|
||||
|
||||
fn main() {
|
||||
let opt = Opt::parse();
|
||||
let opt = CliOpt::parse();
|
||||
|
||||
// Copy the pane contents (piped in via stdin) into a buffer, and split lines.
|
||||
let stdin = io::stdin();
|
||||
|
|
@ -17,7 +17,18 @@ fn main() {
|
|||
|
||||
// Execute copyrat over the buffer (will take control over stdout).
|
||||
// This returns the selected matches.
|
||||
let output: String = run(buffer, &opt);
|
||||
let selections: Vec<(String, bool)> = run(buffer, &opt);
|
||||
|
||||
// Early exit, signaling no selections were found.
|
||||
if selections.is_empty() {
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
let output = selections
|
||||
.iter()
|
||||
.map(|(text, _)| text.as_str())
|
||||
.collect::<Vec<&str>>()
|
||||
.join("\n");
|
||||
|
||||
// Write output to a target_path if provided, else print to original stdout.
|
||||
match opt.target_path {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue