A simple CPU rendered GUI IDE experience.
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs6
-rw-r--r--src/trm.rs52
3 files changed, 59 insertions, 0 deletions
diff --git a/Cargo.toml b/Cargo.toml
index d152851..5e13982 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -62,6 +62,7 @@ arc-swap = "1.7.1"
atools = "0.1.10"
swizzle = "0.1.0"
walkdir = "2.5.0"
+niri = { package = "niri-ipc", version = "25.11.0" }
[profile.dev.package]
rust-analyzer.opt-level = 3
diff --git a/src/main.rs b/src/main.rs
index 7b5d1d2..c3e262e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,7 @@
// this looks pretty good though
#![feature(tuple_trait, unboxed_closures, fn_traits)]
#![feature(
+ try_blocks_heterogeneous,
current_thread_id,
vec_try_remove,
iter_next_chunk,
@@ -36,6 +37,7 @@ use std::borrow::Cow;
use std::iter::once;
mod act;
mod sym;
+mod trm;
use std::num::NonZeroU32;
use std::os::fd::AsFd;
use std::path::{Path, PathBuf};
@@ -1256,6 +1258,9 @@ hovering.request = (DropH::new(handle), cursor_position).into();
_ => {}
}
match o {
+ Some(Do::SpawnTerminal) => {
+ trm::toggle(workspace.as_deref().unwrap_or(Path::new("/home/os/")));
+ }
Some(Do::MatchingBrace) => {
if let Some((l, f)) = lsp!() {
l.matching_brace(f, &mut text);
@@ -1745,6 +1750,7 @@ Default => {
K(Key::Character(x) if x == "l" && ctrl()) => _ [Symbols],
K(Key::Character(x) if x == "." && ctrl()) => _ [CodeAction],
K(Key::Character(x) if x == "0" && ctrl()) => _ [MatchingBrace],
+ K(Key::Character(x) if x == "`" && ctrl()) => _ [SpawnTerminal],
K(Key::Named(ArrowUp | ArrowLeft | ArrowDown | ArrowRight | Home | End) if shift()) => Selection(Range<usize> => 0..0) [StartSelection],
M(MouseButton::Left if shift()) => Selection(Range<usize> => 0..0) [StartSelection],
M(MouseButton::Left if ctrl()) => _ [GoToDefinition],
diff --git a/src/trm.rs b/src/trm.rs
new file mode 100644
index 0000000..9eee9a5
--- /dev/null
+++ b/src/trm.rs
@@ -0,0 +1,52 @@
+use std::path::Path;
+use std::sync::atomic::AtomicU64;
+use std::sync::atomic::Ordering::Relaxed;
+use std::time::Duration;
+
+use niri::ColumnDisplay::Normal;
+use niri::{Action, Request, Response};
+static LAST: AtomicU64 = AtomicU64::new(!0);
+
+pub fn toggle(at: &Path) {
+ _ = try bikeshed anyhow::Result<()> {
+ let l = LAST.load(Relaxed);
+ let mut niri = niri::socket::Socket::connect()?;
+ let Ok(Ok(Response::FocusedWindow(Some(focused)))) = niri.send(Request::FocusedWindow) else { unreachable!() };
+ if l != !0 {
+ let Ok(Ok(Response::Windows(x))) = niri.send(Request::Windows) else { unreachable!() };
+ _ = niri.send(Request::Action(Action::SetColumnDisplay {
+ display: Normal
+ }))?;
+ if x.iter().any(|x| x.id == l) {
+ _ = niri.send(Request::Action(Action::FocusWindow { id: l }))?;
+
+ // std::thread::sleep(Duration::from_millis(500));
+ // let Ok(Ok(Response::FocusedWindow(Some(x)))) = niri.send(Request::FocusedWindow) else { unreachable!() };
+ // dbg!(&x);
+ // if x.layout.window_size.1 < 200 {
+ _ = niri.send(Request::Action(Action::SetWindowHeight {
+ id: Some(l),
+ change: niri::SizeChange::SetFixed(400),
+ }))?;
+ // }
+ return
+ }
+ // it died :(
+ }
+ _ = niri.send(Request::Action(Action::Spawn {
+ command: ["kitty", "--class", "gratty", at.to_str().unwrap()]
+ .map(String::from)
+ .to_vec(),
+ }))?;
+ std::thread::sleep(Duration::from_millis(500));
+ _ = niri.send(Request::Action(Action::ConsumeOrExpelWindowLeft {
+ id: None,
+ }))?;
+ _ = niri.send(Request::Action(Action::SetWindowHeight {
+ id: None,
+ change: niri::SizeChange::SetFixed(400),
+ }))?;
+ let Ok(Ok(Response::FocusedWindow(Some(ot)))) = niri.send(Request::FocusedWindow) else { unreachable!() };
+ LAST.store(ot.id, Relaxed);
+ };
+}