From 9c0d92d07cc0bf8fa61167a38dbffe68141480d8 Mon Sep 17 00:00:00 2001 From: voidarc Date: Fri, 21 Aug 2026 16:34:01 +0100 Subject: [PATCH] added prompt function --- src/utils.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/utils.rs b/src/utils.rs index 20bd3e4..d7b5b67 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,7 +1,21 @@ use crate::structs::{Library, Shelf}; -use std::{fs, io, path::Path}; +use std::{ + fs, + io::{self, Write}, + path::Path, +}; use xdg::BaseDirectories; +pub fn prompt(text: &str) -> Result { + print!("{} ", text); + std::io::stdout().flush()?; + + let mut response = String::new(); + std::io::stdin().read_line(&mut response); + + Ok(response.trim_end().to_owned()) +} + pub fn get_shelf_index(shelves: &Vec, id: &u8) -> Option { shelves.iter().position(|shelf| shelf.id == *id) }