#![cfg_attr(feature = "fail-on-warnings", deny(warnings))]
#![warn(clippy::all, clippy::pedantic)]
#![allow(clippy::module_name_repetitions)]
use bmux_recording_protocol::{RecordingEventKind, RecordingPayload as ProtocolRecordingPayload};
use serde::{Deserialize, Serialize};
use std::sync::Arc;
use uuid::Uuid;
type RecordingPayload = ProtocolRecordingPayload<bmux_ipc::Event, bmux_ipc::ErrorCode>;
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq)]
pub struct RecordMeta {
#[serde(default)]
pub session_id: Option<Uuid>,
#[serde(default)]
pub pane_id: Option<Uuid>,
#[serde(default)]
pub client_id: Option<Uuid>,
}
pub trait RecordingSink: Send + Sync {
fn record(&self, kind: RecordingEventKind, payload: RecordingPayload, meta: RecordMeta);
}
#[derive(Clone)]
pub struct RecordingSinkHandle(pub Arc<dyn RecordingSink>);
impl RecordingSinkHandle {
#[must_use]
pub fn new<S: RecordingSink + 'static>(sink: S) -> Self {
Self(Arc::new(sink))
}
#[must_use]
pub fn from_arc(sink: Arc<dyn RecordingSink>) -> Self {
Self(sink)
}
#[must_use]
pub fn noop() -> Self {
Self::new(NoopRecordingSink)
}
}
#[derive(Debug, Default)]
pub struct NoopRecordingSink;
impl RecordingSink for NoopRecordingSink {
fn record(&self, _kind: RecordingEventKind, _payload: RecordingPayload, _meta: RecordMeta) {}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RollingRecordingSettings {
pub window_secs: u64,
pub event_kinds: Vec<RecordingEventKind>,
}
impl RollingRecordingSettings {
#[must_use]
pub const fn is_available(&self) -> bool {
self.window_secs > 0 && !self.event_kinds.is_empty()
}
#[must_use]
pub fn capture_input(&self) -> bool {
self.event_kinds.contains(&RecordingEventKind::PaneInputRaw)
}
}