mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
128 lines
2.7 KiB
Rust
128 lines
2.7 KiB
Rust
pub type Usually<T> = Result<T, Box<dyn Error>>;
|
|
|
|
pub use crate::draw::*;
|
|
|
|
pub use crate::device::{
|
|
Device,
|
|
DynamicDevice,
|
|
AppEvent,
|
|
};
|
|
|
|
pub use crate::time::*;
|
|
|
|
pub use crate::layout::{
|
|
Rows,
|
|
Columns
|
|
};
|
|
|
|
pub use std::error::Error;
|
|
|
|
pub use std::io::{
|
|
stdout,
|
|
Stdout,
|
|
Write
|
|
};
|
|
|
|
pub use std::thread::{
|
|
spawn,
|
|
JoinHandle
|
|
};
|
|
|
|
pub use std::time::Duration;
|
|
|
|
pub use std::sync::{
|
|
Arc,
|
|
Mutex,
|
|
atomic::{
|
|
Ordering,
|
|
AtomicBool,
|
|
AtomicUsize
|
|
},
|
|
mpsc::{self, channel, Sender, Receiver}
|
|
};
|
|
|
|
pub use crossterm::{
|
|
ExecutableCommand, QueueableCommand,
|
|
event::{Event, KeyEvent, KeyCode, KeyModifiers},
|
|
terminal::{
|
|
self,
|
|
Clear, ClearType,
|
|
EnterAlternateScreen, LeaveAlternateScreen,
|
|
enable_raw_mode, disable_raw_mode
|
|
},
|
|
};
|
|
|
|
pub use ratatui::{
|
|
prelude::{
|
|
Buffer, Rect, Style, Color, CrosstermBackend, Layout, Stylize, Direction,
|
|
Line, Constraint
|
|
},
|
|
widgets::{Widget, WidgetRef},
|
|
//style::Stylize,
|
|
};
|
|
|
|
pub use jack::{
|
|
AsyncClient,
|
|
AudioIn,
|
|
AudioOut,
|
|
Client,
|
|
ClientOptions,
|
|
ClientStatus,
|
|
ClosureProcessHandler,
|
|
Control,
|
|
Frames,
|
|
MidiIn,
|
|
MidiOut,
|
|
NotificationHandler,
|
|
Port,
|
|
PortId,
|
|
ProcessHandler,
|
|
ProcessScope,
|
|
RawMidi,
|
|
Transport,
|
|
TransportState,
|
|
TransportStatePosition
|
|
};
|
|
|
|
pub type BoxedNotificationHandler = Box<dyn Fn(AppEvent) + Send>;
|
|
|
|
pub type BoxedProcessHandler = Box<dyn FnMut(&Client, &ProcessScope)-> Control + Send>;
|
|
|
|
pub type Jack<N> = AsyncClient<N, ClosureProcessHandler<BoxedProcessHandler>>;
|
|
|
|
pub type KeyBinding<T> = (
|
|
KeyCode, KeyModifiers, &'static str, &'static str, &'static dyn Fn(&mut T)
|
|
);
|
|
|
|
#[macro_export] macro_rules! key {
|
|
($k:ident $(($char:literal))?, $m:ident, $n: literal, $d: literal, $f: ident) => {
|
|
(KeyCode::$k $(($char))?, KeyModifiers::$m, $n, $d, &$f)
|
|
};
|
|
}
|
|
|
|
#[macro_export] macro_rules! keymap {
|
|
($T:ty { $([$k:ident $(($char:literal))?, $m:ident, $n: literal, $d: literal, $f: ident]),* }) => {
|
|
&[
|
|
$((KeyCode::$k $(($char))?, KeyModifiers::$m, $n, $d, &$f as &'static dyn Fn(&mut $T))),*
|
|
] as &'static [KeyBinding<$T>]
|
|
}
|
|
}
|
|
|
|
pub use crate::{key, keymap};
|
|
|
|
pub fn handle_keymap <T> (
|
|
commands: &[KeyBinding<T>], state: &mut T, event: &AppEvent
|
|
) -> Result<bool, Box<dyn Error>> {
|
|
match event {
|
|
AppEvent::Input(Event::Key(event)) => {
|
|
for (code, modifiers, _, _, command) in commands.iter() {
|
|
if *code == event.code && modifiers.bits() == event.modifiers.bits() {
|
|
command(state);
|
|
return Ok(true)
|
|
}
|
|
}
|
|
},
|
|
_ => {}
|
|
};
|
|
Ok(false)
|
|
}
|