mirror of
https://github.com/wez/wezterm.git
synced 2024-11-29 21:44:24 +03:00
make it possible to re-use the line serialization in other pdus
This commit is contained in:
parent
0b3af1b7fe
commit
b384ee4233
@ -446,25 +446,30 @@ struct LineHyperlink {
|
||||
coords: Vec<CellCoordinates>,
|
||||
}
|
||||
|
||||
/// What's all this?
|
||||
/// Cells hold references to Arc<Hyperlink> and it is important to us to
|
||||
/// maintain identity of the hyperlinks in the individual cells, while also
|
||||
/// only sending a single copy of the associated URL.
|
||||
/// This section of code extracts the hyperlinks from the cells and builds
|
||||
/// up a mapping that can be used to restore the identity when the `lines()`
|
||||
/// method is called.
|
||||
#[derive(Deserialize, Serialize, PartialEq, Debug)]
|
||||
pub struct GetLinesResponse {
|
||||
pub tab_id: TabId,
|
||||
pub struct SerializedLines {
|
||||
lines: Vec<(StableRowIndex, Line)>,
|
||||
hyperlinks: Vec<LineHyperlink>,
|
||||
// TODO: image references
|
||||
}
|
||||
|
||||
impl GetLinesResponse {
|
||||
pub fn new(tab_id: TabId, mut lines: Vec<(StableRowIndex, Line)>) -> Self {
|
||||
impl SerializedLines {
|
||||
pub fn lines(self) -> Vec<(StableRowIndex, Line)> {
|
||||
self.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vec<(StableRowIndex, Line)>> for SerializedLines {
|
||||
fn from(mut lines: Vec<(StableRowIndex, Line)>) -> Self {
|
||||
let mut hyperlinks = vec![];
|
||||
|
||||
// What's all this?
|
||||
// Cells hold references to Arc<Hyperlink> and it is important to us to
|
||||
// maintain identity of the hyperlinks in the individual cells, while also
|
||||
// only sending a single copy of the associated URL.
|
||||
// This section of code extracts the hyperlinks from the cells and builds
|
||||
// up a mapping that can be used to restore the identity when the `lines()`
|
||||
// method is called.
|
||||
for (line_idx, (_, line)) in lines.iter_mut().enumerate() {
|
||||
let mut current_link: Option<Arc<Hyperlink>> = None;
|
||||
let mut current_range = 0..0;
|
||||
@ -526,16 +531,14 @@ impl GetLinesResponse {
|
||||
}
|
||||
}
|
||||
|
||||
Self {
|
||||
tab_id,
|
||||
lines,
|
||||
hyperlinks,
|
||||
}
|
||||
Self { lines, hyperlinks }
|
||||
}
|
||||
}
|
||||
|
||||
/// Reconsitute hyperlinks or other attributes that were decomposed for
|
||||
/// serialization, and return the line data.
|
||||
pub fn lines(self) -> Vec<(StableRowIndex, Line)> {
|
||||
/// Reconsitute hyperlinks or other attributes that were decomposed for
|
||||
/// serialization, and return the line data.
|
||||
impl Into<Vec<(StableRowIndex, Line)>> for SerializedLines {
|
||||
fn into(self) -> Vec<(StableRowIndex, Line)> {
|
||||
if self.hyperlinks.is_empty() {
|
||||
self.lines
|
||||
} else {
|
||||
@ -562,6 +565,12 @@ impl GetLinesResponse {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, PartialEq, Debug)]
|
||||
pub struct GetLinesResponse {
|
||||
pub tab_id: TabId,
|
||||
pub lines: SerializedLines,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
@ -715,10 +715,10 @@ impl<S: ReadAndWrite> ClientSession<S> {
|
||||
lines_and_indices.push((stable_row, line));
|
||||
}
|
||||
}
|
||||
Ok(Pdu::GetLinesResponse(GetLinesResponse::new(
|
||||
Ok(Pdu::GetLinesResponse(GetLinesResponse {
|
||||
tab_id,
|
||||
lines_and_indices,
|
||||
)))
|
||||
lines: lines_and_indices.into(),
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -399,7 +399,7 @@ impl RenderableInner {
|
||||
match result {
|
||||
Ok(result) => {
|
||||
let config = configuration();
|
||||
let lines = result.lines();
|
||||
let lines = result.lines.lines();
|
||||
log::trace!("got {} lines", lines.len());
|
||||
|
||||
for (stable_row, mut line) in lines.into_iter() {
|
||||
|
Loading…
Reference in New Issue
Block a user