Skip to content

Commit

Permalink
add development notice
Browse files Browse the repository at this point in the history
  • Loading branch information
Builditluc committed Mar 21, 2024
1 parent 9c52db4 commit dbd06af
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 88 deletions.
86 changes: 2 additions & 84 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use anyhow::Result;
use crossterm::event::{KeyCode, KeyEvent};
use ratatui::prelude::{Constraint, Direction, Layout, Rect};
use std::sync::Arc;
use tracing::warn;
use wiki_api::{languages::Language, Endpoint};

use tokio::sync::{mpsc, Mutex};
use tokio::sync::mpsc;

use crate::{
action::{Action, ActionPacket, ActionResult},
Expand All @@ -18,11 +17,9 @@ use crate::{
status::{StatusComponent, STATUS_HEIGHT},
Component,
},
event::EventHandler,
has_modifier, key_event,
page_loader::PageLoader,
terminal::{Frame, Tui},
trace_dbg,
terminal::Frame,
ui::centered_rect,
};

Expand Down Expand Up @@ -254,82 +251,3 @@ impl Component for AppComponent {
}
}
}

pub struct App {
pub app_component: Arc<Mutex<AppComponent>>,
pub should_quit: bool,
}

impl App {
pub fn new() -> Self {
Self {
app_component: Arc::new(Mutex::new(AppComponent::default())),
should_quit: false,
}
}

pub async fn run(&mut self, actions: Option<ActionPacket>) -> Result<()> {
let (action_tx, mut action_rx) = mpsc::unbounded_channel();

self.app_component.lock().await.init(action_tx.clone())?;

let mut tui = Tui::new()?;
tui.enter()?;

let _action_tx = action_tx.clone();
let _root = self.app_component.clone();

tokio::spawn(async move {
let render_tick = 20;
let mut event_handler = EventHandler::new(render_tick);
loop {
let event = event_handler.next().await;
if let ActionResult::Consumed(action) = _root.lock().await.handle_events(event) {
action.send(&_action_tx);
}
}
});

if let Some(actions) = actions {
let _action_tx = action_tx.clone();
tokio::spawn(async move {
actions.send(&_action_tx);
});
}

loop {
if let Some(action) = action_rx.recv().await {
if !matches!(action, Action::RenderTick) {
trace_dbg!(&action);
}

match action {
Action::RenderTick => {
let mut app_component = self.app_component.lock().await;
tui.terminal
.draw(|frame| app_component.render(frame, frame.size()))
.unwrap();
}
Action::Quit => self.should_quit = true,
action => match self.app_component.lock().await.update(action) {
ActionResult::Consumed(action) => action.send(&action_tx),
ActionResult::Ignored => {}
},
}
}

if self.should_quit {
break;
}
}

tui.exit()?;
Ok(())
}
}

impl Default for App {
fn default() -> Self {
Self::new()
}
}
2 changes: 1 addition & 1 deletion src/components/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::terminal::Frame;

use super::Component;

const HELP_MSG: &str = "Press [?] for help";
const HELP_MSG: &str = "DEVELOPMENT VERSION - Press [?] for help";
const HELP_MSG_LEN: u16 = HELP_MSG.len() as u16;

pub const STATUS_HEIGHT: u16 = 1;
Expand Down
92 changes: 89 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,103 @@
use std::sync::Arc;

use anyhow::Result;
use tokio::sync::{mpsc, Mutex};
use wiki_tui::{
app::App, cli::match_cli, logging::initialize_logging, panic_handler::initialize_panic_handler,
action::{Action, ActionResult},
app::AppComponent,
cli::match_cli,
components::Component,
event::EventHandler,
logging::initialize_logging,
panic_handler::initialize_panic_handler,
terminal::Tui,
trace_dbg,
};

#[tokio::main]
async fn main() -> Result<()> {
println!(
r#"
IMPORTANT:
wiki-tui is going through a major rewrite (we're going async and switching backends, among other
things). Please note that this is a DEVELOPMENT version and can / will include:
- BUGS
- MISSING FEATURES
- other issues...
For more information about the rewrite, please refer to PR#226 (and its linked issues):
https://github.com/Builditluc/wiki-tui/pull/226
Please feel free to try out this version, and report bugs / suggestions / etc.!
Thank you!
- Builditluc
"#
);

let actions = match_cli();

initialize_logging()?;
initialize_panic_handler()?;

let mut app = App::new();
app.run(actions).await?;
let (action_tx, mut action_rx) = mpsc::unbounded_channel();

let app_component = Arc::new(Mutex::new(AppComponent::default()));
let mut should_quit = false;

app_component.lock().await.init(action_tx.clone())?;

let mut tui = Tui::new()?;
tui.enter()?;

let _action_tx = action_tx.clone();
let _root = app_component.clone();

// Event Thread
tokio::spawn(async move {
let render_tick = 20;
let mut event_handler = EventHandler::new(render_tick);
loop {
let event = event_handler.next().await;
if let ActionResult::Consumed(action) = _root.lock().await.handle_events(event) {
action.send(&_action_tx);
}
}
});

// Send actions to be run at startup
if let Some(actions) = actions {
let _action_tx = action_tx.clone();
tokio::spawn(async move {
actions.send(&_action_tx);
});
}

// Main Loop
loop {
if let Some(action) = action_rx.recv().await {
if !matches!(action, Action::RenderTick) {
trace_dbg!(&action);
}

match action {
Action::RenderTick => {
let mut app_component = app_component.lock().await;
tui.terminal
.draw(|frame| app_component.render(frame, frame.size()))
.unwrap();
}
Action::Quit => should_quit = true,
action => match app_component.lock().await.update(action) {
ActionResult::Consumed(action) => action.send(&action_tx),
ActionResult::Ignored => {}
},
}
}

if should_quit {
break;
}
}

tui.exit()?;
Ok(())
}

0 comments on commit dbd06af

Please sign in to comment.