diff --git a/extra/config.toml b/extra/config.toml index 5aaef9d..6a05401 100644 --- a/extra/config.toml +++ b/extra/config.toml @@ -41,6 +41,16 @@ # The tty which contains lemurs. This has to be mirrored in the lemurs.service tty = 2 +# Focus behaviour of fields when Lemurs is initially started +# +# Possible values: +# - default: Initially focus on first non-cached value +# - no-focus: No initial focus +# - environment: Initially focus on the environment selector +# - username: Initially focus on the username field +# - password: Initially focus on the password field +focus_behaviour = "default" + [power_controls] # Allow for the shutdown option to be used allow_shutdown = true diff --git a/src/config.rs b/src/config.rs index d384068..20758e2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -153,6 +153,9 @@ macro_rules! toml_config_struct { toml_config_struct! { Config, PartialConfig, tty => u8, + + focus_behaviour => FocusBehaviour, + power_controls => PowerControlConfig [PartialPowerControlConfig], environment_switcher => SwitcherConfig [PartialSwitcherConfig], username_field => UsernameFieldConfig [PartialUsernameFieldConfig], @@ -245,6 +248,20 @@ toml_config_struct! { PasswordFieldConfig, PartialPasswordFieldConfig, style => InputFieldStyle [PartialInputFieldStyle], } +#[derive(Debug, Clone, Deserialize)] +pub enum FocusBehaviour { + #[serde(rename = "default")] + FirstNonCached, + #[serde(rename = "no-focus")] + NoFocus, + #[serde(rename = "environment")] + Environment, + #[serde(rename = "username")] + Username, + #[serde(rename = "password")] + Password, +} + impl Default for Config { fn default() -> Config { toml::from_str(include_str!("../extra/config.toml")).unwrap_or_else(|_| { diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 4b96004..edb4c7d 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -6,7 +6,7 @@ use std::sync::{Arc, Mutex}; use std::time::Duration; use crate::auth::{AuthUserInfo, AuthenticationError}; -use crate::config::Config; +use crate::config::{Config, FocusBehaviour}; use crate::info_caching::{get_cached_username, set_cached_username}; use crate::post_login::{EnvironmentStartError, PostLoginEnvironment}; use status_message::StatusMessage; @@ -124,8 +124,7 @@ impl LoginForm { get_cached_username() } else { None - } - .unwrap_or_default(); + }; LoginForm { preview, @@ -140,7 +139,7 @@ impl LoginForm { username_widget: InputFieldWidget::new( InputFieldDisplayType::Echo, config.username_field.style.clone(), - preset_username, + preset_username.clone().unwrap_or_default(), ), password_widget: InputFieldWidget::new( InputFieldDisplayType::Replace( @@ -152,7 +151,16 @@ impl LoginForm { config.password_field.style.clone(), String::default(), ), - input_mode: InputMode::Normal, + input_mode: match config.focus_behaviour { + FocusBehaviour::NoFocus => InputMode::Normal, + FocusBehaviour::Environment => InputMode::Switcher, + FocusBehaviour::Username => InputMode::Username, + FocusBehaviour::Password => InputMode::Password, + FocusBehaviour::FirstNonCached => match preset_username { + Some(_) => InputMode::Password, + None => InputMode::Username, + }, + }, status_message: None, config, send_redraw_channel: None,