Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ edition = "2024"

[workspace.dependencies]
bytes = { version = "1.11.0", features = ["serde"] }
color-eyre = { version = "0.6" }
crossterm = { version = "0.29.0" }
derive_more = { version = "2", features = ["display"] }
itertools = { version = "0.14" }
futures-util = { version = "0.3" }
itertools = { version = "0.14" }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0.145" }
tokio = { version = "1.48", features = ["full"] }
tracing = { version = "0.1" }
tracing-appender = { version = "0.2" }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tracing-error = { version = "0.2" }
tracing-subscriber = { version = "0.3", features = ["env-filter", "fmt"] }
vt100 = { version = "0" }
color-eyre = { version = "0.6" }
3 changes: 2 additions & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ handle-macro = {path = "../handle-macro"}
remux-core = { path = "../core" }

bytes.workspace = true
color-eyre.workspace = true
crossterm.workspace = true
futures-util.workspace = true
serde.workspace = true
tokio.workspace = true
tracing-appender.workspace = true
tracing-error.workspace = true
tracing-subscriber.workspace = true
tracing.workspace = true
vt100.workspace = true
color-eyre.workspace = true

clap = { version = "4.5.51", features = ["derive"] }
mlua = { version = "0.11.4", features = ["lua54", "serde", "async", "vendored", "send"] }
Expand Down
45 changes: 22 additions & 23 deletions cli/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,79 +125,81 @@ impl App {
}
}

#[instrument(skip(self))]
#[instrument(parent=None, skip(self), name="App")]
pub async fn run(&mut self) -> Result<()> {
let mut term = ratatui::init();
debug!("starting app");
debug!("Starting app");
let (input_tx, mut input_rx) = mpsc::channel::<Input>(100);
let (lua_tx, mut lua_rx) = broadcast::channel(100);
self.bg_tasks.extend(input::start_input_listeners(input_tx));
self.bg_tasks.push(lua::start_status_line_task(lua_tx)?);
let mut ticker = interval(Duration::from_millis(50));
debug!("Enabled raw mode");
// execute!(stdout(), EnterAlternateScreen)?;
debug!("Entered alternate screen");

// need an initial render since ui updates app state to convey terminal size information
term.draw(|f| ui::draw(f, &mut self.state))?;
loop {
if self.state.terminal.needs_resize {
let (rows, cols) = self.state.terminal.size;
debug!("setting terminal emulator size (rows={rows}, cols={cols})");
info!(rows = rows, cols = cols, "Setting terminal emulator size");
self.state.terminal.emulator.set_size(rows, cols);
self.state.terminal.needs_resize = false;
let (rows, cols) = self.state.terminal.size;
comm::send_event(&mut self.stream, CliEvent::TerminalResize { rows, cols }).await?;
}
tokio::select! {
Some(input) = input_rx.recv() => {
let span = error_span!("Recieved Input");
let _guard = span.enter();
use Input::{Stdin, Resize};
match input {
match &input {
Stdin(bytes) => {
trace!("stdin({bytes:?}");
self.dispatch_stdin(bytes).await.unwrap();
trace!(input=?input);
self.dispatch_stdin(bytes.clone()).await.unwrap();
}
Resize => {
debug!("resize");
self.handle_resize(&mut term).await;
info!(input=?input);
self.handle_resize(&mut term).await.unwrap();
}
}
}
Ok(mut status_line_state) = lua_rx.recv() => {
debug!("received status line state");
trace!(status_line_state=?status_line_state, "received status line state");
status_line_state.apply_built_ins(&self.state);
self.state.ui.status_line = status_line_state;
}
res = comm::recv_daemon_event(&mut self.stream) => {
match res {
Ok(event) => {
let span = error_span!("Recieved Daemon Event");
let _guard = span.enter();
match &event {
DaemonEvent::Raw(..) => {
trace!(event=?event);
}
_ => {
info!(event=?event);
}
}
match event {
DaemonEvent::Raw(bytes) => {
trace!("DaemonEvent(Raw({bytes:?}))");
self.state.terminal.emulator.process(&bytes);
}
DaemonEvent::Disconnected => {
debug!("DaemonEvent(Disconnected)");
break;
}
DaemonEvent::ActiveSession(session_id) => {
debug!("DaemonEvent(ActiveSession({session_id}))");
self.state.daemon.set_active_session(session_id);
}
DaemonEvent::NewSession(session_id) => {
debug!("DaemonEvent(NewSession({session_id}))");
self.state.daemon.add_session(session_id);
}
_ => {
todo!();
}
// DaemonEvent::DeletedSession(_session_id) => {
// todo!("implement delete session");
// }
}
}
Err(e) => {
error!("Error receiving daemon event: {e}");
error!(error=%e, "Error receiving daemon event");
break;
}
}
Expand All @@ -217,7 +219,6 @@ impl App {
Ok(())
}

#[instrument(skip(self, bytes))]
async fn dispatch_stdin(&mut self, bytes: Bytes) -> Result<()> {
match self.state.mode {
AppMode::Normal => self.handle_stdin_for_normal_mode(bytes).await?,
Expand All @@ -229,7 +230,6 @@ impl App {

async fn handle_stdin_for_selecting_mode(&mut self, bytes: Bytes) -> Result<()> {
let event = Event::parse_from(&bytes)?.unwrap();
panic!("hi");

let selection_opt = match self.state.ui.selector.selector_type {
SelectorType::Basic => BasicSelectorWidget::input(event, &mut self.state.ui.selector),
Expand Down Expand Up @@ -260,7 +260,6 @@ impl App {
self.dispatch_action(action).await;
}
input_parser::ParsedEvent::DaemonAction(cli_event) => {
debug!("sending cli event: {cli_event:?}");
comm::send_event(&mut self.stream, cli_event).await?;
}
}
Expand Down
39 changes: 28 additions & 11 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,45 @@ async fn main() {

fn setup_logging() -> Result<tracing_appender::non_blocking::WorkerGuard> {
use tracing_appender::non_blocking;
use tracing_subscriber::{EnvFilter, fmt};

use tracing_error::ErrorLayer;
use tracing_subscriber::{EnvFilter, FmtSubscriber, fmt::format::FmtSpan, layer::SubscriberExt};
// Create the log file
let file = File::create("./logs/remux-cli.log")?;
let (non_blocking, guard) = non_blocking(file);
let env_filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("debug"));
let subscriber = fmt().with_writer(non_blocking).with_env_filter(env_filter).finish();
let (non_blocking_writer, guard) = non_blocking(file);

// Environment filter
let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("debug"));

// Build the subscriber
let subscriber = FmtSubscriber::builder()
.with_env_filter(filter)
.with_span_events(FmtSpan::NONE)
.with_line_number(false)
.with_file(false)
.with_target(false)
.with_level(true)
.with_thread_ids(false)
.with_writer(non_blocking_writer)
.finish()
.with(ErrorLayer::default());

tracing::subscriber::set_global_default(subscriber)?;

Ok(guard)
}

#[instrument]
async fn connect() -> Result<UnixStream> {
let socket_path = get_sock_path()?;
debug!("Connecting to {:?}", socket_path);
debug!(path=?socket_path, "Connecting to unix socket");
let stream = UnixStream::connect(socket_path.clone()).await?;
Ok(stream)
}

#[instrument]
async fn run(command: Commands) -> Result<()> {
let stream = connect().await?;
debug!("Running command: {:?}", command);
debug!("Running command");
match command {
Commands::Attach { session_id } => {
attach(
Expand All @@ -89,12 +106,12 @@ async fn run(command: Commands) -> Result<()> {
}
}

#[instrument(skip(stream, attach_request))]
#[instrument(skip(stream))]
async fn attach(mut stream: UnixStream, attach_request: CliRequestMessage<Attach>) -> Result<()> {
debug!("Sending attach request: {:?}", attach_request);
debug!("Sending attach request");
let res = comm::send_and_recv_message(&mut stream, &attach_request).await?;
debug!("Recieved attach response: {:?}", res);
debug!("Recieved initial daemon state: {:?}", res.initial_daemon_state);
debug!(response=?res, "Recieved attach response");
debug!(daemon_state=?res.initial_daemon_state, "Recieved initial daemon state");

debug!("Starting app");
let mut app = App::new(stream, res.initial_daemon_state);
Expand Down
2 changes: 1 addition & 1 deletion cli/src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(unused)]

use tokio::task::JoinHandle;
pub use tracing::{debug, error, info, instrument, trace, warn};
pub use tracing::{debug, error, error_span, info, instrument, trace, warn};

pub type CliTask = JoinHandle<Result<()>>;

Expand Down
4 changes: 0 additions & 4 deletions cli/src/ui/status_line_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use ratatui::{
layout::{Constraint, Direction, Layout},
widgets::{Paragraph, Widget},
};
use tracing::info;

use crate::states::status_line_state::StatusLineState;

Expand All @@ -22,9 +21,6 @@ impl Widget for StatusLineWidget {
return;
}

info!("rendering status line widget");

// 1. Create 3 horizontal constraints for Left, Center, Right sections
let chunks = Layout::default()
.direction(Direction::Horizontal)
.constraints([
Expand Down
3 changes: 0 additions & 3 deletions core/src/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,12 @@ pub async fn send_message(stream: &mut UnixStream, message: &impl Message) -> Re
}

pub async fn read_message<M: Message>(stream: &mut UnixStream) -> Result<M> {
println!("reading message");
let mut num_bytes = [0u8; 4];
stream.read_exact(&mut num_bytes).await?;
let num_bytes = u32::from_be_bytes(num_bytes);
let mut message_bytes = vec![0u8; num_bytes as usize];
stream.read_exact(&mut message_bytes).await?;
println!("reading message2");
let res = serde_json::from_slice(&message_bytes)?;
println!("here");
Ok(res)
}

Expand Down
4 changes: 3 additions & 1 deletion daemon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ handle-macro = {path = "../handle-macro"}
remux-core = { path = "../core" }

bytes.workspace = true
color-eyre.workspace = true
crossterm.workspace = true
derive_more.workspace = true
itertools.workspace = true
serde.workspace = true
tokio.workspace = true
tracing-error.workspace = true
tracing-subscriber.workspace = true
tracing.workspace = true
vt100.workspace = true
color-eyre.workspace = true

nix = { version = "0.30.1", features = ["term", "process", "signal"] }
pty = "0.2.2"
Expand Down
Loading