Skip to content

Add editing Bitcoin config file#19

Merged
pool2win merged 10 commits into
p2poolv2:mainfrom
framicheli:settings
Apr 13, 2026
Merged

Add editing Bitcoin config file#19
pool2win merged 10 commits into
p2poolv2:mainfrom
framicheli:settings

Conversation

@framicheli
Copy link
Copy Markdown
Contributor

  • Open, edit, save bitcoin.conf
  • Improved Bitcoin Config view
  • Backspace to go to parent folder in file explorer

@framicheli framicheli mentioned this pull request Apr 2, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 2, 2026

Codecov Report

❌ Patch coverage is 92.25422% with 78 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/main.rs 85.41% 35 Missing ⚠️
src/components/bitcoin_config_view.rs 94.53% 23 Missing ⚠️
src/bitcoin_config.rs 88.57% 20 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_config rewrites every enabled entry as a top-level key=value line, but parse_config explicitly 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 in ConfigEntry) 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.

Comment on lines +16 to +21
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 {
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread src/components/bitcoin_config_view.rs Outdated
Comment on lines +54 to +56
// Truncate the right side
let avail = max_len.saturating_sub(1);
format!("\u{2026}{}", &s[s.len().saturating_sub(avail)..])
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
// 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)

Copilot uses AI. Check for mistakes.
Comment thread src/main.rs Outdated
Comment on lines +221 to +236
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;
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
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;
}

Copilot uses AI. Check for mistakes.
…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)
@pool2win pool2win merged commit 35343a0 into p2poolv2:main Apr 13, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants