mirror of
https://github.com/coastalwhite/lemurs
synced 2024-11-26 20:10:17 +00:00
Add a configuration option for focus behaviour (#74)
* Add a configuration option for focus behaviour * Rust fmt
This commit is contained in:
parent
3a96b066c3
commit
d65b1c3fdd
3 changed files with 40 additions and 5 deletions
|
@ -41,6 +41,16 @@
|
||||||
# The tty which contains lemurs. This has to be mirrored in the lemurs.service
|
# The tty which contains lemurs. This has to be mirrored in the lemurs.service
|
||||||
tty = 2
|
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]
|
[power_controls]
|
||||||
# Allow for the shutdown option to be used
|
# Allow for the shutdown option to be used
|
||||||
allow_shutdown = true
|
allow_shutdown = true
|
||||||
|
|
|
@ -153,6 +153,9 @@ macro_rules! toml_config_struct {
|
||||||
|
|
||||||
toml_config_struct! { Config, PartialConfig,
|
toml_config_struct! { Config, PartialConfig,
|
||||||
tty => u8,
|
tty => u8,
|
||||||
|
|
||||||
|
focus_behaviour => FocusBehaviour,
|
||||||
|
|
||||||
power_controls => PowerControlConfig [PartialPowerControlConfig],
|
power_controls => PowerControlConfig [PartialPowerControlConfig],
|
||||||
environment_switcher => SwitcherConfig [PartialSwitcherConfig],
|
environment_switcher => SwitcherConfig [PartialSwitcherConfig],
|
||||||
username_field => UsernameFieldConfig [PartialUsernameFieldConfig],
|
username_field => UsernameFieldConfig [PartialUsernameFieldConfig],
|
||||||
|
@ -245,6 +248,20 @@ toml_config_struct! { PasswordFieldConfig, PartialPasswordFieldConfig,
|
||||||
style => InputFieldStyle [PartialInputFieldStyle],
|
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 {
|
impl Default for Config {
|
||||||
fn default() -> Config {
|
fn default() -> Config {
|
||||||
toml::from_str(include_str!("../extra/config.toml")).unwrap_or_else(|_| {
|
toml::from_str(include_str!("../extra/config.toml")).unwrap_or_else(|_| {
|
||||||
|
|
|
@ -6,7 +6,7 @@ use std::sync::{Arc, Mutex};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use crate::auth::{AuthUserInfo, AuthenticationError};
|
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::info_caching::{get_cached_username, set_cached_username};
|
||||||
use crate::post_login::{EnvironmentStartError, PostLoginEnvironment};
|
use crate::post_login::{EnvironmentStartError, PostLoginEnvironment};
|
||||||
use status_message::StatusMessage;
|
use status_message::StatusMessage;
|
||||||
|
@ -124,8 +124,7 @@ impl LoginForm {
|
||||||
get_cached_username()
|
get_cached_username()
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
};
|
||||||
.unwrap_or_default();
|
|
||||||
|
|
||||||
LoginForm {
|
LoginForm {
|
||||||
preview,
|
preview,
|
||||||
|
@ -140,7 +139,7 @@ impl LoginForm {
|
||||||
username_widget: InputFieldWidget::new(
|
username_widget: InputFieldWidget::new(
|
||||||
InputFieldDisplayType::Echo,
|
InputFieldDisplayType::Echo,
|
||||||
config.username_field.style.clone(),
|
config.username_field.style.clone(),
|
||||||
preset_username,
|
preset_username.clone().unwrap_or_default(),
|
||||||
),
|
),
|
||||||
password_widget: InputFieldWidget::new(
|
password_widget: InputFieldWidget::new(
|
||||||
InputFieldDisplayType::Replace(
|
InputFieldDisplayType::Replace(
|
||||||
|
@ -152,7 +151,16 @@ impl LoginForm {
|
||||||
config.password_field.style.clone(),
|
config.password_field.style.clone(),
|
||||||
String::default(),
|
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,
|
status_message: None,
|
||||||
config,
|
config,
|
||||||
send_redraw_channel: None,
|
send_redraw_channel: None,
|
||||||
|
|
Loading…
Reference in a new issue