-
Notifications
You must be signed in to change notification settings - Fork 485
/
mod.rs
39 lines (32 loc) · 1.1 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use crate::deser;
use crate::prelude::*;
use clap::Args;
use crossterm::style::{style, Stylize};
use std::process;
pub mod var;
pub mod var_stdin;
#[derive(Debug, Clone, Args)]
pub struct Input {
/// Selection line
pub line: String,
}
fn extract_elements(argstr: &str) -> Result<(&str, &str, &str)> {
let mut parts = argstr.split(deser::terminal::DELIMITER).skip(3);
let tags = parts.next().context("No `tags` element provided.")?;
let comment = parts.next().context("No `comment` element provided.")?;
let snippet = parts.next().context("No `snippet` element provided.")?;
Ok((tags, comment, snippet))
}
impl Runnable for Input {
fn run(&self) -> Result<()> {
let line = &self.line;
let (tags, comment, snippet) = extract_elements(line)?;
println!(
"{comment} {tags} \n{snippet}",
comment = style(comment).with(CONFIG.comment_color()),
tags = style(format!("[{}]", tags)).with(CONFIG.tag_color()),
snippet = style(deser::fix_newlines(snippet)).with(CONFIG.snippet_color()),
);
process::exit(0)
}
}