jrnl: shorten command and add inquire

This commit is contained in:
Schrottkatze 2024-05-06 21:33:14 +02:00
parent caaa7c7c6b
commit 73bbc7c616
Signed by: schrottkatze
SSH key fingerprint: SHA256:hXb3t1vINBFCiDCmhRABHX5ocdbLiKyCdKI4HK2Rbbc
2 changed files with 4 additions and 11 deletions

View file

@ -1,5 +1,5 @@
[package] [package]
name = "jrnl" name = "j"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
@ -15,3 +15,4 @@ petgraph = "0.6.4"
ratatui = "0.26.2" ratatui = "0.26.2"
temp-file = "0.1.8" temp-file = "0.1.8"
termsize = "0.1.6" termsize = "0.1.6"
inquire = "0.7.5"

View file

@ -6,6 +6,7 @@ use std::{
process::Command, process::Command,
}; };
use inquire::Text;
use temp_file::{TempFile, TempFileBuilder}; use temp_file::{TempFile, TempFileBuilder};
use crate::md::{Entry, ToMd}; use crate::md::{Entry, ToMd};
@ -17,7 +18,7 @@ pub fn add_entry(path: PathBuf, title: Option<String>) -> io::Result<()> {
std::process::exit(1); std::process::exit(1);
} }
let title = prompt("Title")?; let title = Text::new("Title").prompt().unwrap();
let tmp = TempFileBuilder::new() let tmp = TempFileBuilder::new()
.suffix(".jrnl-entry.md") .suffix(".jrnl-entry.md")
@ -57,12 +58,3 @@ pub fn add_entry(path: PathBuf, title: Option<String>) -> io::Result<()> {
Ok(()) Ok(())
} }
fn prompt(title: &str) -> io::Result<String> {
print!("{}: ", title);
let _ = io::stdout().flush();
let mut buf = String::new();
let stdin = io::stdin();
stdin.read_line(&mut buf)?;
Ok(buf)
}