Commit 5a32b4d0 authored by SJFrK's avatar SJFrK

Add initial command line arguments.

Add support for --version, --help/-h and -R.
-R is without function as of now.
parent ade5e35f
......@@ -13,6 +13,9 @@ use orbclient::Window;
use std::env::args;
// TODO: write proper help message
const HELP: &'static str = "Don't panic!";
/// A SplitBuffer and related state
pub struct Buffer {
/// The document
......@@ -205,10 +208,35 @@ impl Editor {
previous_instruction: None,
};
if let Some(x) = args().skip(1).next() {
editor.open(&x);
let mut files: Vec<String> = Vec::new();
for arg in args().skip(1) {
match arg.as_str() {
"--version" => {
println!("Sodium {}", option_env!("CARGO_PKG_VERSION").unwrap_or("unknown"));
return;
},
"--help" | "-h" => {
println!("{}", HELP);
return;
}
"-R" => {
match editor.options.set("readonly") {
Ok(_) => debugln!(editor, "Set readonly mode"),
Err(_) => println!("Could not set readonly mode")
}
}
_ => {
files.push(arg);
}
}
}
if files.len() > 0 {
// TODO: open multiple files into separate buffers
editor.open(&files[0]);
}
debugln!(editor, "Starting Sodium");
editor.redraw();
......
......@@ -8,6 +8,8 @@ pub struct Options {
pub highlight: bool,
/// Line marker (dimmed background of the current line).
pub line_marker: bool,
/// enables read-only mode
pub readonly: bool,
}
impl Options {
......@@ -18,6 +20,7 @@ impl Options {
debug: true, // TODO: Let this be `true` only in debug compilation cfg
highlight: true,
line_marker: true,
readonly: true, // TODO: actually implement read-only mode
}
}
......@@ -28,6 +31,7 @@ impl Options {
"debug" | "debug_mode" => Some(&mut self.debug),
"highlight" | "hl" => Some(&mut self.highlight),
"line_marker" | "linemarker" | "linemark" | "lm" => Some(&mut self.line_marker),
"readonly" | "ro" => Some(&mut self.readonly),
_ => None,
}
}
......@@ -39,6 +43,7 @@ impl Options {
"debug" | "debug_mode" => Some(self.debug),
"highlight" | "hl" => Some(self.highlight),
"line_marker" | "linemarker" | "linemark" | "lm" => Some(self.line_marker),
"readonly" | "ro" => Some(self.readonly),
_ => None,
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment