fix(main): prevent overrunning string index on column edits
This commit is contained in:
parent
b71916c905
commit
8e7b8d3e66
65
src/main.rs
65
src/main.rs
|
@ -3,7 +3,6 @@ use std::fmt::Display;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{BufRead, BufReader, stdin, stdout, Write};
|
use std::io::{BufRead, BufReader, stdin, stdout, Write};
|
||||||
use std::ops::Deref;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
|
@ -88,30 +87,28 @@ async fn main() {
|
||||||
Ok(relay) => {
|
Ok(relay) => {
|
||||||
or_print(client.add_relay(relay).await);
|
or_print(client.add_relay(relay).await);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => match File::open(&relayfile).map(|f| BufReader::new(f).lines().flatten()) {
|
||||||
match File::open(&relayfile).map(|f| BufReader::new(f).lines().flatten()) {
|
Ok(lines) => {
|
||||||
Ok(lines) => {
|
for line in lines {
|
||||||
for line in lines {
|
or_print(client.add_relay(line).await);
|
||||||
or_print(client.add_relay(line).await);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
eprintln!("Could not read relays file: {}", e);
|
|
||||||
if let Some(line) = prompt("Relay?") {
|
|
||||||
let url = if line.contains("://") { line } else { "wss://".to_string() + &line };
|
|
||||||
or_print(
|
|
||||||
client
|
|
||||||
.add_relay(url.clone())
|
|
||||||
.await,
|
|
||||||
).map(|bool| {
|
|
||||||
if bool {
|
|
||||||
or_print(fs::write(&relayfile, url));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
Err(e) => {
|
||||||
|
eprintln!("Could not read relays file: {}", e);
|
||||||
|
if let Some(line) = prompt("Relay?") {
|
||||||
|
let url = if line.contains("://") {
|
||||||
|
line
|
||||||
|
} else {
|
||||||
|
"wss://".to_string() + &line
|
||||||
|
};
|
||||||
|
or_print(client.add_relay(url.clone()).await).map(|bool| {
|
||||||
|
if bool {
|
||||||
|
or_print(fs::write(&relayfile, url));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
//let proxy = Some(SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::LOCALHOST, 9050)));
|
//let proxy = Some(SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::LOCALHOST, 9050)));
|
||||||
|
@ -188,7 +185,11 @@ async fn main() {
|
||||||
loop {
|
loop {
|
||||||
tasks.print_tasks();
|
tasks.print_tasks();
|
||||||
|
|
||||||
print!(" {}{}) ", tasks.get_task_path(tasks.get_position()), tasks.get_prompt_suffix());
|
print!(
|
||||||
|
" {}{}) ",
|
||||||
|
tasks.get_task_path(tasks.get_position()),
|
||||||
|
tasks.get_prompt_suffix()
|
||||||
|
);
|
||||||
stdout().flush().unwrap();
|
stdout().flush().unwrap();
|
||||||
match lines.next() {
|
match lines.next() {
|
||||||
Some(Ok(input)) => {
|
Some(Ok(input)) => {
|
||||||
|
@ -206,13 +207,19 @@ async fn main() {
|
||||||
|
|
||||||
let mut iter = input.chars();
|
let mut iter = input.chars();
|
||||||
let op = iter.next();
|
let op = iter.next();
|
||||||
let arg = input[1..].trim();
|
let arg = if input.len() > 1 {
|
||||||
|
input[1..].trim()
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
};
|
||||||
match op {
|
match op {
|
||||||
None => {}
|
None => {}
|
||||||
|
|
||||||
Some(':') => match input[1..2].parse::<usize>() {
|
Some(':') => match iter.next().and_then(|s| s.to_digit(10)) {
|
||||||
Ok(index) => {
|
Some(digit) => {
|
||||||
if input.len() == 2 {
|
let index = digit as usize;
|
||||||
|
let remaining = iter.collect::<String>().trim().to_string();
|
||||||
|
if remaining.is_empty() {
|
||||||
tasks.properties.remove(index);
|
tasks.properties.remove(index);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -223,7 +230,7 @@ async fn main() {
|
||||||
tasks.properties.insert(index, value);
|
tasks.properties.insert(index, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_) => {
|
None => {
|
||||||
let pos = tasks.properties.iter().position(|s| s == arg);
|
let pos = tasks.properties.iter().position(|s| s == arg);
|
||||||
match pos {
|
match pos {
|
||||||
None => {
|
None => {
|
||||||
|
|
Loading…
Reference in New Issue