Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use p2poolv2_config::Config as P2PoolConfig;
use pdm::app::AppAction;
use pdm::app::{App, CurrentScreen};
use pdm::config::parse_config as parse_bitcoin_config;
use pdm::ui;
use pdm::ui::ui;

use anyhow::Result;
use crossterm::{
Expand Down Expand Up @@ -43,7 +43,7 @@ fn main() -> Result<()> {

fn run_app<B: Backend>(terminal: &mut Terminal<B>, app: &mut App) -> Result<()> {
loop {
terminal.draw(|f| ui::ui(f, app))?;
terminal.draw(|f| ui(f, app))?;

if let Event::Key(key) = event::read()? {
if key.kind != KeyEventKind::Press {
Expand Down Expand Up @@ -167,14 +167,14 @@ mod tests {
let mut app = App::new();

// Initial render
terminal.draw(|f| ui::ui(f, &mut app)).unwrap();
terminal.draw(|f| ui(f, &mut app)).unwrap();
insta::assert_debug_snapshot!("home_screen", terminal.backend());

// Simulate sidebar move
app.sidebar_index = 1;
app.toggle_menu();

terminal.draw(|f| ui::ui(f, &mut app)).unwrap();
terminal.draw(|f| ui(f, &mut app)).unwrap();
insta::assert_debug_snapshot!("menu_toggled", terminal.backend());

assert_eq!(app.current_screen, CurrentScreen::BitcoinConfig);
Expand Down Expand Up @@ -204,7 +204,7 @@ mod tests {
handle_action(AppAction::CloseModal, &mut app).unwrap();
assert_eq!(app.current_screen, CurrentScreen::BitcoinConfig);

terminal.draw(|f| ui::ui(f, &mut app)).unwrap();
terminal.draw(|f| ui(f, &mut app)).unwrap();
}

#[test]
Expand Down Expand Up @@ -246,7 +246,7 @@ mod tests {

assert_eq!(app.bitcoin_conf_path, Some(file_path));

terminal.draw(|f| ui::ui(f, &mut app)).unwrap();
terminal.draw(|f| ui(f, &mut app)).unwrap();
}

#[test]
Expand Down
275 changes: 0 additions & 275 deletions src/ui.rs

This file was deleted.

58 changes: 58 additions & 0 deletions src/ui/bitcoin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// SPDX-FileCopyrightText: 2024 PDM Authors
//
// SPDX-License-Identifier: AGPL-3.0-or-later

use crate::app::App;
use ratatui::{
prelude::*,
widgets::{Block, Borders, List, ListItem, Paragraph},
};

// Render the bitcoin config view when no config is loaded yet.
pub fn render(f: &mut Frame, app: &mut App, area: Rect) {
if app.bitcoin_conf_path.is_none() {
let p = Paragraph::new("Press [Enter] to select a bitcoin.conf file").block(
Block::default()
.borders(Borders::ALL)
.title(" Bitcoin Config "),
);
f.render_widget(p, area);
return;
}

let items: Vec<ListItem> = app
.bitcoin_data
.iter()
.map(|entry| {
let style = if entry.enabled {
Style::default()
.fg(Color::White)
.add_modifier(Modifier::BOLD)
} else {
Style::default().fg(Color::DarkGray)
};

let content = Line::from(vec![
Span::styled(format!("{} = ", entry.key), style),
Span::styled(&entry.value, style),
if !entry.enabled {
Span::styled(" (disabled)", style)
} else {
Span::raw("")
},
]);

ListItem::new(content)
})
.collect();

let list = List::new(items)
.block(
Block::default()
.borders(Borders::ALL)
.title(" Bitcoin Configuration "),
)
.highlight_style(Style::default().bg(Color::Yellow));

f.render_widget(list, area);
}
Loading
Loading