Commit 41e4be8f authored by Ticki's avatar Ticki

Add 'q' and command line arguments

parent 80c62d21
use std::ops::{Index, IndexMut};
use std::cmp::min;
use std::ops::{Index, IndexMut};
use std::str::Chars;
pub trait Line<'a> {
......
use editor::Editor;
use redraw::RedrawTask;
use buffer::Buffer;
use cursor::Cursor;
use editor::Editor;
use redraw::RedrawTask;
impl Editor {
/// Delete a character
......
use buffer::{Buffer, SplitBuffer};
use cursor::Cursor;
use graphics::StatusBar;
use options::Options;
use key::{Key, Cmd};
use key_state::KeyState;
use redraw::RedrawTask;
use buffer::{Buffer, SplitBuffer};
use options::Options;
use parse::Inst;
use redraw::RedrawTask;
#[cfg(feature = "orbital")]
use orbclient::Window;
use std::env::args;
/// The current state of the editor, including the file, the cursor, the scrolling info, etc.
pub struct Editor {
/// The current cursor
......@@ -73,6 +75,10 @@ impl Editor {
redraw_task: RedrawTask::Null,
};
if let Some(x) = args().skip(1).next() {
editor.open(&x);
}
debugln!(editor, "Starting Sodium");
editor.redraw();
......
......@@ -7,26 +7,26 @@ extern crate orbclient;
#[macro_use]
pub mod debug;
pub mod editor;
pub mod buffer;
pub mod parse;
pub mod key_state;
pub mod cursor;
pub mod delete;
pub mod editor;
pub mod exec;
pub mod graphics;
pub mod insert;
pub mod invert;
pub mod key;
pub mod prompt;
pub mod key_state;
pub mod mode;
pub mod motion;
pub mod movement;
pub mod open;
pub mod redraw;
pub mod options;
pub mod parse;
pub mod position;
pub mod graphics;
pub mod prompt;
pub mod redraw;
pub mod selection;
pub mod mode;
pub mod movement;
pub mod motion;
pub mod cursor;
pub mod insert;
pub mod delete;
pub mod exec;
pub mod invert;
fn main() {
editor::Editor::init();
......
use buffer::Buffer;
use editor::Editor;
use parse::Inst;
use position::to_signed_pos;
use buffer::Buffer;
impl Editor {
/// Convert an instruction to a motion (new coordinate). Returns None if the instructions given
......
use editor::Editor;
use buffer::Buffer;
use editor::Editor;
impl Editor {
/// Goto a given position. Does not automatically bound.
......
use buffer::{Buffer, SplitBuffer};
use editor::Editor;
use std::fs::File;
use std::io::Read;
use buffer::{Buffer, SplitBuffer};
pub enum OpenStatus {
Ok,
......
pub struct Options {
pub highlight: bool,
pub autoindent: bool,
pub line_marker: bool,
pub debug: bool,
pub highlight: bool,
pub line_marker: bool,
}
impl Options {
/// Create new default options
pub fn new() -> Self {
Options {
highlight: true,
autoindent: true,
line_marker: true,
debug: true, // TODO: Let this be `true` only in debug compilation cfg
highlight: true,
line_marker: true,
}
}
/// Get the given option as a mutable reference
pub fn get_mut(&mut self, name: &str) -> Option<&mut bool> {
match name {
"hightlight" | "hl" => Some(&mut self.highlight),
"autoindent" | "ai" => Some(&mut self.autoindent),
"line_marker" | "linemarker" | "linemark" | "lm" => Some(&mut self.line_marker),
"debug" | "debug_mode" => Some(&mut self.debug),
"hightlight" | "hl" => Some(&mut self.highlight),
"line_marker" | "linemarker" | "linemark" | "lm" => Some(&mut self.line_marker),
_ => None,
}
}
......@@ -30,10 +30,10 @@ impl Options {
/// Get a given option
pub fn get(&self, name: &str) -> Option<bool> {
match name {
"hightlight" | "hl" => Some(self.highlight),
"autoindent" | "ai" => Some(self.autoindent),
"line_marker" | "linemarker" | "linemark" | "lm" => Some(self.line_marker),
"debug" | "debug_mode" => Some(self.debug),
"hightlight" | "hl" => Some(self.highlight),
"line_marker" | "linemarker" | "linemark" | "lm" => Some(self.line_marker),
_ => None,
}
}
......
use key::{Cmd, Key};
use editor::Editor;
use redraw::RedrawTask;
use key::{Cmd, Key};
use mode::Mode;
use redraw::RedrawTask;
#[cfg(feature = "orbital")]
use orbclient::{EventOption, Event};
......
use editor::Editor;
use open::OpenStatus;
use std::process::exit;
impl Editor {
/// Invoke a command in the prompt
pub fn invoke(&mut self, cmd: String) {
......@@ -14,35 +16,38 @@ impl Editor {
Ok(()) => format!("Option set: {}", sec_cmd),
Err(()) => format!("Option does not exist: {}", sec_cmd),
}
}
},
"unset" => {
self.status_bar.msg = match self.options.unset(sec_cmd) {
Ok(()) => format!("Option unset: {}", sec_cmd),
Err(()) => format!("Option does not exist: {}", sec_cmd),
}
}
},
"toggle" | "tog" => {
self.status_bar.msg = match self.options.toggle(sec_cmd) {
Ok(()) => format!("Option toggled: {}", sec_cmd),
Err(()) => format!("Option does not exist: {}", sec_cmd),
}
}
},
"get" => {
self.status_bar.msg = match self.options.get(sec_cmd) {
Some(true) => format!("Option set: {}", sec_cmd),
Some(false) => format!("Option unset: {}", sec_cmd),
None => format!("Option does not exist: {}", sec_cmd),
}
}
},
"o" | "open" => {
self.status_bar.msg = match self.open(sec_cmd) {
OpenStatus::NotFound => format!("File {} could not be opened", sec_cmd),
OpenStatus::Ok => format!("File {} opened", sec_cmd),
}
}
},
"help" => {
self.open("/apps/sodium/help.txt");
}
},
"q" | "quit" => {
exit(0);
},
c => {
self.status_bar.msg = format!("Unknown command: {}", c);
}
......
use editor::Editor;
use buffer::Buffer;
use editor::Editor;
impl Editor {
/// Remove from a given motion (row based), i.e. if the motion given is to another line, all
......
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