1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/// Main function
/// Init the status and display and listen to events (keyboard, mouse, resize, custom...).
/// The application is redrawn after every event.
/// When the user issues a quit event, the main loop is broken
/// Then we reset the cursor, drop everything holding a terminal and print the last path.
// // example plugin
// use crossterm::{
// event::{self, DisableMouseCapture, EnableMouseCapture, Event},
// execute,
// terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
// };
// use libloading::{Library, Symbol};
// use plugin_api::{DrawContext, PluginEntryFn, PluginInfo};
// use ratatui::{backend::CrosstermBackend, Terminal};
//
// use std::io;
// use std::time::Duration;
//
// struct AppContext; // dummy for now
//
// impl DrawContext for AppContext {}
//
// fn main2() -> Result<(), Box<dyn std::error::Error>> {
// enable_raw_mode()?;
// let mut stdout = io::stdout();
// execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?;
// let backend = CrosstermBackend::new(stdout);
// let mut terminal = Terminal::new(backend)?;
//
// let lib = unsafe { Library::new("plugins/hello_world/target/release/libHello_World.so")? };
// let entry: Symbol<PluginEntryFn> = unsafe { lib.get(b"plugin_entry")? };
// let plugin_info: &mut PluginInfo = unsafe { &mut *entry() };
//
// let mut ctx = AppContext;
//
// loop {
// terminal.draw(|f| {
// let area = f.area();
// (plugin_info.draw)(&mut ctx, f, area);
// })?;
//
// if event::poll(Duration::from_millis(200))? {
// if let Event::Key(k) = event::read()? {
// if (plugin_info.on_event)(&mut ctx, k) {
// println!("Plugin a consommé : {:?}", k);
// }
// if k.code == crossterm::event::KeyCode::Char('q') {
// break;
// }
// }
// }
// }
//
// disable_raw_mode()?;
// execute!(
// terminal.backend_mut(),
// LeaveAlternateScreen,
// DisableMouseCapture
// )?;
// Ok(())
// }