Skip to content

Commit

Permalink
chore: update dependencies and clean up unused ones (#3)
Browse files Browse the repository at this point in the history
* chore: update dependencies and clean up unused ones

* chore: use latest version of syntect-tui

* style: format via rustfmt

* refactor: fix clippy lints

* refactor: fix clippy lints
  • Loading branch information
orhun authored Sep 12, 2024
1 parent 636acf9 commit 8383d8d
Show file tree
Hide file tree
Showing 14 changed files with 1,679 additions and 1,194 deletions.
959 changes: 678 additions & 281 deletions Cargo.lock

Large diffs are not rendered by default.

44 changes: 20 additions & 24 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,38 @@ license = "Apache-2.0"
authors = ["Chleba <[email protected]>"]
build = "build.rs"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ratatui = { version = "0.28.1", features = ["serde", "macros", "unstable-widget-ref", "unstable"] }
ratatui-image = { version = "1.0.5", features = ["crossterm"] }
crossterm = { version = "0.28.1", features = ["serde", "event-stream"] }
tui-big-text = "0.6.0"
better-panic = "0.3.0"
clap = { version = "4.4.5", features = ["derive", "cargo", "wrap_help", "unicode", "string", "unstable-styles"] }
color-eyre = "0.6.2"
syntect = "5.2.0"
clap = { version = "4.5.17", features = ["derive", "cargo", "wrap_help", "unicode", "string", "unstable-styles"] }
config = "0.14.0"
crossterm = { version = "0.27.0", features = ["serde", "event-stream"] }
derive_deref = "1.1.1"
directories = "5.0.1"
futures = "0.3.28"
human-panic = "1.2.0"
human-panic = "2.0.1"
color-eyre = "0.6.2"
dyn-clone = "1.0.11"
rustix = { version = "^0.38.4", optional = true, features = ["stdio", "termios", "fs"]}
image = "0.24.9"
image = { version = "0.25.2", default-features = false, features = ["png", "jpeg"] }
json5 = "0.4.1"
lazy_static = "1.4.0"
libc = "0.2.148"
log = "0.4.20"
pretty_assertions = "1.4.0"
ratatui = { version = "0.26.2", features = ["serde", "macros", "unstable-widget-ref", "unstable"] }
ratatui-image = { version = "1.0.0", features = ["crossterm"] }
serde = { version = "1.0.188", features = ["derive"] }
serde_json = "1.0.107"
lazy_static = "1.5.0"
serde = { version = "1.0.210", features = ["derive"] }
serde_json = "1.0.128"
signal-hook = "0.3.17"
strip-ansi-escapes = "0.2.0"
strum = { version = "0.26.1", features = ["derive"] }
tokio = { version = "1.32.0", features = ["full"] }
tokio-util = "0.7.9"
strum = { version = "0.26.3", features = ["derive"] }
tokio = { version = "1.40.0", features = ["full"] }
tokio-util = "0.7.12"
tracing = "0.1.37"
tracing-error = "0.2.0"
tracing-subscriber = { version = "0.3.17", features = ["env-filter", "serde"] }
tui-big-text = "0.4.3"
base64 = "0.22.1"
syntect = "5.2.0"
syntect-tui = "3.0.2"
syntect-tui = "3.0.4"

[build-dependencies]
vergen = { version = "8.2.6", features = [ "build", "git", "gitoxide", "cargo" ]}
vergen-gix = { version = "1.0.1", features = ["build"] }

[dev-dependencies]
pretty_assertions = "1.4.0"
8 changes: 6 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
fn main() -> Result<(), Box<dyn std::error::Error>> {
vergen::EmitBuilder::builder().all_build().all_git().emit()?;
Ok(())
let build = vergen_gix::BuildBuilder::all_build()?;
vergen_gix::Emitter::default()
.add_instructions(&build)?
.add_instructions(&vergen_gix::GixBuilder::all_git()?)?
.emit()?;
Ok(())
}
10 changes: 5 additions & 5 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl App {
tui::Event::Key(key) => {
if let Some(keymap) = self.config.keybindings.get(&self.mode) {
if let Some(action) = keymap.get(&vec![key]) {
log::info!("Got action: {action:?}");
tracing::info!("Got action: {action:?}");
action_tx.send(action.clone())?;
} else {
// If the key was not handled as a single key action,
Expand All @@ -84,7 +84,7 @@ impl App {

// Check for multi-key combinations
if let Some(action) = keymap.get(&self.last_tick_key_events) {
log::info!("Got action: {action:?}");
tracing::info!("Got action: {action:?}");
action_tx.send(action.clone())?;
}
}
Expand All @@ -101,7 +101,7 @@ impl App {

while let Ok(action) = action_rx.try_recv() {
if action != Action::Tick && action != Action::Render {
log::debug!("{action:?}");
tracing::debug!("{action:?}");
}
match action {
Action::Tick => {
Expand All @@ -114,7 +114,7 @@ impl App {
tui.resize(Rect::new(0, 0, w, h))?;
tui.draw(|f| {
for component in self.components.iter_mut() {
let r = component.draw(f, f.size());
let r = component.draw(f, f.area());
if let Err(e) = r {
action_tx
.send(Action::Error(format!("Failed to draw: {:?}", e)))
Expand All @@ -126,7 +126,7 @@ impl App {
Action::Render => {
tui.draw(|f| {
for component in self.components.iter_mut() {
let r = component.draw(f, f.size());
let r = component.draw(f, f.area());
if let Err(e) = r {
action_tx
.send(Action::Error(format!("Failed to draw: {:?}", e)))
Expand Down
220 changes: 110 additions & 110 deletions src/components.rs
Original file line number Diff line number Diff line change
@@ -1,124 +1,124 @@
use color_eyre::eyre::Result;
use crossterm::event::{KeyEvent, MouseEvent};
use ratatui::layout::Rect;
use ratatui::layout::{Rect, Size};
use tokio::sync::mpsc::UnboundedSender;

use crate::{
action::Action,
config::Config,
tui::{Event, Frame},
action::Action,
config::Config,
tui::{Event, Frame},
};

pub mod title;
pub mod slides;
pub mod title;

/// `Component` is a trait that represents a visual and interactive element of the user interface.
/// Implementors of this trait can be registered with the main application loop and will be able to receive events,
/// update state, and be rendered on the screen.
pub trait Component {
/// Register an action handler that can send actions for processing if necessary.
///
/// # Arguments
///
/// * `tx` - An unbounded sender that can send actions.
///
/// # Returns
///
/// * `Result<()>` - An Ok result or an error.
#[allow(unused_variables)]
fn register_action_handler(&mut self, tx: UnboundedSender<Action>) -> Result<()> {
Ok(())
}
/// Register a configuration handler that provides configuration settings if necessary.
///
/// # Arguments
///
/// * `config` - Configuration settings.
///
/// # Returns
///
/// * `Result<()>` - An Ok result or an error.
#[allow(unused_variables)]
fn register_config_handler(&mut self, config: Config) -> Result<()> {
Ok(())
}
/// Initialize the component with a specified area if necessary.
///
/// # Arguments
///
/// * `area` - Rectangular area to initialize the component within.
///
/// # Returns
///
/// * `Result<()>` - An Ok result or an error.
fn init(&mut self, area: Rect, json_slides: String) -> Result<()> {
Ok(())
}
/// Handle incoming events and produce actions if necessary.
///
/// # Arguments
///
/// * `event` - An optional event to be processed.
///
/// # Returns
///
/// * `Result<Option<Action>>` - An action to be processed or none.
fn handle_events(&mut self, event: Option<Event>) -> Result<Option<Action>> {
let r = match event {
Some(Event::Key(key_event)) => self.handle_key_events(key_event)?,
Some(Event::Mouse(mouse_event)) => self.handle_mouse_events(mouse_event)?,
_ => None,
};
Ok(r)
}
/// Handle key events and produce actions if necessary.
///
/// # Arguments
///
/// * `key` - A key event to be processed.
///
/// # Returns
///
/// * `Result<Option<Action>>` - An action to be processed or none.
#[allow(unused_variables)]
fn handle_key_events(&mut self, key: KeyEvent) -> Result<Option<Action>> {
Ok(None)
}
/// Handle mouse events and produce actions if necessary.
///
/// # Arguments
///
/// * `mouse` - A mouse event to be processed.
///
/// # Returns
///
/// * `Result<Option<Action>>` - An action to be processed or none.
#[allow(unused_variables)]
fn handle_mouse_events(&mut self, mouse: MouseEvent) -> Result<Option<Action>> {
Ok(None)
}
/// Update the state of the component based on a received action. (REQUIRED)
///
/// # Arguments
///
/// * `action` - An action that may modify the state of the component.
///
/// # Returns
///
/// * `Result<Option<Action>>` - An action to be processed or none.
#[allow(unused_variables)]
fn update(&mut self, action: Action) -> Result<Option<Action>> {
Ok(None)
}
/// Render the component on the screen. (REQUIRED)
///
/// # Arguments
///
/// * `f` - A frame used for rendering.
/// * `area` - The area in which the component should be drawn.
///
/// # Returns
///
/// * `Result<()>` - An Ok result or an error.
fn draw(&mut self, f: &mut Frame<'_>, area: Rect) -> Result<()>;
/// Register an action handler that can send actions for processing if necessary.
///
/// # Arguments
///
/// * `tx` - An unbounded sender that can send actions.
///
/// # Returns
///
/// * `Result<()>` - An Ok result or an error.
#[allow(unused_variables)]
fn register_action_handler(&mut self, tx: UnboundedSender<Action>) -> Result<()> {
Ok(())
}
/// Register a configuration handler that provides configuration settings if necessary.
///
/// # Arguments
///
/// * `config` - Configuration settings.
///
/// # Returns
///
/// * `Result<()>` - An Ok result or an error.
#[allow(unused_variables)]
fn register_config_handler(&mut self, config: Config) -> Result<()> {
Ok(())
}
/// Initialize the component with a specified area if necessary.
///
/// # Arguments
///
/// * `area` - Rectangular area to initialize the component within.
///
/// # Returns
///
/// * `Result<()>` - An Ok result or an error.
fn init(&mut self, _area: Size, json_slides: String) -> Result<()> {
Ok(())
}
/// Handle incoming events and produce actions if necessary.
///
/// # Arguments
///
/// * `event` - An optional event to be processed.
///
/// # Returns
///
/// * `Result<Option<Action>>` - An action to be processed or none.
fn handle_events(&mut self, event: Option<Event>) -> Result<Option<Action>> {
let r = match event {
Some(Event::Key(key_event)) => self.handle_key_events(key_event)?,
Some(Event::Mouse(mouse_event)) => self.handle_mouse_events(mouse_event)?,
_ => None,
};
Ok(r)
}
/// Handle key events and produce actions if necessary.
///
/// # Arguments
///
/// * `key` - A key event to be processed.
///
/// # Returns
///
/// * `Result<Option<Action>>` - An action to be processed or none.
#[allow(unused_variables)]
fn handle_key_events(&mut self, key: KeyEvent) -> Result<Option<Action>> {
Ok(None)
}
/// Handle mouse events and produce actions if necessary.
///
/// # Arguments
///
/// * `mouse` - A mouse event to be processed.
///
/// # Returns
///
/// * `Result<Option<Action>>` - An action to be processed or none.
#[allow(unused_variables)]
fn handle_mouse_events(&mut self, mouse: MouseEvent) -> Result<Option<Action>> {
Ok(None)
}
/// Update the state of the component based on a received action. (REQUIRED)
///
/// # Arguments
///
/// * `action` - An action that may modify the state of the component.
///
/// # Returns
///
/// * `Result<Option<Action>>` - An action to be processed or none.
#[allow(unused_variables)]
fn update(&mut self, action: Action) -> Result<Option<Action>> {
Ok(None)
}
/// Render the component on the screen. (REQUIRED)
///
/// # Arguments
///
/// * `f` - A frame used for rendering.
/// * `area` - The area in which the component should be drawn.
///
/// # Returns
///
/// * `Result<()>` - An Ok result or an error.
fn draw(&mut self, f: &mut Frame<'_>, area: Rect) -> Result<()>;
}
Loading

0 comments on commit 8383d8d

Please sign in to comment.