Skip to content

Commit

Permalink
refactor: introduced panes and splitted each pane into separate struct 🔥
Browse files Browse the repository at this point in the history
  • Loading branch information
zaghaghi committed Mar 4, 2024
1 parent e117d0b commit f03b303
Show file tree
Hide file tree
Showing 14 changed files with 653 additions and 279 deletions.
5 changes: 2 additions & 3 deletions src/action.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use serde::{Deserialize, Serialize};
use strum::Display;

use crate::components::home::Pane;

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Display, Deserialize)]
pub enum Action {
Tick,
Expand All @@ -14,7 +12,8 @@ pub enum Action {
Refresh,
Error(String),
Help,
Focus(Pane),
FocusNext,
FocusPrev,
Up,
Down,
}
6 changes: 3 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use tokio::sync::mpsc;

use crate::{
action::Action,
components::{home::Home, Page},
config::Config,
pages::{home::Home, Page},
tui,
};

Expand All @@ -28,7 +28,7 @@ pub struct App {

impl App {
pub fn new(openapi_path: String) -> Result<Self> {
let home = Home::new(openapi_path);
let home = Home::new(openapi_path)?;
let config = Config::new()?;
let mode = Mode::Home;
Ok(Self {
Expand Down Expand Up @@ -84,7 +84,7 @@ impl App {
tui::Event::Resize(x, y) => action_tx.send(Action::Resize(x, y))?,
tui::Event::Key(key) => {
if let Some(keymap) = self.config.keybindings.get(&self.mode) {
if let Some(action) = keymap.get(&vec![key.clone()]) {
if let Some(action) = keymap.get(&vec![key]) {
log::info!("Got action: {action:?}");
action_tx.send(action.clone())?;
} else {
Expand Down
258 changes: 0 additions & 258 deletions src/components/home.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl Config {
for (mode, default_styles) in default_config.styles.iter() {
let user_styles = cfg.styles.entry(*mode).or_default();
for (style_key, style) in default_styles.iter() {
user_styles.entry(style_key.clone()).or_insert_with(|| style.clone());
user_styles.entry(style_key.clone()).or_insert_with(|| *style);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
pub mod action;
pub mod app;
pub mod cli;
pub mod components;
pub mod config;
pub mod pages;
pub mod panes;
pub mod tui;
pub mod utils;

Expand Down
13 changes: 0 additions & 13 deletions src/components.rs → src/pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,3 @@ pub trait Page {

fn draw(&mut self, f: &mut Frame<'_>, area: Rect) -> Result<()>;
}

pub trait Pane {
fn init(&mut self) -> Result<()> {
Ok(())
}

#[allow(unused_variables)]
fn update(&mut self, action: Action) -> Result<Option<Action>> {
Ok(None)
}

fn draw(&mut self, f: &mut Frame<'_>, area: Rect) -> Result<()>;
}
Loading

0 comments on commit f03b303

Please sign in to comment.