added prompt function
This commit is contained in:
16
src/utils.rs
16
src/utils.rs
@@ -1,7 +1,21 @@
|
|||||||
use crate::structs::{Library, Shelf};
|
use crate::structs::{Library, Shelf};
|
||||||
use std::{fs, io, path::Path};
|
use std::{
|
||||||
|
fs,
|
||||||
|
io::{self, Write},
|
||||||
|
path::Path,
|
||||||
|
};
|
||||||
use xdg::BaseDirectories;
|
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> {
|
pub fn get_shelf_index(shelves: &Vec<Shelf>, id: &u8) -> Option<usize> {
|
||||||
shelves.iter().position(|shelf| shelf.id == *id)
|
shelves.iter().position(|shelf| shelf.id == *id)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user