use ratatui::prelude::*;
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(
feature = "serialization",
derive(serde::Serialize, serde::Deserialize)
)]
pub struct TimelineEvent {
pub id: String,
pub timestamp: f64,
pub label: String,
pub color: Color,
}
impl TimelineEvent {
pub fn new(id: impl Into<String>, timestamp: f64, label: impl Into<String>) -> Self {
Self {
id: id.into(),
timestamp,
label: label.into(),
color: Color::Yellow,
}
}
pub fn with_color(mut self, color: Color) -> Self {
self.color = color;
self
}
pub fn set_color(&mut self, color: Color) {
self.color = color;
}
pub fn color(&self) -> Color {
self.color
}
}
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(
feature = "serialization",
derive(serde::Serialize, serde::Deserialize)
)]
pub struct TimelineSpan {
pub id: String,
pub start: f64,
pub end: f64,
pub label: String,
pub color: Color,
pub lane: usize,
}
impl TimelineSpan {
pub fn new(id: impl Into<String>, start: f64, end: f64, label: impl Into<String>) -> Self {
Self {
id: id.into(),
start,
end,
label: label.into(),
color: Color::Cyan,
lane: 0,
}
}
pub fn with_color(mut self, color: Color) -> Self {
self.color = color;
self
}
pub fn set_color(&mut self, color: Color) {
self.color = color;
}
pub fn color(&self) -> Color {
self.color
}
pub fn with_lane(mut self, lane: usize) -> Self {
self.lane = lane;
self
}
pub fn duration(&self) -> f64 {
self.end - self.start
}
}
#[derive(Clone, Debug, Default, PartialEq, Eq)]
#[cfg_attr(
feature = "serialization",
derive(serde::Serialize, serde::Deserialize)
)]
pub enum SelectedType {
#[default]
Event,
Span,
}
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(
feature = "serialization",
derive(serde::Serialize, serde::Deserialize)
)]
pub enum TimelineMessage {
AddEvent(TimelineEvent),
AddSpan(TimelineSpan),
SetEvents(Vec<TimelineEvent>),
SetSpans(Vec<TimelineSpan>),
Clear,
ZoomIn,
ZoomOut,
PanLeft,
PanRight,
FitAll,
SelectNext,
SelectPrev,
}
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(
feature = "serialization",
derive(serde::Serialize, serde::Deserialize)
)]
pub enum TimelineOutput {
EventSelected(String),
SpanSelected(String),
ViewChanged {
start: f64,
end: f64,
},
}