Compare commits
3 Commits
luau/warn
...
luau/out.w
Author | SHA1 | Date | |
---|---|---|---|
e06a4a6c72 | |||
bf92ed7bad | |||
54ae2f4b1c |
@ -1,6 +1,6 @@
|
|||||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
pub mod shell;
|
pub mod session;
|
||||||
mod commands;
|
mod commands;
|
||||||
mod ps;
|
mod ps;
|
||||||
mod rc;
|
mod rc;
|
||||||
@ -11,5 +11,5 @@ mod vm;
|
|||||||
mod alias;
|
mod alias;
|
||||||
#[path = "./luau/terminal.rs"]
|
#[path = "./luau/terminal.rs"]
|
||||||
mod terminal;
|
mod terminal;
|
||||||
#[path = "./luau/system.rs"]
|
#[path = "./luau/shell.rs"]
|
||||||
mod sytem;
|
mod shell;
|
@ -1,4 +1,4 @@
|
|||||||
use mlua::{Result as lResult, Table};
|
use mlua::{Result as lResult, Table, Value};
|
||||||
use whoami::fallible;
|
use whoami::fallible;
|
||||||
use crate::vm::LuauVm;
|
use crate::vm::LuauVm;
|
||||||
|
|
||||||
@ -11,9 +11,8 @@ impl PsPrompt for LuauVm {
|
|||||||
fn ps_prompt(&self) -> lResult<Table> {
|
fn ps_prompt(&self) -> lResult<Table> {
|
||||||
let prompt_table = self.0.create_table()?;
|
let prompt_table = self.0.create_table()?;
|
||||||
let prompt_metatable = self.0.create_table()?;
|
let prompt_metatable = self.0.create_table()?;
|
||||||
prompt_metatable.set("__index", self.0.create_function(|_, (lua_self, index): (String, String)| -> lResult<()> {
|
prompt_metatable.set("__index", self.0.create_function(|_, (table, index): (Table, Value)| -> lResult<String> {
|
||||||
println!("lua_self={} index={}", lua_self, index);
|
table.raw_get::<String>(index)
|
||||||
Ok(())
|
|
||||||
})?)?;
|
})?)?;
|
||||||
prompt_metatable.set("__newindex", self.0.create_function(|_, _: String| -> lResult<String> {
|
prompt_metatable.set("__newindex", self.0.create_function(|_, _: String| -> lResult<String> {
|
||||||
Ok("placeholder".to_owned())
|
Ok("placeholder".to_owned())
|
@ -25,13 +25,12 @@ macro_rules! background_styles_luau {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait TerminalColors {
|
trait Colors {
|
||||||
fn background(&self, style_table: &Table) -> lResult<()>;
|
fn background(&self, style_table: &Table) -> lResult<()>;
|
||||||
fn foreground(&self, style_table: &Table) -> lResult<()>;
|
fn foreground(&self, style_table: &Table) -> lResult<()>;
|
||||||
fn styling(&self) -> lResult<Table>;
|
fn styling(&self, term_out_table: &Table) -> lResult<()>;
|
||||||
fn terminal(&self, luau_globals: &Table) -> lResult<()>;
|
|
||||||
}
|
}
|
||||||
impl TerminalColors for LuauVm {
|
impl Colors for LuauVm {
|
||||||
fn background(&self, style_table: &Table) -> lResult<()> {
|
fn background(&self, style_table: &Table) -> lResult<()> {
|
||||||
let foreground_table = self.0.create_table()?;
|
let foreground_table = self.0.create_table()?;
|
||||||
foreground_styles_luau!(self, foreground_table,
|
foreground_styles_luau!(self, foreground_table,
|
||||||
@ -46,8 +45,7 @@ impl TerminalColors for LuauVm {
|
|||||||
underline_blue underline_magenta underline_cyan underline_white
|
underline_blue underline_magenta underline_cyan underline_white
|
||||||
bold
|
bold
|
||||||
);
|
);
|
||||||
style_table.set("FOREGROUND", foreground_table)?;
|
style_table.set("FOREGROUND", foreground_table)
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn foreground(&self, style_table: &Table) -> lResult<()> {
|
fn foreground(&self, style_table: &Table) -> lResult<()> {
|
||||||
@ -60,21 +58,37 @@ impl TerminalColors for LuauVm {
|
|||||||
on_blue on_magenta
|
on_blue on_magenta
|
||||||
on_cyan on_white
|
on_cyan on_white
|
||||||
);
|
);
|
||||||
style_table.set("BACKGROUND", background_table)?;
|
style_table.set("BACKGROUND", background_table)
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn styling(&self) -> lResult<Table> {
|
fn styling(&self, term_out_table: &Table) -> lResult<()> {
|
||||||
let style_table = self.0.create_table()?;
|
let style_table = self.0.create_table()?;
|
||||||
self.foreground(&style_table)?;
|
self.foreground(&style_table)?;
|
||||||
self.background(&style_table)?;
|
self.background(&style_table)?;
|
||||||
Ok(style_table)
|
term_out_table.set("STYLE", style_table)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
fn terminal(&self, luau_globals: &Table) -> lResult<()> {
|
|
||||||
let term_table = self.0.create_table()?;
|
trait Write {
|
||||||
term_table.set("OUT", self.styling()?)?;
|
fn write(&self, term_out_table: &Table) -> lResult<()>;
|
||||||
luau_globals.set("TERMINAL", &term_table)?;
|
}
|
||||||
Ok(())
|
impl Write for LuauVm {
|
||||||
|
fn write(&self, term_out_table: &Table) -> lResult<()> {
|
||||||
|
term_out_table.set("WRITE", self.0.create_function(|_, s: String| -> lResult<()> {
|
||||||
|
print!("{s}");
|
||||||
|
Ok(())
|
||||||
|
})?)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait Terminal {
|
||||||
|
fn global_terminal(&self, luau_globals: &Table) -> lResult<()>;
|
||||||
|
}
|
||||||
|
impl Terminal for LuauVm {
|
||||||
|
fn global_terminal(&self, luau_globals: &Table) -> lResult<()> {
|
||||||
|
let term_table = self.0.create_table()?;
|
||||||
|
let term_out_table = self.0.create_table()?;
|
||||||
|
term_table.set("OUT", term_out_table)?;
|
||||||
|
luau_globals.set("TERMINAL", &term_table)
|
||||||
}
|
}
|
||||||
}
|
}
|
17
src/ps.rs
17
src/ps.rs
@ -1,9 +1,14 @@
|
|||||||
use const_format::formatcp;
|
use const_format::formatcp;
|
||||||
use color_print::{cformat, cprint};
|
|
||||||
|
|
||||||
pub const DEFAULT_PS: &str = formatcp!("lambdashell-{}", env!("CARGO_PKG_VERSION"));
|
pub const DEFAULT_PS: &str = formatcp!("lambdashell-{}", env!("CARGO_PKG_VERSION"));
|
||||||
|
|
||||||
pub fn working_dir_name() -> String {
|
struct Ps(String);
|
||||||
|
impl Ps {
|
||||||
|
fn set(prompt: String) -> Self {
|
||||||
|
Self(prompt)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn working_dir_name(&self) -> String {
|
||||||
std::env::current_dir().map_or("?".to_owned(), |path| {
|
std::env::current_dir().map_or("?".to_owned(), |path| {
|
||||||
path.file_name().map_or("?".to_owned(), |name| {
|
path.file_name().map_or("?".to_owned(), |name| {
|
||||||
let name_os_string = name.to_os_string();
|
let name_os_string = name.to_os_string();
|
||||||
@ -13,9 +18,9 @@ pub fn working_dir_name() -> String {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn display(ps1: &String) {
|
fn display(&self) {
|
||||||
let working_dir_name = cformat!(" <bold>{}</> ", working_dir_name());
|
print!("{}", self.0);
|
||||||
cprint!("{}{}λ ", ps1, working_dir_name);
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user