Minor change adding a spaces_per_tab function
This commit is contained in:
parent
fe4ab556f8
commit
8a38a7f1c2
|
@ -1,5 +1,9 @@
|
||||||
|
fn spaces_per_tab(){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
fn status_bar() {
|
fn status_bar() {
|
||||||
let sb = ` ${file_name}:${y}:${x} | ${file_type} | ${line_count} Lines`;
|
let sb = ` ${file_name}:${y}:${x} | ${file_type} | ${line_count} Lines | HELLO`;
|
||||||
|
|
||||||
return sb;
|
return sb;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,34 +9,35 @@ use rhai::Scope;
|
||||||
use rhai::AST;
|
use rhai::AST;
|
||||||
|
|
||||||
pub struct Config<'a> {
|
pub struct Config<'a> {
|
||||||
cfg: String,
|
pub cfg: String,
|
||||||
eng: Engine,
|
pub engine: Engine,
|
||||||
pub scope: Scope<'a>,
|
pub scope: Scope<'a>,
|
||||||
ast: AST,
|
pub ast: AST,
|
||||||
}
|
}
|
||||||
impl Config<'static> {
|
impl Config<'static> {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let mut engine = Engine::new();
|
let mut engine = Engine::new();
|
||||||
let mut scope = Scope::new();
|
let mut scope = Scope::new();
|
||||||
let ast = engine
|
let ast = engine
|
||||||
.compile_file(PathBuf::from_str("/home/able/Projects/adit/assets/config.rhai").unwrap())
|
.compile_file(PathBuf::from_str("/home/able/adit/assets/config.rhai").unwrap())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
let spaces_per_tab = engine.call_fn::<Dynamic>(&mut scope, &ast, "start", ());
|
||||||
let result = engine.call_fn::<Dynamic>(&mut scope, &ast, "status_bar", ());
|
let result = engine.call_fn::<Dynamic>(&mut scope, &ast, "status_bar", ());
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
cfg: String::new(),
|
cfg: String::new(),
|
||||||
eng: Engine::new(),
|
engine: engine,
|
||||||
scope: Scope::new(),
|
scope,
|
||||||
ast,
|
ast,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn call(&mut self, fn_name: &str) -> String {
|
pub fn call(&mut self, fn_name: &str) -> Dynamic {
|
||||||
match self
|
match self
|
||||||
.eng
|
.engine
|
||||||
.call_fn::<String>(&mut self.scope, &self.ast, fn_name, ())
|
.call_fn::<Dynamic>(&mut self.scope, &self.ast, fn_name, ())
|
||||||
{
|
{
|
||||||
Ok(string) => string,
|
Ok(ret) => ret,
|
||||||
Err(err) => panic!("{}", err),
|
Err(err) => panic!("{}", err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ impl Editor<'static> {
|
||||||
Document::default()
|
Document::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut cfg = Config::new();
|
// let mut cfg = Config::new();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
should_quit: false,
|
should_quit: false,
|
||||||
|
@ -222,8 +222,11 @@ impl Editor<'static> {
|
||||||
|
|
||||||
// NOTE: I am more of the opinion that adit should use hard tab.
|
// NOTE: I am more of the opinion that adit should use hard tab.
|
||||||
Key::Char('\t') => {
|
Key::Char('\t') => {
|
||||||
for c in " ".chars() {
|
let spaces = self.config.engine.call_fn::<i64>(&mut self.config.scope, &self.config.ast, "spaces_per_tab", () ).unwrap_or(2);
|
||||||
self.document.insert(&self.cursor_position, c);
|
|
||||||
|
|
||||||
|
for c in 0..spaces {
|
||||||
|
self.document.insert(&self.cursor_position, ' ');
|
||||||
self.move_cursor(Key::Right);
|
self.move_cursor(Key::Right);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -361,7 +364,7 @@ impl Editor<'static> {
|
||||||
self.cursor_position = Position { x, y }
|
self.cursor_position = Position { x, y }
|
||||||
}
|
}
|
||||||
fn draw_welcome_message(&mut self) {
|
fn draw_welcome_message(&mut self) {
|
||||||
let mut welcome_message = self.config.call("welcome_message");
|
let mut welcome_message:String = self.config.call("welcome_message").to_string();
|
||||||
let width = self.terminal.size().width as usize;
|
let width = self.terminal.size().width as usize;
|
||||||
let len = welcome_message.len();
|
let len = welcome_message.len();
|
||||||
#[allow(clippy::arithmetic_side_effects, clippy::integer_division)]
|
#[allow(clippy::arithmetic_side_effects, clippy::integer_division)]
|
||||||
|
@ -429,7 +432,7 @@ impl Editor<'static> {
|
||||||
.unwrap_or("buffer".to_owned()),
|
.unwrap_or("buffer".to_owned()),
|
||||||
);
|
);
|
||||||
|
|
||||||
status = self.config.call("status_bar");
|
status = self.config.call("status_bar").to_string();
|
||||||
|
|
||||||
#[allow(clippy::arithmetic_side_effects)]
|
#[allow(clippy::arithmetic_side_effects)]
|
||||||
let len = status.len();
|
let len = status.len();
|
||||||
|
|
Loading…
Reference in a new issue