mirror of
https://github.com/FliegendeWurst/tmux-thumbs.git
synced 2024-11-22 21:05:00 +00:00
Fix issue with multi selection
This commit is contained in:
parent
6ef320d676
commit
122c26b8b0
24
src/main.rs
24
src/main.rs
@ -8,6 +8,7 @@ mod view;
|
|||||||
|
|
||||||
use self::clap::{App, Arg};
|
use self::clap::{App, Arg};
|
||||||
use clap::crate_version;
|
use clap::crate_version;
|
||||||
|
use std::fs::OpenOptions;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::io::{self, Read};
|
use std::io::{self, Read};
|
||||||
|
|
||||||
@ -167,25 +168,32 @@ fn main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if !selected.is_empty() {
|
if !selected.is_empty() {
|
||||||
for (text, upcase) in selected.iter() {
|
let output = selected
|
||||||
let mut output = format.to_string();
|
.iter()
|
||||||
let break_line = if multi { "\n" } else { "" };
|
.map(|(text, upcase)| {
|
||||||
|
|
||||||
let upcase_value = if *upcase { "true" } else { "false" };
|
let upcase_value = if *upcase { "true" } else { "false" };
|
||||||
|
|
||||||
|
let mut output = format.to_string();
|
||||||
|
|
||||||
output = str::replace(&output, "%U", upcase_value);
|
output = str::replace(&output, "%U", upcase_value);
|
||||||
output = str::replace(&output, "%H", text.as_str());
|
output = str::replace(&output, "%H", text.as_str());
|
||||||
|
output
|
||||||
let output = format!("{}{}", output, break_line);
|
})
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join("\n");
|
||||||
|
|
||||||
if target.is_empty() {
|
if target.is_empty() {
|
||||||
print!("{}", output);
|
print!("{}", output);
|
||||||
} else {
|
} else {
|
||||||
let mut file = std::fs::File::create(target).expect("Unable to open the target file");
|
let mut file = OpenOptions::new()
|
||||||
|
.create(true)
|
||||||
|
.truncate(true)
|
||||||
|
.write(true)
|
||||||
|
.open(target)
|
||||||
|
.expect("Unable to open the target file");
|
||||||
|
|
||||||
file.write(output.as_bytes()).unwrap();
|
file.write(output.as_bytes()).unwrap();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
::std::process::exit(1);
|
::std::process::exit(1);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user