Minor change adding a spaces_per_tab function

This commit is contained in:
Able 2024-11-20 08:49:50 -06:00
parent fe4ab556f8
commit 8a38a7f1c2
3 changed files with 24 additions and 16 deletions

View file

@ -1,5 +1,9 @@
fn spaces_per_tab(){
return 1;
}
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;
}

View file

@ -9,34 +9,35 @@ use rhai::Scope;
use rhai::AST;
pub struct Config<'a> {
cfg: String,
eng: Engine,
pub cfg: String,
pub engine: Engine,
pub scope: Scope<'a>,
ast: AST,
pub ast: AST,
}
impl Config<'static> {
pub fn new() -> Self {
let mut engine = Engine::new();
let mut scope = Scope::new();
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();
let spaces_per_tab = engine.call_fn::<Dynamic>(&mut scope, &ast, "start", ());
let result = engine.call_fn::<Dynamic>(&mut scope, &ast, "status_bar", ());
Self {
cfg: String::new(),
eng: Engine::new(),
scope: Scope::new(),
engine: engine,
scope,
ast,
}
}
pub fn call(&mut self, fn_name: &str) -> String {
pub fn call(&mut self, fn_name: &str) -> Dynamic {
match self
.eng
.call_fn::<String>(&mut self.scope, &self.ast, fn_name, ())
.engine
.call_fn::<Dynamic>(&mut self.scope, &self.ast, fn_name, ())
{
Ok(string) => string,
Ok(ret) => ret,
Err(err) => panic!("{}", err),
}
}

View file

@ -82,7 +82,7 @@ impl Editor<'static> {
Document::default()
};
let mut cfg = Config::new();
// let mut cfg = Config::new();
Self {
should_quit: false,
@ -222,8 +222,11 @@ impl Editor<'static> {
// NOTE: I am more of the opinion that adit should use hard tab.
Key::Char('\t') => {
for c in " ".chars() {
self.document.insert(&self.cursor_position, c);
let spaces = self.config.engine.call_fn::<i64>(&mut self.config.scope, &self.config.ast, "spaces_per_tab", () ).unwrap_or(2);
for c in 0..spaces {
self.document.insert(&self.cursor_position, ' ');
self.move_cursor(Key::Right);
}
}
@ -361,7 +364,7 @@ impl Editor<'static> {
self.cursor_position = Position { x, y }
}
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 len = welcome_message.len();
#[allow(clippy::arithmetic_side_effects, clippy::integer_division)]
@ -429,7 +432,7 @@ impl Editor<'static> {
.unwrap_or("buffer".to_owned()),
);
status = self.config.call("status_bar");
status = self.config.call("status_bar").to_string();
#[allow(clippy::arithmetic_side_effects)]
let len = status.len();