Add editing Bitcoin config file#19
Conversation
framicheli
commented
Apr 2, 2026
- Open, edit, save bitcoin.conf
- Improved Bitcoin Config view
- Backspace to go to parent folder in file explorer
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
Adds an interactive Bitcoin config workflow to the TUI (select bitcoin.conf, browse entries, edit values, and save), plus small UX improvements to the file explorer and status bar.
Changes:
- Introduce an editable Bitcoin Config screen with entry list + detail panel, in-place value editing, and “save config” action.
- Enhance the file explorer with Backspace-to-parent navigation and updated status-bar hints/warnings/success messaging.
- Update snapshot tests to reflect the new UI/status bar behavior.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/main.rs |
Adds Bitcoin Config-specific input handling plus new actions for commit/edit/save and file validation messaging. |
src/app.rs |
Extends app state with BitcoinConfigView and adds new AppActions for editing/saving. |
src/components/bitcoin_config_view.rs |
Implements the new Bitcoin config UI (two-panel layout), edit mode, and path title shortening. |
src/bitcoin_config.rs |
Adds save_config() to write edited config back to disk. |
src/components/file_explorer.rs |
Adds Backspace navigation to the parent directory and corresponding tests. |
src/components/status_bar.rs |
Updates hints for the new flows (edit/save/back, warnings, success message) and adds tests. |
src/lib.rs |
Exposes the new bitcoin_config module and removes the old config module export. |
tests/snapshots/ui_snapshots__config_screen_render.snap |
Snapshot update for revised status bar text/layout. |
src/snapshots/pdm__ui__tests__bitcoin_config_screen_render.snap |
Snapshot update for revised Bitcoin Config screen rendering. |
src/snapshots/pdm__tests__menu_toggled.snap |
Snapshot update for revised status bar text/layout. |
Comments suppressed due to low confidence (1)
src/bitcoin_config.rs:1390
save_configrewrites every enabled entry as a top-levelkey=valueline, butparse_configexplicitly reads values from INI sections (main/test/signet/regtest). Any value that originally came from a section will be saved without its section, changing Bitcoin Core semantics. To avoid incorrect configs, preserve the section when parsing (store it inConfigEntry) and write entries back into the appropriate INI section(s) instead of flattening.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let home = std::env::var("HOME").unwrap_or_default(); | ||
| let full = path.to_string_lossy().into_owned(); | ||
|
|
||
| let s = if !home.is_empty() && full.starts_with(&home) { | ||
| format!("~{}", &full[home.len()..]) | ||
| } else { |
There was a problem hiding this comment.
shorten_path slices a UTF-8 String with &full[home.len()..]. This will panic if the slice boundaries ever fall on a non-ASCII character boundary (e.g., HOME/path containing multi-byte characters). Prefer strip_prefix(&home) (or operating on Path/OsStr) instead of byte indexing.
| // Truncate the right side | ||
| let avail = max_len.saturating_sub(1); | ||
| format!("\u{2026}{}", &s[s.len().saturating_sub(avail)..]) |
There was a problem hiding this comment.
format!("…{}", &s[s.len().saturating_sub(avail)..]) can panic for paths containing non-ASCII characters because the computed start index may split a UTF-8 codepoint. Use a char-based truncation approach (e.g., s.chars()), or a unicode-width aware truncation helper, to guarantee valid boundaries.
| // Truncate the right side | |
| let avail = max_len.saturating_sub(1); | |
| format!("\u{2026}{}", &s[s.len().saturating_sub(avail)..]) | |
| // Truncate the right side on character boundaries. | |
| let avail = max_len.saturating_sub(1); | |
| let total_chars = s.chars().count(); | |
| let suffix: String = s | |
| .chars() | |
| .skip(total_chars.saturating_sub(avail)) | |
| .collect(); | |
| format!("\u{2026}{}", suffix) |
| let entries = parse_bitcoin_config(&path).unwrap_or_default(); | ||
| let has_known_keys = | ||
| entries.iter().any(|e| e.enabled && e.schema.is_some()); | ||
|
|
||
| if has_known_keys { | ||
| app.bitcoin_conf_path = Some(path.clone()); | ||
| app.bitcoin_data = entries; | ||
| app.current_screen = CurrentScreen::BitcoinConfig; | ||
| app.bitcoin_config_view.sidebar_focused = false; | ||
| app.bitcoin_config_view.warning_message = None; | ||
| } else { | ||
| app.bitcoin_config_view.warning_message = Some( | ||
| "File does not appear to be a Bitcoin config. Select another file." | ||
| .to_string(), | ||
| ); | ||
| app.current_screen = CurrentScreen::BitcoinConfig; |
There was a problem hiding this comment.
parse_bitcoin_config(&path).unwrap_or_default() discards the actual parse/I/O error and can incorrectly show the “not a Bitcoin config” warning for cases like permission denied or malformed INI. Handle Err(e) separately and surface an actionable error message to the user (and avoid treating parse failure as an empty config).
| let entries = parse_bitcoin_config(&path).unwrap_or_default(); | |
| let has_known_keys = | |
| entries.iter().any(|e| e.enabled && e.schema.is_some()); | |
| if has_known_keys { | |
| app.bitcoin_conf_path = Some(path.clone()); | |
| app.bitcoin_data = entries; | |
| app.current_screen = CurrentScreen::BitcoinConfig; | |
| app.bitcoin_config_view.sidebar_focused = false; | |
| app.bitcoin_config_view.warning_message = None; | |
| } else { | |
| app.bitcoin_config_view.warning_message = Some( | |
| "File does not appear to be a Bitcoin config. Select another file." | |
| .to_string(), | |
| ); | |
| app.current_screen = CurrentScreen::BitcoinConfig; | |
| match parse_bitcoin_config(&path) { | |
| Ok(entries) => { | |
| let has_known_keys = | |
| entries.iter().any(|e| e.enabled && e.schema.is_some()); | |
| if has_known_keys { | |
| app.bitcoin_conf_path = Some(path.clone()); | |
| app.bitcoin_data = entries; | |
| app.current_screen = CurrentScreen::BitcoinConfig; | |
| app.bitcoin_config_view.sidebar_focused = false; | |
| app.bitcoin_config_view.warning_message = None; | |
| } else { | |
| app.bitcoin_config_view.warning_message = Some( | |
| "File does not appear to be a Bitcoin config. Select another file." | |
| .to_string(), | |
| ); | |
| app.current_screen = CurrentScreen::BitcoinConfig; | |
| } | |
| } | |
| Err(e) => { | |
| app.bitcoin_config_view.warning_message = Some(format!( | |
| "Failed to read or parse Bitcoin config: {e}. Check file permissions and format, then try again." | |
| )); | |
| app.current_screen = CurrentScreen::BitcoinConfig; | |
| } |
…ving bitcoin conf, UI tweaks - shorten_path panics on non-ASCII HOME prefix (bitcoin_config_view.rs) - Right-side truncation byte-slices (bitcoin_config_view.rs) - parse_bitcoin_config().unwrap_or_default() discards I/O errors (main.rs) - save_config flattened INI sections (bitcoin_config.rs) - save_message was cleared before it could render (bitcoin_config_view.rs) - sidebar_index < 3 bug in BitcoinStatus (main.rs) - selected_index not reset on file reload (main.rs) - Magic number 7 repeated in 4 places (app.rs, main.rs) - ConfigType rendered with debug format (bitcoin_config_view.rs) - candidate.len() used byte length (bitcoin_config_view.rs)