Skip to content
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
./src/snapshots
14 changes: 13 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ use std::path::PathBuf;
pub enum CurrentScreen {
Home,
BitcoinConfig,
BitcoinStatus,
P2PoolConfig,
P2PoolStatus,
LNConfig,
LNStatus,
SharesMarket,
FileExplorer,
Exiting,
}
Expand Down Expand Up @@ -41,6 +46,7 @@ pub struct App {
pub explorer: FileExplorer,
pub p2pool_config: Option<P2PoolConfig>,
pub bitcoin_data: Vec<BitcoinEntry>,
pub bitcoin_status_tab: usize,
}

impl App {
Expand All @@ -54,6 +60,7 @@ impl App {
explorer: FileExplorer::new(),
p2pool_config: None,
bitcoin_data: Vec::new(),
bitcoin_status_tab: 0,
}
}

Expand All @@ -62,7 +69,12 @@ impl App {
match self.sidebar_index {
0 => self.current_screen = CurrentScreen::Home,
1 => self.current_screen = CurrentScreen::BitcoinConfig,
2 => self.current_screen = CurrentScreen::P2PoolConfig,
2 => self.current_screen = CurrentScreen::BitcoinStatus,
3 => self.current_screen = CurrentScreen::P2PoolConfig,
4 => self.current_screen = CurrentScreen::P2PoolStatus,
5 => self.current_screen = CurrentScreen::LNConfig,
6 => self.current_screen = CurrentScreen::LNStatus,
7 => self.current_screen = CurrentScreen::SharesMarket,
_ => {}
}
}
Expand Down
72 changes: 72 additions & 0 deletions src/components/bitcoin_config_view.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// 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},
};

#[derive(Debug, Clone)]
pub struct BitcoinConfigView;

impl BitcoinConfigView {
pub fn new() -> Self {
Self
}

// Bitcoin Config
pub fn render(f: &mut Frame, app: &mut App, area: Rect) {
if app.bitcoin_conf_path.is_some() {
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);
} else {
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);
}
}
}

impl Default for BitcoinConfigView {
fn default() -> Self {
Self::new()
}
}
78 changes: 78 additions & 0 deletions src/components/bitcoin_status_view.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// SPDX-FileCopyrightText: 2024 PDM Authors
//
// SPDX-License-Identifier: AGPL-3.0-or-later

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

#[derive(Debug, Clone)]
pub struct BitcoinStatusView;

impl BitcoinStatusView {
pub fn new() -> Self {
Self
}

pub fn render(f: &mut Frame, app: &App, area: Rect) {
let outer = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Length(4), // Tabs bar
Constraint::Min(0), // Tab content
])
.split(area);

let tabs = Tabs::new(vec!["Chain Info", "System", "Logs", "Peers"])
.block(Block::default().borders(Borders::ALL).title(" Info "))
.select(app.bitcoin_status_tab)
.highlight_style(Style::default().bg(Color::Gray).fg(Color::Black));

f.render_widget(tabs, outer[0]);

let content_area = outer[1];
match app.bitcoin_status_tab {
// Chain Info
0 => {
let text = "Chain Info";
let p = Paragraph::new(text)
.block(Block::default().borders(Borders::ALL))
.wrap(Wrap { trim: true });
f.render_widget(p, content_area);
}
// System
1 => {
let text = "System";
let p = Paragraph::new(text)
.block(Block::default().borders(Borders::ALL))
.wrap(Wrap { trim: true });
f.render_widget(p, content_area);
}
// Logs
2 => {
let text = "Logs";
let p = Paragraph::new(text)
.block(Block::default().borders(Borders::ALL))
.wrap(Wrap { trim: true });
f.render_widget(p, content_area);
}
// Peers
3 => {
let text = "Peers";
let p = Paragraph::new(text)
.block(Block::default().borders(Borders::ALL))
.wrap(Wrap { trim: true });
f.render_widget(p, content_area);
}
_ => {}
}
}
}

impl Default for BitcoinStatusView {
fn default() -> Self {
Self::new()
}
}
42 changes: 39 additions & 3 deletions src/components/file_explorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
//
// SPDX-License-Identifier: AGPL-3.0-or-later

use crate::app::AppAction;
use crate::app::{App, AppAction};
use crossterm::event::{KeyCode, KeyEvent};
use ratatui::{
prelude::*,
widgets::{Block, Borders, List, ListItem, ListState},
};
use std::fs;
use std::path::PathBuf;

Expand Down Expand Up @@ -138,13 +142,45 @@ impl FileExplorer {
_ => AppAction::None,
}
}

pub fn render(f: &mut Frame, app: &mut App, area: Rect) {
let files: Vec<ListItem> = app
.explorer
.files
.iter()
.map(|path| {
let display_name = if path.ends_with("..") {
"📁 ..".to_string()
} else {
let name = path.file_name().unwrap_or_default().to_string_lossy();
if path.is_dir() {
format!("📁 {}", name)
} else {
format!("📄 {}", name)
}
};
ListItem::new(display_name)
})
.collect();

let mut state = ListState::default();
state.select(Some(app.explorer.selected_index));

let title = format!(" Select File (Current: {:?}) ", app.explorer.current_dir);

let list = List::new(files)
.block(Block::default().borders(Borders::ALL).title(title))
.highlight_style(Style::default().bg(Color::Blue).fg(Color::White))
.highlight_symbol(">> ");

f.render_stateful_widget(list, area, &mut state);
}
}

#[cfg(test)]
mod tests {
use super::*;
use std::env::temp_dir;
use std::fs::{File, create_dir};
use std::fs::File;

fn setup_temp_fs() -> PathBuf {
use std::time::{SystemTime, UNIX_EPOCH};
Expand Down
31 changes: 31 additions & 0 deletions src/components/home_view.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-FileCopyrightText: 2024 PDM Authors
//
// SPDX-License-Identifier: AGPL-3.0-or-later

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

#[derive(Debug, Clone)]
pub struct HomeView;

impl HomeView {
pub fn new() -> Self {
Self
}

pub fn render(f: &mut Frame, _app: &mut App, area: Rect) {
let p = Paragraph::new("Welcome to PDM.\n\nSelect a config from the sidebar to edit.")
.block(Block::default().borders(Borders::ALL).title(" Home "))
.wrap(Wrap { trim: true });
f.render_widget(p, area);
}
}

impl Default for HomeView {
fn default() -> Self {
Self::new()
}
}
31 changes: 31 additions & 0 deletions src/components/ln_config_view.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-FileCopyrightText: 2024 PDM Authors
//
// SPDX-License-Identifier: AGPL-3.0-or-later

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

#[derive(Debug, Clone)]
pub struct LNConfigView;

impl LNConfigView {
pub fn new() -> Self {
Self
}

// LN Config
pub fn render(f: &mut Frame, _app: &mut App, area: Rect) {
let p = Paragraph::new("LN Config")
.block(Block::default().borders(Borders::ALL).title(" LN Config "));
f.render_widget(p, area);
}
}

impl Default for LNConfigView {
fn default() -> Self {
Self::new()
}
}
31 changes: 31 additions & 0 deletions src/components/ln_status_view.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-FileCopyrightText: 2024 PDM Authors
//
// SPDX-License-Identifier: AGPL-3.0-or-later

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

#[derive(Debug, Clone)]
pub struct LNStatusView;

impl LNStatusView {
pub fn new() -> Self {
Self
}

// LN Status
pub fn render(f: &mut Frame, _app: &mut App, area: Rect) {
let p = Paragraph::new("LN Status")
.block(Block::default().borders(Borders::ALL).title(" LN Status "));
f.render_widget(p, area);
}
}

impl Default for LNStatusView {
fn default() -> Self {
Self::new()
}
}
9 changes: 9 additions & 0 deletions src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@
//
// SPDX-License-Identifier: AGPL-3.0-or-later

pub mod bitcoin_config_view;
pub mod bitcoin_status_view;
pub mod file_explorer;
pub mod home_view;
pub mod ln_config_view;
pub mod ln_status_view;
pub mod p2pool_config_view;
pub mod p2pool_status_view;
pub mod shares_market_view;
pub mod status_bar;
Loading
Loading