Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/tools/export-content/src/main.rs
6849 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
use crate::app::Content;
29
30
mod app;
31
32
fn main() -> Result<()> {
33
let check = std::env::args().any(|arg| arg == "--check");
34
if check {
35
Content::load().unwrap();
36
return Ok(());
37
}
38
39
init_panic_hook();
40
let mut terminal = init_terminal().unwrap();
41
let res = run_app(&mut terminal);
42
restore_terminal().unwrap();
43
res
44
}
45
46
fn run_app<B: Backend>(terminal: &mut Terminal<B>) -> Result<()> {
47
let app = App::new()?;
48
app.run(terminal)
49
}
50
51
fn init_panic_hook() {
52
let original_hook = take_hook();
53
set_hook(Box::new(move |panic_info| {
54
// intentionally ignore errors here since we're already in a panic
55
let _ = restore_terminal();
56
original_hook(panic_info);
57
}));
58
}
59
60
fn init_terminal() -> Result<Terminal<impl Backend>> {
61
enable_raw_mode().into_diagnostic()?;
62
execute!(io::stdout(), EnterAlternateScreen, EnableMouseCapture).into_diagnostic()?;
63
let backend = CrosstermBackend::new(io::stdout());
64
let terminal = Terminal::new(backend).into_diagnostic()?;
65
Ok(terminal)
66
}
67
68
fn restore_terminal() -> Result<()> {
69
disable_raw_mode().into_diagnostic()?;
70
execute!(io::stdout(), LeaveAlternateScreen, DisableMouseCapture).into_diagnostic()?;
71
Ok(())
72
}
73
74