From 35dd10890d7c6d1023d6c8647c0984b69b811410 Mon Sep 17 00:00:00 2001 From: Jonas Maier <> Date: Mon, 9 Mar 2026 13:37:20 +0100 Subject: basic setup for unix socket comms --- src/main.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index f038336..5d2643f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +#![feature(unix_socket_ancillary_data)] + use std::collections::HashMap; use std::ffi::OsStr; use std::fs; @@ -5,7 +7,7 @@ use std::io::{self, IsTerminal, Read, Write}; use std::os::unix::ffi::OsStrExt; use std::os::unix::io::AsRawFd; use std::path::Path; -use std::process::{Command, Stdio}; +use std::process::{Command, Stdio, exit}; use std::sync::{Arc, Mutex}; use std::thread::sleep; use std::time::Duration; @@ -13,6 +15,7 @@ use std::time::Duration; pub mod basedir; pub mod completion; pub mod cursor; +pub mod date; pub mod history; pub mod linebuf; pub mod panic; @@ -20,7 +23,7 @@ pub mod parse; pub mod raw; pub mod reload; pub mod run; -pub mod date; +pub mod unix; use linebuf::LineBuf; use raw::*; @@ -67,6 +70,7 @@ pub struct Session { builtins: HashMap, vars: HashMap, funs: HashMap>, + socket_running: Option, /// n before end of history.len() /// 0 == not checking history @@ -133,7 +137,9 @@ impl Session { let new = if self.history_visit == 0 { Vec::new() } else { - self.history[self.history.len() - self.history_visit].cmd.clone() + self.history[self.history.len() - self.history_visit] + .cmd + .clone() }; io::stdout().write_all(&new).unwrap(); io::stdout().flush().unwrap(); @@ -165,7 +171,9 @@ impl Session { } // skip it - while let Some(x) = self.line.get_left() && !x.is_ascii_whitespace() { + while let Some(x) = self.line.get_left() + && !x.is_ascii_whitespace() + { self.line.left(); i += 1; } @@ -256,6 +264,7 @@ fn event_loop() { builtins: run::builtin_map(), prev_path: vec![b'.'], history_visit: 0, + socket_running: None, vars: HashMap::new(), funs: HashMap::new(), }; @@ -263,6 +272,7 @@ fn event_loop() { print!("{}", se.prompt()); let session = Arc::new(Mutex::new(se)); + let _sock_dropper = unix::listen(session.clone()); loop { let mut buf = [0u8; 1]; @@ -479,6 +489,7 @@ fn event_loop() { } fn main() { + unix::maybe_run_defined_function(); if !io::stdin().is_terminal() { println!("need to run in a tty"); return; -- cgit v1.2.3