Added endpoint selector, reworked config.toml structure, added movent features for text input
This commit is contained in:
40
src/main.rs
40
src/main.rs
@@ -23,8 +23,8 @@ async fn main() -> Result<()> {
|
||||
let config = if config::Config::exists() {
|
||||
config::Config::load()?
|
||||
} else {
|
||||
let url = prompt_server_url()?;
|
||||
config::Config::create_with_url(&url)?
|
||||
let (url, name) = prompt_first_endpoint()?;
|
||||
config::Config::create_with_endpoint(&url, &name)?
|
||||
};
|
||||
|
||||
enable_raw_mode()?;
|
||||
@@ -166,8 +166,8 @@ async fn run_exec(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Runs before ratatui starts. Prompts for the server URL on first launch.
|
||||
fn prompt_server_url() -> Result<String> {
|
||||
/// Runs before ratatui starts. Prompts for endpoint URL and name on first launch.
|
||||
fn prompt_first_endpoint() -> Result<(String, String)> {
|
||||
use std::io::Write;
|
||||
|
||||
println!();
|
||||
@@ -179,22 +179,34 @@ fn prompt_server_url() -> Result<String> {
|
||||
println!(" {}", config::config_path().display());
|
||||
println!();
|
||||
|
||||
loop {
|
||||
print!(" URL сервера меню: ");
|
||||
let name = loop {
|
||||
print!(" Название эндпоинта: ");
|
||||
std::io::stdout().flush()?;
|
||||
let mut buf = String::new();
|
||||
std::io::stdin().read_line(&mut buf)?;
|
||||
let val = buf.trim().to_string();
|
||||
if val.is_empty() {
|
||||
println!(" Название не может быть пустым. Попробуйте ещё раз.\n");
|
||||
continue;
|
||||
}
|
||||
break val;
|
||||
};
|
||||
|
||||
let mut url = String::new();
|
||||
std::io::stdin().read_line(&mut url)?;
|
||||
let url = url.trim().to_string();
|
||||
|
||||
if url.is_empty() {
|
||||
let url = loop {
|
||||
print!(" URL эндпоинта: ");
|
||||
std::io::stdout().flush()?;
|
||||
let mut buf = String::new();
|
||||
std::io::stdin().read_line(&mut buf)?;
|
||||
let val = buf.trim().to_string();
|
||||
if val.is_empty() {
|
||||
println!(" URL не может быть пустым. Попробуйте ещё раз.\n");
|
||||
continue;
|
||||
}
|
||||
break val;
|
||||
};
|
||||
|
||||
println!();
|
||||
return Ok(url);
|
||||
}
|
||||
println!();
|
||||
Ok((url, name))
|
||||
}
|
||||
|
||||
async fn read_crossterm_event() -> Result<Option<crossterm::event::Event>> {
|
||||
|
||||
Reference in New Issue
Block a user