Impl password input prompt, improve help info
This commit is contained in:
parent
b90503f815
commit
78c18afe5e
2 changed files with 55 additions and 7 deletions
|
@ -15,9 +15,10 @@ counter, and the filename currently being played
|
||||||
mpd_info_screen [FLAGS] [OPTIONS] <host> [port]
|
mpd_info_screen [FLAGS] [OPTIONS] <host> [port]
|
||||||
|
|
||||||
FLAGS:
|
FLAGS:
|
||||||
--disable-show-artist
|
--disable-show-artist disable artist display
|
||||||
--disable-show-filename
|
--disable-show-filename disable filename display
|
||||||
--disable-show-title
|
--disable-show-title disable title display
|
||||||
|
--pprompt input password via prompt
|
||||||
-h, --help Prints help information
|
-h, --help Prints help information
|
||||||
-V, --version Prints version information
|
-V, --version Prints version information
|
||||||
|
|
||||||
|
|
55
src/main.rs
55
src/main.rs
|
@ -18,6 +18,7 @@ const INITIAL_FONT_SIZE: u16 = 96;
|
||||||
const ARTIST_INITIAL_FONT_SIZE: u16 = 48;
|
const ARTIST_INITIAL_FONT_SIZE: u16 = 48;
|
||||||
const TIMER_FONT_SIZE: u16 = 64;
|
const TIMER_FONT_SIZE: u16 = 64;
|
||||||
const SCREEN_DIFF_MARGIN: f32 = 1.0;
|
const SCREEN_DIFF_MARGIN: f32 = 1.0;
|
||||||
|
const PROMPT_Y_OFFSET: f32 = 48.0;
|
||||||
|
|
||||||
#[derive(StructOpt, Debug)]
|
#[derive(StructOpt, Debug)]
|
||||||
#[structopt(name = "mpd_info_screen")]
|
#[structopt(name = "mpd_info_screen")]
|
||||||
|
@ -27,12 +28,14 @@ struct Opt {
|
||||||
port: u16,
|
port: u16,
|
||||||
#[structopt(short = "p")]
|
#[structopt(short = "p")]
|
||||||
password: Option<String>,
|
password: Option<String>,
|
||||||
#[structopt(long = "disable-show-title")]
|
#[structopt(long = "disable-show-title", help = "disable title display")]
|
||||||
disable_show_title: bool,
|
disable_show_title: bool,
|
||||||
#[structopt(long = "disable-show-artist")]
|
#[structopt(long = "disable-show-artist", help = "disable artist display")]
|
||||||
disable_show_artist: bool,
|
disable_show_artist: bool,
|
||||||
#[structopt(long = "disable-show-filename")]
|
#[structopt(long = "disable-show-filename", help = "disable filename display")]
|
||||||
disable_show_filename: bool,
|
disable_show_filename: bool,
|
||||||
|
#[structopt(long = "pprompt", help = "input password via prompt")]
|
||||||
|
enable_prompt_password: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Shared {
|
struct Shared {
|
||||||
|
@ -593,6 +596,50 @@ async fn main() -> Result<(), String> {
|
||||||
let opt = Opt::from_args();
|
let opt = Opt::from_args();
|
||||||
println!("Got host addr == {}, port == {}", opt.host, opt.port);
|
println!("Got host addr == {}, port == {}", opt.host, opt.port);
|
||||||
|
|
||||||
|
let mut password: Option<String> = opt.password;
|
||||||
|
|
||||||
|
if opt.enable_prompt_password {
|
||||||
|
let mut input: String = String::new();
|
||||||
|
let mut asterisks: String = String::new();
|
||||||
|
'prompt_loop: loop {
|
||||||
|
draw_text(
|
||||||
|
"Input password:",
|
||||||
|
TEXT_X_OFFSET,
|
||||||
|
TEXT_Y_OFFSET + PROMPT_Y_OFFSET,
|
||||||
|
PROMPT_Y_OFFSET,
|
||||||
|
WHITE,
|
||||||
|
);
|
||||||
|
if let Some(k) = get_last_key_pressed() {
|
||||||
|
if k == KeyCode::Backspace {
|
||||||
|
input.pop();
|
||||||
|
} else if k == KeyCode::Enter {
|
||||||
|
password = Some(input);
|
||||||
|
break 'prompt_loop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(c) = get_char_pressed() {
|
||||||
|
input.push(c);
|
||||||
|
}
|
||||||
|
let input_count = input.chars().count();
|
||||||
|
if asterisks.len() < input_count {
|
||||||
|
for _ in 0..(input_count - asterisks.len()) {
|
||||||
|
asterisks.push('*');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
asterisks.truncate(input_count);
|
||||||
|
}
|
||||||
|
draw_text(
|
||||||
|
&asterisks,
|
||||||
|
TEXT_X_OFFSET,
|
||||||
|
TEXT_Y_OFFSET + PROMPT_Y_OFFSET * 2.0,
|
||||||
|
PROMPT_Y_OFFSET,
|
||||||
|
WHITE,
|
||||||
|
);
|
||||||
|
|
||||||
|
next_frame().await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let connection = get_connection(opt.host, opt.port)?;
|
let connection = get_connection(opt.host, opt.port)?;
|
||||||
connection
|
connection
|
||||||
.set_read_timeout(Some(Duration::from_millis(50)))
|
.set_read_timeout(Some(Duration::from_millis(50)))
|
||||||
|
@ -602,7 +649,7 @@ async fn main() -> Result<(), String> {
|
||||||
.expect("Should be able to set timeout for TcpStream writes");
|
.expect("Should be able to set timeout for TcpStream writes");
|
||||||
|
|
||||||
let shared_data = Arc::new(Mutex::new(Shared::new(connection)));
|
let shared_data = Arc::new(Mutex::new(Shared::new(connection)));
|
||||||
if let Some(p) = opt.password {
|
if let Some(p) = password {
|
||||||
shared_data
|
shared_data
|
||||||
.lock()
|
.lock()
|
||||||
.expect("Should be able to get mutex lock")
|
.expect("Should be able to get mutex lock")
|
||||||
|
|
Loading…
Reference in a new issue