mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-17 13:17:55 +08:00
b7d068c729
* make imap list and search return msg instead of fetch * move imap logouts to main fn * improve list command * improve search command * improve flags command * improve template reply * improve tpl forward command * refactor tpl and msg reply/forward * refactor copy, move and write commands * refactor attachment command * fix attachment part of copy and move commands * fix send, save, read and mbox * put back notify and watch commands * fix msg encoding * refactor edit choices, clean dead code * fix attachment for write, reply and forward commands * refactor config mod struct * refactor project folder struct * fix vim plugin (#215)
93 lines
2.4 KiB
Rust
93 lines
2.4 KiB
Rust
use anyhow::{anyhow, Context, Result};
|
|
use log::{debug, error};
|
|
use std::io::{self, Write};
|
|
|
|
pub enum PreEditChoice {
|
|
Edit,
|
|
Discard,
|
|
Quit,
|
|
}
|
|
|
|
pub fn pre_edit() -> Result<PreEditChoice> {
|
|
println!("A draft was found:");
|
|
print!("(e)dit, (d)iscard or (q)uit? ");
|
|
io::stdout().flush().context("cannot flush stdout")?;
|
|
|
|
let mut buf = String::new();
|
|
io::stdin()
|
|
.read_line(&mut buf)
|
|
.context("cannot read stdin")?;
|
|
|
|
match buf.bytes().next().map(|bytes| bytes as char) {
|
|
Some('e') => {
|
|
debug!("edit choice matched");
|
|
Ok(PreEditChoice::Edit)
|
|
}
|
|
Some('d') => {
|
|
debug!("discard choice matched");
|
|
Ok(PreEditChoice::Discard)
|
|
}
|
|
Some('q') => {
|
|
debug!("quit choice matched");
|
|
Ok(PreEditChoice::Quit)
|
|
}
|
|
Some(choice) => {
|
|
error!(r#"invalid choice "{}""#, choice);
|
|
Err(anyhow!(r#"invalid choice "{}""#, choice))
|
|
}
|
|
None => {
|
|
error!("empty choice");
|
|
Err(anyhow!("empty choice"))
|
|
}
|
|
}
|
|
}
|
|
|
|
pub enum PostEditChoice {
|
|
Send,
|
|
Edit,
|
|
LocalDraft,
|
|
RemoteDraft,
|
|
Discard,
|
|
}
|
|
|
|
pub fn post_edit() -> Result<PostEditChoice> {
|
|
print!("(s)end, (e)dit, (l)ocal/(r)emote draft or (d)iscard? ");
|
|
io::stdout().flush().context("cannot flush stdout")?;
|
|
|
|
let mut buf = String::new();
|
|
io::stdin()
|
|
.read_line(&mut buf)
|
|
.context("cannot read stdin")?;
|
|
|
|
match buf.bytes().next().map(|bytes| bytes as char) {
|
|
Some('s') => {
|
|
debug!("send choice matched");
|
|
Ok(PostEditChoice::Send)
|
|
}
|
|
Some('l') => {
|
|
debug!("save local draft choice matched");
|
|
Ok(PostEditChoice::LocalDraft)
|
|
}
|
|
Some('r') => {
|
|
debug!("save remote draft matched");
|
|
Ok(PostEditChoice::RemoteDraft)
|
|
}
|
|
Some('e') => {
|
|
debug!("edit choice matched");
|
|
Ok(PostEditChoice::Edit)
|
|
}
|
|
Some('d') => {
|
|
debug!("discard choice matched");
|
|
Ok(PostEditChoice::Discard)
|
|
}
|
|
Some(choice) => {
|
|
error!(r#"invalid choice "{}""#, choice);
|
|
Err(anyhow!(r#"invalid choice "{}""#, choice))
|
|
}
|
|
None => {
|
|
error!("empty choice");
|
|
Err(anyhow!("empty choice"))
|
|
}
|
|
}
|
|
}
|