A simple CPU rendered GUI IDE experience.
Diffstat (limited to 'src/commands.rs')
-rw-r--r--src/commands.rs175
1 files changed, 72 insertions, 103 deletions
diff --git a/src/commands.rs b/src/commands.rs
index 78dea1a..9e01796 100644
--- a/src/commands.rs
+++ b/src/commands.rs
@@ -13,9 +13,10 @@ use rust_analyzer::lsp::ext::*;
use crate::FG;
use crate::edi::{Editor, lsp_m};
-use crate::lsp::PathURI;
-use crate::menu::{back, charc, filter, next, score};
-use crate::text::{RopeExt, SortTedits, TextArea, col, color_};
+use crate::lsp::{Anonymize, PathURI};
+use crate::menu::charc;
+use crate::menu::generic::{GenericMenu, MenuData};
+use crate::text::{RopeExt, SortTedits, col, color_};
macro_rules! commands {
($(#[doc = $d: literal] $t:tt $identifier: ident: $c:literal),+ $(,)?) => {
@@ -68,116 +69,74 @@ commands!(
@ RARunTest: "run-test",
);
-#[derive(Debug, Default)]
-pub struct Commands {
- pub tedit: TextArea,
- pub selection: usize,
- pub vo: usize,
-}
-
-const N: usize = 30;
-impl Commands {
- fn f(&self) -> String {
- self.tedit.rope.to_string()
- }
- pub fn next(mut self) -> Self {
- let n = filter_c(&self.f()).count();
- // coz its bottom up
- back::<N>(n, &mut self.selection, &mut self.vo);
- self
+pub enum Cmds {}
+impl MenuData for Cmds {
+ const HEIGHT: usize = 30;
+ type Data = ();
+ type Element<'a> = Cmd;
+ fn gn((): &()) -> impl Iterator<Item = Cmd> {
+ Cmd::ALL.into_iter()
}
- pub fn sel(&self) -> Cmd {
- let f = self.f();
- score_c(filter_c(&f), &f)[self.selection].1
- }
+ fn r(
+ _: &Self::Data,
+ x: Cmd,
+ _: &Path,
+ c: usize,
+ selected: bool,
+ indices: &[u32],
+ to: &mut Vec<Cell>,
+ ) {
+ let bg = if selected { col!("#262d3b") } else { col!("#1c212b") };
- pub fn back(mut self) -> Self {
- let n = filter_c(&self.f()).count();
- next::<N>(n, &mut self.selection, &mut self.vo);
- self
- }
- pub fn cells(&self, c: usize, ws: &Path) -> Vec<Cell> {
- let f = self.f();
- let mut out = vec![];
- let v = score_c(filter_c(&f), &f);
- let vlen = v.len();
- let i = v.into_iter().zip(0..vlen).skip(self.vo).take(N).rev();
-
- i.for_each(|((_, x, indices), i)| {
- r(x, ws, c, i == self.selection, &indices, &mut out)
+ let ds: Style = Style::new(FG, bg);
+ let d: Cell = Cell { letter: None, style: ds };
+ let mut b = vec![d; c];
+ let (bgt, col, ty) = (col!("#FFFFFF"), col!("#ACACAC"), "");
+ b.iter_mut().zip(ty.chars()).for_each(|(x, c)| {
+ *x = (Style::new(col, bgt) | Style::BOLD).basic(c)
});
+ let i = &mut b[..];
+ let qualifier = x.desc().chars();
+ let _left = i.len() as i32
+ - (charc(&x.name()) as i32 + qualifier.clone().count() as i32)
+ - 3;
- out
+ i.iter_mut()
+ .zip(
+ x.name()
+ .chars()
+ .chain([' '])
+ .map(|x| ds.basic(x))
+ .zip(0..)
+ .chain(
+ qualifier
+ .map(|x| {
+ Style {
+ bg,
+ fg: color_("#858685"),
+ ..default()
+ }
+ .basic(x)
+ })
+ .zip(repeat(u32::MAX)),
+ ),
+ )
+ .for_each(|(a, (b, i))| {
+ *a = b;
+ if indices.contains(&i) {
+ a.style |= (Style::BOLD, color_("#ffcc66"));
+ }
+ });
+ to.extend(b);
}
}
-fn score_c(
- x: impl Iterator<Item = Cmd>,
- filter: &'_ str,
-) -> Vec<(u32, Cmd, Vec<u32>)> {
- score(x, filter)
-}
-
-fn filter_c(f: &'_ str) -> impl Iterator<Item = Cmd> {
- filter(Cmd::ALL.into_iter(), f)
-}
-impl crate::menu::Key<'static> for Cmd {
- fn key(&self) -> impl Into<std::borrow::Cow<'static, str>> {
+pub type Commands = GenericMenu<Cmds>;
+impl<'a> crate::menu::Key<'a> for Cmd {
+ fn key(&self) -> impl Into<std::borrow::Cow<'a, str>> {
self.name()
}
}
-#[implicit_fn::implicit_fn]
-fn r(
- x: Cmd,
- _workspace: &Path,
- c: usize,
- selected: bool,
- indices: &[u32],
- to: &mut Vec<Cell>,
-) {
- let bg = if selected { col!("#262d3b") } else { col!("#1c212b") };
-
- let ds: Style = Style::new(FG, bg);
- let d: Cell = Cell { letter: None, style: ds };
- let mut b = vec![d; c];
- let (bgt, col, ty) = (col!("#FFFFFF"), col!("#ACACAC"), "");
- b.iter_mut().zip(ty.chars()).for_each(|(x, c)| {
- *x = (Style::new(col, bgt) | Style::BOLD).basic(c)
- });
- let i = &mut b[..];
- let qualifier = x.desc().chars();
- let _left = i.len() as i32
- - (charc(&x.name()) as i32 + qualifier.clone().count() as i32)
- - 3;
-
- i.iter_mut()
- .zip(
- x.name()
- .chars()
- .chain([' '])
- .map(|x| ds.basic(x))
- .zip(0..)
- .chain(
- qualifier
- .map(|x| {
- Style {
- bg,
- fg: color_("#858685"),
- ..default()
- }
- .basic(x)
- })
- .zip(repeat(u32::MAX)),
- ),
- )
- .for_each(|(a, (b, i))| {
- *a = b;
- if indices.contains(&i) {
- a.style |= (Style::BOLD, color_("#ffcc66"));
- }
- });
- to.extend(b);
-}
impl Editor {
pub fn handle_command(
@@ -304,6 +263,16 @@ impl Editor {
};
self.open_loc(x, w);
}
+ Cmd::RARunnables => {
+ let x = l
+ .runtime
+ .block_on(l.runnables(
+ o,
+ self.text.to_l_position(*self.text.cursor.first()),
+ )?)
+ .anonymize()?;
+ // self.state = State::Runnables;
+ }
_ => unimplemented!(),
}