summaryrefslogtreecommitdiff
path: root/src/bin/br
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/br')
-rw-r--r--src/bin/br/main.rs34
1 files changed, 25 insertions, 9 deletions
diff --git a/src/bin/br/main.rs b/src/bin/br/main.rs
index 81c5ec9..da11a18 100644
--- a/src/bin/br/main.rs
+++ b/src/bin/br/main.rs
@@ -55,6 +55,7 @@ fn main() {
args.named("size").short('s');
args.named("decode-stdin").short('i');
args.named("encode-stdout").short('o');
+ args.named("trust-files");
args.raise_errors();
let source = args.get("source").as_path_opt();
@@ -71,6 +72,7 @@ fn main() {
};
let decode_stdin = args.get("decode-stdin").as_bool();
let encode_stdout = args.get("encode-stdout").as_bool();
+ let trust_files = args.get("trust-files").as_bool();
// -----------------------------------------------------------------------
@@ -78,7 +80,9 @@ fn main() {
let mut title = String::from("Bedrock program");
let mut icon = None;
- if let Some(metadata) = Metadata::from(&bytecode) {
+ let metadata = Metadata::from(&bytecode);
+
+ if let Some(ref metadata) = metadata {
let name = metadata.name().unwrap_or("unnamed".to_string());
let authors = metadata.authors().unwrap_or_else(Vec::new);
let mut metadata_string = format!("Program is '{name}'");
@@ -110,16 +114,26 @@ fn main() {
path.add_extension("sym"); path
});
+ let name = metadata.and_then(|m| m.name()).and_then(|n| match n.split_once('/') {
+ Some((name, _)) => Some(name.to_string()),
+ None => Some(n),
+ });
+ let identifier = name.as_ref().and_then(
+ |n| Some(n.to_lowercase().chars().filter_map(
+ |c| c.is_alphanumeric().then_some(c)
+ ).collect())
+ );
+
let config = EmulatorConfig {
dimensions, fullscreen, zoom, palette, show_cursor,
- decode_stdin, encode_stdout,
- symbols_path, title, icon,
+ decode_stdin, encode_stdout, trust_files,
+ symbols_path, name, identifier, title, icon,
};
- if let Ok(phosphor) = Phosphor::new() {
- match mode {
+ match Phosphor::new() {
+ Ok(phosphor) => match mode {
Mode::Dynamic => {
- info!("Starting graphical emulator");
+ info!("Starting graphical emulator (hidden)");
let mut emulator = GraphicalEmulator::new(config, debug);
emulator.load_program(&bytecode);
emulator.run(phosphor, false);
@@ -128,7 +142,7 @@ fn main() {
info!("Starting graphical emulator");
let mut emulator = GraphicalEmulator::new(config, debug);
emulator.load_program(&bytecode);
- emulator.run(phosphor, false);
+ emulator.run(phosphor, true);
}
Mode::Headless => {
info!("Starting headless emulator");
@@ -137,9 +151,9 @@ fn main() {
emulator.run();
}
}
- } else {
- match mode {
+ Err(err) => match mode {
Mode::Dynamic => {
+ eprintln!("EventLoopError: {err:?}");
info!("Could not start graphical event loop");
info!("Starting headless emulator");
let mut emulator = HeadlessEmulator::new(&config, debug);
@@ -147,6 +161,7 @@ fn main() {
emulator.run();
}
Mode::Graphical => {
+ eprintln!("EventLoopError: {err:?}");
fatal!("Could not start graphical event loop");
}
Mode::Headless => {
@@ -210,6 +225,7 @@ Switches:
--debug, (-d) Show debug information while the program is running
--decode-stdin (-i) Decode transmissions on standard input from text lines.
--encode-stdout (-o) Encode transmissions on standard output as text lines.
+ --trust-files Give the program unrestricted access to the file system.
--help (-h) Print this help information
--verbose, (-v) Print additional information
--version Print the program version and exit