-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remote control zjstatus with pipes (#48)
* chore: update to latest version of zellij * fix: deprecated functions in chrono * chore: update nix deps * chore: remove deprecated chrono functions * feat: add refresh via pipes with line protocol * fix: handle multiple lines in pipe * fix(clippy): char instead of str * feat: add notification widget * chore: update nix flake * chore: update cargo deps * chore: update cargo deps * chore: update nix flake * chore: clean up imports for tracing * chore: update nix flake * chore: update cargo deps * chore: update nix flake * chore: update cargo deps * chore: remove pinning of chrono Since chrono-tz now fixed the deprecations from chrono we can finally remove the pinning. * chore: update nix flake * chore: update cargo deps
- Loading branch information
Showing
12 changed files
with
461 additions
and
229 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub mod border; | ||
pub mod config; | ||
pub mod frames; | ||
pub mod pipe; | ||
pub mod render; | ||
pub mod widgets; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
use std::ops::Sub; | ||
|
||
use chrono::{Duration, Local}; | ||
|
||
use crate::{ | ||
config::ZellijState, | ||
widgets::{command::TIMESTAMP_FORMAT, notification}, | ||
}; | ||
|
||
/// Parses the line protocol and updates the state accordingly | ||
/// | ||
/// The protocol is as follows: | ||
/// | ||
/// zjstatus::command_name::args | ||
/// | ||
/// It first starts with `zjstatus` as a prefix to indicate that the line is | ||
/// used for the line protocol and zjstatus should parse it. It is followed | ||
/// by the command name and then the arguments. The following commands are | ||
/// available: | ||
/// | ||
/// - `rerun` - Reruns the command with the given name (like in the config) as | ||
/// argument. E.g. `zjstatus::rerun::command_1` | ||
/// | ||
/// The function returns a boolean indicating whether the state has been | ||
/// changed and the UI should be re-rendered. | ||
#[tracing::instrument(skip(state))] | ||
pub fn parse_protocol(state: &mut ZellijState, input: &str) -> bool { | ||
tracing::debug!("parsing protocol"); | ||
let lines = input.split('\n').collect::<Vec<&str>>(); | ||
|
||
let mut should_render = false; | ||
for line in lines { | ||
let line_renders = process_line(state, line); | ||
|
||
if line_renders { | ||
should_render = true; | ||
} | ||
} | ||
|
||
should_render | ||
} | ||
|
||
#[tracing::instrument(skip_all)] | ||
fn process_line(state: &mut ZellijState, line: &str) -> bool { | ||
let parts = line.split("::").collect::<Vec<&str>>(); | ||
|
||
if parts.len() < 3 { | ||
return false; | ||
} | ||
|
||
if parts[0] != "zjstatus" { | ||
return false; | ||
} | ||
|
||
tracing::debug!("command: {}", parts[1]); | ||
|
||
let mut should_render = false; | ||
#[allow(clippy::single_match)] | ||
match parts[1] { | ||
"rerun" => { | ||
rerun_command(state, parts[2]); | ||
|
||
should_render = true; | ||
} | ||
"notify" => { | ||
notify(state, parts[2]); | ||
|
||
should_render = true; | ||
} | ||
_ => {} | ||
} | ||
|
||
should_render | ||
} | ||
|
||
fn notify(state: &mut ZellijState, message: &str) { | ||
state.incoming_notification = Some(notification::Message { | ||
body: message.to_string(), | ||
received_at: Local::now(), | ||
}); | ||
} | ||
|
||
fn rerun_command(state: &mut ZellijState, command_name: &str) { | ||
let command_result = state.command_results.get(command_name); | ||
|
||
if command_result.is_none() { | ||
return; | ||
} | ||
|
||
let mut command_result = command_result.unwrap().clone(); | ||
|
||
let ts = Sub::<Duration>::sub(Local::now(), Duration::try_days(1).unwrap()); | ||
|
||
command_result.context.insert( | ||
"timestamp".to_string(), | ||
ts.format(TIMESTAMP_FORMAT).to_string(), | ||
); | ||
|
||
state.command_results.remove(command_name); | ||
state | ||
.command_results | ||
.insert(command_name.to_string(), command_result.clone()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.