forked from Furumi/furumi-tui
Show both keymap notice and logging warning at startup
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
78bf2cf583
commit
595c886303
3 files changed
+49
-8
No files matched your search
+38
-5
@@ -93,6 +93,17 @@ fn now_epoch_seconds() -> i64 {
|
||||
.unwrap_or(0)
|
||||
}
|
||||
|
||||
/// Joins two optional startup status messages with `; `, keeping both.
|
||||
pub(crate) fn join_status_messages(
|
||||
first: Option<String>,
|
||||
second: Option<String>,
|
||||
) -> Option<String> {
|
||||
match (first, second) {
|
||||
(Some(left), Some(right)) => Some(format!("{left}; {right}")),
|
||||
(left, right) => left.or(right),
|
||||
}
|
||||
}
|
||||
|
||||
fn err_string(err: anyhow::Error) -> String {
|
||||
format!("{err:#}")
|
||||
}
|
||||
@@ -394,11 +405,7 @@ pub async fn run(
|
||||
tracing::info!(path = %db_path.display(), "library opened");
|
||||
|
||||
let (settings, settings_warning) = crate::config::settings::load();
|
||||
let status_message = match (startup_warning, settings_warning) {
|
||||
(Some(left), Some(right)) => Some(format!("{left}; {right}")),
|
||||
(Some(message), None) | (None, Some(message)) => Some(message),
|
||||
(None, None) => None,
|
||||
};
|
||||
let status_message = join_status_messages(startup_warning, settings_warning);
|
||||
let mut state = AppState {
|
||||
status_message,
|
||||
..AppState::default()
|
||||
@@ -4491,3 +4498,29 @@ fn push_media_metadata(state: &AppState, runtime: &Runtime) {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod status_message_tests {
|
||||
use super::join_status_messages;
|
||||
|
||||
#[test]
|
||||
fn startup_messages_are_joined_not_dropped() {
|
||||
assert_eq!(
|
||||
join_status_messages(
|
||||
Some("keymap notice".into()),
|
||||
Some("logging disabled: x".into())
|
||||
)
|
||||
.as_deref(),
|
||||
Some("keymap notice; logging disabled: x")
|
||||
);
|
||||
assert_eq!(
|
||||
join_status_messages(None, Some("only".into())).as_deref(),
|
||||
Some("only")
|
||||
);
|
||||
assert_eq!(
|
||||
join_status_messages(Some("only".into()), None).as_deref(),
|
||||
Some("only")
|
||||
);
|
||||
assert_eq!(join_status_messages(None, None), None);
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -65,7 +65,9 @@ fn main() -> Result<()> {
|
||||
// after local guards have been dropped and the terminal has been restored.
|
||||
let _stderr_capture = capture_stderr();
|
||||
let (keymap, keymap_warning) = config::keymap::Keymap::load();
|
||||
let startup_warning = keymap_warning.or(startup_warning);
|
||||
// The keymap message may be an informational notice; keep both so a
|
||||
// logging failure is not hidden behind it.
|
||||
let startup_warning = app::join_status_messages(keymap_warning, startup_warning);
|
||||
|
||||
// The app (tokio + TUI) runs on a worker thread; the main thread stays
|
||||
// dedicated to the OS media-key event loop — on macOS the system only
|
||||
|
||||
Reference in new issue
Block a user