Commit 724d1d8c authored by Ticki's avatar Ticki

Make orbital a feature

parent 33f2c85c
*.lock
*.bin
*.gen
*.list
......
[root]
name = "sodium"
version = "0.1.0"
dependencies = [
"orbtk 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "advapi32-sys"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bitflags"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "bitflags"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libc"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libc"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "num"
version = "0.1.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rand 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "orbtk"
version = "0.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"sdl2 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
"sdl2_ttf 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand"
version = "0.3.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"advapi32-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rustc-serialize"
version = "0.3.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "sdl2"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
"num 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)",
"sdl2-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "sdl2-sys"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
"num 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "sdl2_ttf"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
"sdl2 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
"sdl2-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi-build"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
......@@ -7,4 +7,6 @@ Sodium: A modern vi-like editor
"""
[dependencies]
orbtk = "*"
[features]
orbital = []
use cursor::Cursor;
use std::collections::VecDeque;
use orbital::Window;
use graphics::StatusBar;
use options::Options;
use key_state::KeyState;
use redraw::RedrawTask;
use buffer::SplitBuffer;
#[cfg(feature = "orbital")]
use orbital::Window;
/// The current state of the editor, including the file, the cursor, the scrolling info, etc.
pub struct Editor {
/// The current cursor
......@@ -38,6 +40,7 @@ impl Editor {
pub fn init() {
#[cfg(feature = "orbital")]
let window = Window::new(-1, -1, 700, 500, &"Sodium").unwrap();
let mut editor = Editor {
......
use editor::Editor;
use orbital::Color;
use redraw::RedrawTask;
use mode::Mode;
use mode::PrimitiveMode;
use mode::CommandMode;
#[cfg(feature = "orbital")]
use orbital::Color;
#[cfg(feature = "orbital")]
impl Editor {
/// Redraw the window
pub fn redraw(&mut self) {
......@@ -133,6 +136,7 @@ impl Editor {
}
}
#[cfg(feature = "orbital")]
fn status_bar(editor: &mut Editor, text: String, a: usize, b: usize) {
let h = editor.window.height();
......@@ -163,6 +167,7 @@ fn status_bar(editor: &mut Editor, text: String, a: usize, b: usize) {
}
/// The statubar (showing various info about the current state of the editor)
#[cfg(feature = "orbital")]
pub struct StatusBar {
/// The current mode
pub mode: String,
......@@ -174,6 +179,7 @@ pub struct StatusBar {
pub msg: String,
}
#[cfg(feature = "orbital")]
impl StatusBar {
/// Create new status bar
pub fn new() -> Self {
......
use orbital::*;
#[cfg(feature = "orbital")]
use orbital::{
KeyEvent,
K_LEFT_SHIFT,
K_RIGHT_SHIFT,
K_BKSP,
K_LEFT,
K_RIGHT,
K_UP,
K_DOWN,
K_TAB,
K_ESC,
};
#[derive(Copy, Clone, PartialEq)]
/// A key
......@@ -18,6 +30,7 @@ pub enum Key {
}
impl Key {
#[cfg(feature = "orbital")]
pub fn from_event(k: KeyEvent) -> Key {
match k.character {
'\0' => match k.scancode {
......
use key::Key;
#[cfg(feature = "orbital")]
use orbital::{
KeyEvent,
K_ALT,
......@@ -22,6 +23,7 @@ impl KeyState {
shift: false,
}
}
/// Feed the keystate
pub fn feed(&mut self, k: KeyEvent) -> Option<Key> {
......@@ -30,8 +32,11 @@ impl KeyState {
'\0' => {
// "I once lived here" - bug
match k.scancode {
#[cfg(feature = "orbital")]
K_ALT => self.alt = k.pressed,
#[cfg(feature = "orbital")]
K_CTRL => self.ctrl = k.pressed,
#[cfg(feature = "orbital")]
K_LEFT_SHIFT | K_RIGHT_SHIFT => self.shift = k.pressed,
_ if k.pressed => {
return Some(Key::from_event(k));
......
#![feature(stmt_expr_attributes)]
#[cfg(feature = "orbital")]
extern crate orbital;
pub mod editor;
pub mod buffer;
pub mod parse;
......
use key::{Cmd, Key};
use editor::Editor;
use orbital::{EventOption, Event};
use redraw::RedrawTask;
use mode::Mode;
#[cfg(feature = "orbital")]
use orbital::{EventOption, Event};
#[derive(Copy, Clone)]
/// An instruction, i.e. a command and a numeral parameter
pub struct Inst(pub Parameter, pub Cmd);
......@@ -38,6 +40,7 @@ impl Editor {
/// Get the next character input. Useful for commands taking a character as post-parameter,
/// such as r (replace).
pub fn get_char(&mut self) -> char {
#[cfg(feature = "orbital")]
loop {
match self.window
.poll()
......@@ -65,6 +68,7 @@ impl Editor {
self.status_bar.cmd = String::new();
// self.status_bar.cmd = String::new();
#[cfg(feature = "orbital")]
loop {
match self.window.poll()
.unwrap_or(Event::new())
......
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