added prompt function

This commit is contained in:
2026-08-21 16:34:01 +01:00
parent 5c261c0d34
commit 9c0d92d07c

View File

@@ -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<String, std::io::Error> {
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<Shelf>, id: &u8) -> Option<usize> {
shelves.iter().position(|shelf| shelf.id == *id)
}