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
123 changes: 121 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ itertools = { version = "0.14" }
futures-util = { version = "0.3" }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0.145" }
thiserror = { version = "2.0.17" }
tokio = { version = "1.48", features = ["full"] }
tracing = { version = "0.1" }
tracing-appender = { version = "0.2" }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
vt100 = { version = "0" }
color-eyre = { version = "0.6" }
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ bytes.workspace = true
crossterm.workspace = true
futures-util.workspace = true
serde.workspace = true
thiserror.workspace = true
tokio.workspace = true
tracing-appender.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
47 changes: 26 additions & 21 deletions cli/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::{fmt::Debug, io::Stdout, time::Duration};

use bytes::Bytes;
use clap::FromArgMatches;
use color_eyre::eyre;
use derivative::Derivative;
use ratatui::{Terminal, prelude::CrosstermBackend, restore, widgets::ListState};
use remux_core::{
Expand Down Expand Up @@ -130,32 +132,30 @@ impl 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));
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)).unwrap();
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})");
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
.unwrap();
comm::send_event(&mut self.stream, CliEvent::TerminalResize { rows, cols }).await?;
}
tokio::select! {
Some(input) = input_rx.recv() => {
use Input::{Stdin, Resize};
match input {
Stdin(bytes) => {
trace!("stdin({bytes:?}");
self.dispatch_stdin(bytes).await;
self.dispatch_stdin(bytes).await.unwrap();
}
Resize => {
debug!("resize");
Expand Down Expand Up @@ -203,7 +203,7 @@ impl App {
}
}
_ = ticker.tick() => {
term.draw(|f| ui::draw(f, &mut self.state)).unwrap();
term.draw(|f| ui::draw(f, &mut self.state))?;
}
}
}
Expand All @@ -218,15 +218,19 @@ impl App {
}

#[instrument(skip(self, bytes))]
async fn dispatch_stdin(&mut self, bytes: Bytes) {
async fn dispatch_stdin(&mut self, bytes: Bytes) -> Result<()> {
match self.state.mode {
AppMode::Normal => self.handle_stdin_for_normal_mode(bytes).await,
AppMode::SelectingSession => self.handle_stdin_for_selecting_mode(bytes).await,
AppMode::Normal => self.handle_stdin_for_normal_mode(bytes).await?,
AppMode::SelectingSession => self.handle_stdin_for_selecting_mode(bytes).await?,
}

Ok(())
}

async fn handle_stdin_for_selecting_mode(&mut self, bytes: Bytes) {
let event = Event::parse_from(&bytes).unwrap().unwrap();
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),
SelectorType::Fuzzy => FuzzySelectorWidget::input(event, &mut self.state.ui.selector),
Expand All @@ -235,10 +239,8 @@ impl App {
match selection {
ui::traits::Selection::Index(i) => match self.state.mode {
AppMode::SelectingSession => {
let session = self.state.ui.selector.list[i].parse::<u32>().unwrap();
comm::send_event(&mut self.stream, CliEvent::SwitchSession(session))
.await
.unwrap();
let session = self.state.daemon.session_ids[i];
comm::send_event(&mut self.stream, CliEvent::SwitchSession(session)).await?;
}
AppMode::Normal => {}
},
Expand All @@ -248,20 +250,22 @@ impl App {
self.state.ui.selector.list_state.select(Some(0));
self.state.ui.selector.list.clear();
}
Ok(())
}

async fn handle_stdin_for_normal_mode(&mut self, bytes: Bytes) {
async fn handle_stdin_for_normal_mode(&mut self, bytes: Bytes) -> Result<()> {
for parsed_event in self.input_parser.process(&bytes) {
match parsed_event {
input_parser::ParsedEvent::LocalAction(action) => {
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.unwrap();
comm::send_event(&mut self.stream, cli_event).await?;
}
}
}
Ok(())
}

async fn dispatch_action(&mut self, action: input_parser::Action) {
Expand Down Expand Up @@ -290,11 +294,12 @@ impl App {
}

#[instrument(skip(self, term))]
async fn handle_resize(&mut self, term: &mut Terminal<CrosstermBackend<Stdout>>) {
async fn handle_resize(&mut self, term: &mut Terminal<CrosstermBackend<Stdout>>) -> Result<()> {
self.state.terminal.needs_resize = true;
term.draw(|f| {
ui::draw(f, &mut self.state);
})
.unwrap();
})?;

eyre::Ok(())
}
}
Loading