Adding in and renaming stuff and such
This commit is contained in:
parent
f03b9e41cc
commit
589649298c
11
README.md
Normal file
11
README.md
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# adit
|
||||||
|
|
||||||
|
|
||||||
|
## TODO
|
||||||
|
|
||||||
|
|
||||||
|
- Custom key binds
|
||||||
|
- Custom syntax highlighting
|
||||||
|
-
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,18 @@ fn welcome_message(){
|
||||||
return wm;
|
return wm;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_start(){
|
fn presave() {
|
||||||
|
// Make this more usable later
|
||||||
|
|
||||||
|
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn on_start(){}
|
||||||
|
|
||||||
|
fn on_key(){}
|
||||||
|
|
||||||
|
|
||||||
fn filetype(file) {
|
fn filetype(file) {
|
||||||
switch file {
|
switch file {
|
||||||
"rs" => {
|
"rs" => {
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
use crate::FileType;
|
use crate::{
|
||||||
use crate::Position;
|
FileType,
|
||||||
use crate::Row;
|
Position,
|
||||||
use crate::SearchDirection;
|
Row,
|
||||||
use std::fs;
|
SearchDirection
|
||||||
use std::io::{Error, Write};
|
};
|
||||||
|
use std::{
|
||||||
|
fs,
|
||||||
|
io::{Error, Write},
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Document {
|
pub struct Document {
|
||||||
|
@ -60,6 +64,7 @@ impl Document {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
|
|
||||||
if c == '\n' {
|
if c == '\n' {
|
||||||
self.insert_newline(at);
|
self.insert_newline(at);
|
||||||
} else if at.y == self.rows.len() {
|
} else if at.y == self.rows.len() {
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use crate::config::Config;
|
use {
|
||||||
use crate::config::Theme;
|
crate::{
|
||||||
use crate::Document;
|
config::{Config, Theme},
|
||||||
use crate::Row;
|
Document, Row, Terminal,
|
||||||
use crate::Terminal;
|
},
|
||||||
use core::time::Duration;
|
core::time::Duration,
|
||||||
use std::env;
|
std::{env, time::Instant},
|
||||||
use std::time::Instant;
|
termion::event::Key,
|
||||||
use termion::event::Key;
|
};
|
||||||
|
|
||||||
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
const QUIT_TIMES: u8 = 2;
|
const QUIT_TIMES: u8 = 2;
|
||||||
|
@ -64,6 +64,7 @@ impl Editor<'static> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn default() -> Self {
|
pub fn default() -> Self {
|
||||||
let args: Vec<String> = env::args().collect();
|
let args: Vec<String> = env::args().collect();
|
||||||
let mut initial_status =
|
let mut initial_status =
|
||||||
|
@ -155,7 +156,8 @@ impl Editor<'static> {
|
||||||
}
|
}
|
||||||
self.document.file_name = new_name;
|
self.document.file_name = new_name;
|
||||||
}
|
}
|
||||||
|
// TODO
|
||||||
|
self.config.call("presave");
|
||||||
if self.document.save().is_ok() {
|
if self.document.save().is_ok() {
|
||||||
self.status_message = StatusMessage::from("File saved successfully.".to_string());
|
self.status_message = StatusMessage::from("File saved successfully.".to_string());
|
||||||
} else {
|
} else {
|
||||||
|
@ -202,6 +204,7 @@ impl Editor<'static> {
|
||||||
}
|
}
|
||||||
fn process_keypress(&mut self) -> Result<(), std::io::Error> {
|
fn process_keypress(&mut self) -> Result<(), std::io::Error> {
|
||||||
let pressed_key = Terminal::read_key()?;
|
let pressed_key = Terminal::read_key()?;
|
||||||
|
// TODO: break this out into the config
|
||||||
match pressed_key {
|
match pressed_key {
|
||||||
Key::Ctrl('q') => {
|
Key::Ctrl('q') => {
|
||||||
if self.quit_times > 0 && self.document.is_dirty() {
|
if self.quit_times > 0 && self.document.is_dirty() {
|
||||||
|
@ -225,6 +228,29 @@ impl Editor<'static> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Key::Char('(') => {
|
||||||
|
self.document.insert(&self.cursor_position, ')');
|
||||||
|
self.document.insert(&self.cursor_position, '(');
|
||||||
|
self.move_cursor(Key::Right);
|
||||||
|
}
|
||||||
|
|
||||||
|
Key::Char('[') => {
|
||||||
|
self.document.insert(&self.cursor_position, ']');
|
||||||
|
self.document.insert(&self.cursor_position, '[');
|
||||||
|
self.move_cursor(Key::Right);
|
||||||
|
}
|
||||||
|
|
||||||
|
Key::Char('{') => {
|
||||||
|
self.document.insert(&self.cursor_position, '}');
|
||||||
|
self.document.insert(&self.cursor_position, '{');
|
||||||
|
self.move_cursor(Key::Right);
|
||||||
|
}
|
||||||
|
Key::Char('"') => {
|
||||||
|
self.document.insert(&self.cursor_position, '"');
|
||||||
|
self.document.insert(&self.cursor_position, '"');
|
||||||
|
self.move_cursor(Key::Right);
|
||||||
|
}
|
||||||
|
|
||||||
Key::Char(c) => {
|
Key::Char(c) => {
|
||||||
self.document.insert(&self.cursor_position, c);
|
self.document.insert(&self.cursor_position, c);
|
||||||
self.move_cursor(Key::Right);
|
self.move_cursor(Key::Right);
|
||||||
|
|
Loading…
Reference in a new issue