mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-07 04:06:48 +01:00
Compare commits
No commits in common. "bad20f5037dc22d572a8381840fab871ce65f565" and "faecc2c304ad2c0ebd78d21170a02c172fd356bf" have entirely different histories.
bad20f5037
...
faecc2c304
4 changed files with 88 additions and 55 deletions
|
|
@ -189,20 +189,6 @@ pub const fn to_digit (c: char) -> DslResult<usize> {
|
||||||
Exp(usize, TokenIter<'source>),
|
Exp(usize, TokenIter<'source>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'source> std::fmt::Display for Value<'source> {
|
|
||||||
fn fmt (&self, out: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
|
|
||||||
write!(out, "{}", match self {
|
|
||||||
Nil => String::new(),
|
|
||||||
Err(e) => format!("[error: {e}]"),
|
|
||||||
Num(n) => format!("{n}"),
|
|
||||||
Sym(s) => format!("{s}"),
|
|
||||||
Key(s) => format!("{s}"),
|
|
||||||
Str(s) => format!("{s}"),
|
|
||||||
Exp(_, e) => format!("{e:?}"),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'source> Token<'source> {
|
impl<'source> Token<'source> {
|
||||||
pub const fn new (
|
pub const fn new (
|
||||||
source: &'source str, start: usize, length: usize, value: Value<'source>
|
source: &'source str, start: usize, length: usize, value: Value<'source>
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,9 @@ impl<T: Content<TuiOut>> Content<TuiOut> for std::sync::Arc<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
mod tui_border; pub use self::tui_border::*;
|
mod tui_border; pub use self::tui_border::*;
|
||||||
mod tui_button; pub use self::tui_button::*;
|
|
||||||
mod tui_color; pub use self::tui_color::*;
|
mod tui_color; pub use self::tui_color::*;
|
||||||
mod tui_field; pub use self::tui_field::*;
|
mod tui_field; pub use self::tui_field::*;
|
||||||
|
mod tui_file; pub use self::tui_file::*;
|
||||||
mod tui_phat; pub use self::tui_phat::*;
|
mod tui_phat; pub use self::tui_phat::*;
|
||||||
mod tui_repeat; pub use self::tui_repeat::*;
|
mod tui_repeat; pub use self::tui_repeat::*;
|
||||||
mod tui_scroll; pub use self::tui_scroll::*;
|
mod tui_scroll; pub use self::tui_scroll::*;
|
||||||
|
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
||||||
use crate::{*, Color::*};
|
|
||||||
|
|
||||||
pub fn button_2 <'a> (
|
|
||||||
key: impl Content<TuiOut> + 'a, label: impl Content<TuiOut> + 'a, editing: bool,
|
|
||||||
) -> impl Content<TuiOut> + 'a {
|
|
||||||
let key = Tui::fg_bg(Tui::g(0), Tui::orange(), Bsp::e(
|
|
||||||
Tui::fg_bg(Tui::orange(), Reset, "▐"),
|
|
||||||
Bsp::e(key, Tui::fg(Tui::g(96), "▐"))
|
|
||||||
));
|
|
||||||
let label = When::new(!editing, Tui::fg_bg(Tui::g(255), Tui::g(96), label));
|
|
||||||
Tui::bold(true, Bsp::e(key, label))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn button_3 <'a, K, L, V> (
|
|
||||||
key: K,
|
|
||||||
label: L,
|
|
||||||
value: V,
|
|
||||||
editing: bool,
|
|
||||||
) -> impl Content<TuiOut> + 'a where
|
|
||||||
K: Content<TuiOut> + 'a,
|
|
||||||
L: Content<TuiOut> + 'a,
|
|
||||||
V: Content<TuiOut> + 'a,
|
|
||||||
{
|
|
||||||
let key = Tui::fg_bg(Tui::g(0), Tui::orange(),
|
|
||||||
Bsp::e(Tui::fg_bg(Tui::orange(), Reset, "▐"), Bsp::e(key, Tui::fg(if editing {
|
|
||||||
Tui::g(128)
|
|
||||||
} else {
|
|
||||||
Tui::g(96)
|
|
||||||
}, "▐"))));
|
|
||||||
let label = Bsp::e(
|
|
||||||
When::new(!editing, Bsp::e(
|
|
||||||
Tui::fg_bg(Tui::g(255), Tui::g(96), label),
|
|
||||||
Tui::fg_bg(Tui::g(128), Tui::g(96), "▐"),
|
|
||||||
)),
|
|
||||||
Bsp::e(
|
|
||||||
Tui::fg_bg(Tui::g(224), Tui::g(128), value),
|
|
||||||
Tui::fg_bg(Tui::g(128), Reset, "▌"),
|
|
||||||
));
|
|
||||||
Tui::bold(true, Bsp::e(key, label))
|
|
||||||
}
|
|
||||||
87
tui/src/tui_content/tui_file.rs
Normal file
87
tui/src/tui_content/tui_file.rs
Normal file
|
|
@ -0,0 +1,87 @@
|
||||||
|
use crate::*;
|
||||||
|
/// Browses for phrase to import/export
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct FileBrowser {
|
||||||
|
pub cwd: PathBuf,
|
||||||
|
pub dirs: Vec<(OsString, String)>,
|
||||||
|
pub files: Vec<(OsString, String)>,
|
||||||
|
pub filter: String,
|
||||||
|
pub index: usize,
|
||||||
|
pub scroll: usize,
|
||||||
|
pub size: Measure<TuiOut>
|
||||||
|
}
|
||||||
|
/// Commands supported by [FileBrowser]
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub enum FileBrowserCommand {
|
||||||
|
Begin,
|
||||||
|
Cancel,
|
||||||
|
Confirm,
|
||||||
|
Select(usize),
|
||||||
|
Chdir(PathBuf),
|
||||||
|
Filter(Arc<str>),
|
||||||
|
}
|
||||||
|
content!(TuiOut: |self: FileBrowser| /*Stack::down(|add|{
|
||||||
|
let mut i = 0;
|
||||||
|
for (_, name) in self.dirs.iter() {
|
||||||
|
if i >= self.scroll {
|
||||||
|
add(&Tui::bold(i == self.index, name.as_str()))?;
|
||||||
|
}
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
for (_, name) in self.files.iter() {
|
||||||
|
if i >= self.scroll {
|
||||||
|
add(&Tui::bold(i == self.index, name.as_str()))?;
|
||||||
|
}
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
add(&format!("{}/{i}", self.index))?;
|
||||||
|
Ok(())
|
||||||
|
})*/"todo");
|
||||||
|
impl FileBrowser {
|
||||||
|
pub fn new (cwd: Option<PathBuf>) -> Usually<Self> {
|
||||||
|
let cwd = if let Some(cwd) = cwd { cwd } else { std::env::current_dir()? };
|
||||||
|
let mut dirs = vec![];
|
||||||
|
let mut files = vec![];
|
||||||
|
for entry in std::fs::read_dir(&cwd)? {
|
||||||
|
let entry = entry?;
|
||||||
|
let name = entry.file_name();
|
||||||
|
let decoded = name.clone().into_string().unwrap_or_else(|_|"<unreadable>".to_string());
|
||||||
|
let meta = entry.metadata()?;
|
||||||
|
if meta.is_dir() {
|
||||||
|
dirs.push((name, format!("📁 {decoded}")));
|
||||||
|
} else if meta.is_file() {
|
||||||
|
files.push((name, format!("📄 {decoded}")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(Self {
|
||||||
|
cwd,
|
||||||
|
dirs,
|
||||||
|
files,
|
||||||
|
filter: "".to_string(),
|
||||||
|
index: 0,
|
||||||
|
scroll: 0,
|
||||||
|
size: Measure::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
pub fn len (&self) -> usize {
|
||||||
|
self.dirs.len() + self.files.len()
|
||||||
|
}
|
||||||
|
pub fn is_dir (&self) -> bool {
|
||||||
|
self.index < self.dirs.len()
|
||||||
|
}
|
||||||
|
pub fn is_file (&self) -> bool {
|
||||||
|
self.index >= self.dirs.len()
|
||||||
|
}
|
||||||
|
pub fn path (&self) -> PathBuf {
|
||||||
|
self.cwd.join(if self.is_dir() {
|
||||||
|
&self.dirs[self.index].0
|
||||||
|
} else if self.is_file() {
|
||||||
|
&self.files[self.index - self.dirs.len()].0
|
||||||
|
} else {
|
||||||
|
unreachable!()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
pub fn chdir (&self) -> Usually<Self> {
|
||||||
|
Self::new(Some(self.path()))
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue