Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/tools/export-content/src/main.rs
6601 views
1
//! A tool for exporting release content.
2
//!
3
//! This terminal-based tool generates a release content file
4
//! from the content of the `release-content` directory.
5
//!
6
//! To run this tool, use the following command from the `bevy` repository root:
7
//!
8
//! ```sh
9
//! cargo run -p export-content
10
//! ```
11
12
use std::{
13
io,
14
panic::{set_hook, take_hook},
15
};
16
17
use app::App;
18
use miette::{IntoDiagnostic, Result};
19
use ratatui::{
20
crossterm::{
21
event::{DisableMouseCapture, EnableMouseCapture},
22
execute,
23
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
24
},
25
prelude::*,
26
};
27
28
mod app;
29
30
fn main() -> Result<()> {
31
init_panic_hook();
32
let mut terminal = init_terminal().unwrap();
33
let res = run_app(&mut terminal);
34
restore_terminal().unwrap();
35
res
36
}
37
38
fn run_app<B: Backend>(terminal: &mut Terminal<B>) -> Result<()> {
39
let app = App::new()?;
40
app.run(terminal)
41
}
42
43
fn init_panic_hook() {
44
let original_hook = take_hook();
45
set_hook(Box::new(move |panic_info| {
46
// intentionally ignore errors here since we're already in a panic
47
let _ = restore_terminal();
48
original_hook(panic_info);
49
}));
50
}
51
52
fn init_terminal() -> Result<Terminal<impl Backend>> {
53
enable_raw_mode().into_diagnostic()?;
54
execute!(io::stdout(), EnterAlternateScreen, EnableMouseCapture).into_diagnostic()?;
55
let backend = CrosstermBackend::new(io::stdout());
56
let terminal = Terminal::new(backend).into_diagnostic()?;
57
Ok(terminal)
58
}
59
60
fn restore_terminal() -> Result<()> {
61
disable_raw_mode().into_diagnostic()?;
62
execute!(io::stdout(), LeaveAlternateScreen, DisableMouseCapture).into_diagnostic()?;
63
Ok(())
64
}
65
66