Skip to content

Commit

Permalink
server: Handle new Results from output
Browse files Browse the repository at this point in the history
  • Loading branch information
har7an committed Oct 28, 2022
1 parent c3d6a22 commit 366a6c3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 30 deletions.
13 changes: 8 additions & 5 deletions zellij-server/src/panes/tiled_panes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ impl TiledPanes {
}
pub fn render(&mut self, output: &mut Output, floating_panes_are_visible: bool) -> Result<()> {
let err_context = || "failed to render tiled panes";

let connected_clients: Vec<ClientId> =
{ self.connected_clients.borrow().iter().copied().collect() };
let multiple_users_exist_in_session = { self.connected_clients_in_app.borrow().len() > 1 };
Expand Down Expand Up @@ -450,11 +451,13 @@ impl TiledPanes {
// render boundaries if needed
for (client_id, boundaries) in &mut client_id_to_boundaries {
// TODO: add some conditional rendering here so this isn't rendered for every character
output.add_character_chunks_to_client(
*client_id,
boundaries.render().with_context(err_context)?,
None,
);
output
.add_character_chunks_to_client(
*client_id,
boundaries.render().with_context(err_context)?,
None,
)
.with_context(err_context)?;
}
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion zellij-server/src/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ impl Screen {
for tab_index in tabs_to_close {
self.close_tab_at_index(tab_index).context(err_context)?;
}
let serialized_output = output.serialize();
let serialized_output = output.serialize().context(err_context)?;
self.bus
.senders
.send_to_server(ServerInstruction::Render(Some(serialized_output)))
Expand Down
23 changes: 15 additions & 8 deletions zellij-server/src/tab/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2471,6 +2471,8 @@ impl Tab {
}

fn write_selection_to_clipboard(&self, selection: &str) -> Result<()> {
let err_context = || format!("failed to write selection to clipboard: '{}'", selection);

let mut output = Output::default();
let connected_clients: HashSet<ClientId> =
{ self.connected_clients.borrow().iter().copied().collect() };
Expand All @@ -2481,15 +2483,20 @@ impl Tab {
.clipboard_provider
.set_content(selection, &mut output, client_ids)
{
Ok(_) => {
let serialized_output = output.serialize();
self.senders
.send_to_server(ServerInstruction::Render(Some(serialized_output)))
.context("failed to write selection to clipboard")?;
Event::CopyToClipboard(self.clipboard_provider.as_copy_destination())
},
Ok(_) => output
.serialize()
.and_then(|serialized_output| {
self.senders
.send_to_server(ServerInstruction::Render(Some(serialized_output)))
})
.and_then(|_| {
Ok(Event::CopyToClipboard(
self.clipboard_provider.as_copy_destination(),
))
})
.with_context(err_context)?,
Err(err) => {
log::error!("could not write selection to clipboard: {}", err);
Err::<(), _>(err).with_context(err_context).non_fatal();
Event::SystemClipboardFailure
},
};
Expand Down
37 changes: 21 additions & 16 deletions zellij-server/src/ui/pane_contents_and_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,19 @@ impl<'a> PaneContentsAndUi<'a> {
&mut self,
clients: impl Iterator<Item = ClientId>,
) -> Result<()> {
if let Some((character_chunks, raw_vte_output, sixel_image_chunks)) = self
.pane
.render(None)
.context("failed to render pane contents to multiple clients")?
let err_context = "failed to render pane contents to multiple clients";

if let Some((character_chunks, raw_vte_output, sixel_image_chunks)) =
self.pane.render(None).context(err_context)?
{
let clients: Vec<ClientId> = clients.collect();
self.output.add_character_chunks_to_multiple_clients(
character_chunks,
clients.iter().copied(),
self.z_index,
);
self.output
.add_character_chunks_to_multiple_clients(
character_chunks,
clients.iter().copied(),
self.z_index,
)
.context(err_context)?;
self.output.add_sixel_image_chunks_to_multiple_clients(
sixel_image_chunks,
clients.iter().copied(),
Expand All @@ -77,13 +79,16 @@ impl<'a> PaneContentsAndUi<'a> {
Ok(())
}
pub fn render_pane_contents_for_client(&mut self, client_id: ClientId) -> Result<()> {
let err_context = || format!("failed to render pane contents for client {client_id}");

if let Some((character_chunks, raw_vte_output, sixel_image_chunks)) = self
.pane
.render(Some(client_id))
.with_context(|| format!("failed to render pane contents for client {client_id}"))?
.with_context(err_context)?
{
self.output
.add_character_chunks_to_client(client_id, character_chunks, self.z_index);
.add_character_chunks_to_client(client_id, character_chunks, self.z_index)
.with_context(err_context)?;
self.output.add_sixel_image_chunks_to_client(
client_id,
sixel_image_chunks,
Expand Down Expand Up @@ -150,6 +155,7 @@ impl<'a> PaneContentsAndUi<'a> {
session_is_mirrored: bool,
) -> Result<()> {
let err_context = || format!("failed to render pane frame for client {client_id}");

let pane_focused_for_client_id = self.focused_clients.contains(&client_id);
let other_focused_clients: Vec<ClientId> = self
.focused_clients
Expand Down Expand Up @@ -186,16 +192,15 @@ impl<'a> PaneContentsAndUi<'a> {
other_cursors_exist_in_session: self.multiple_users_exist_in_session,
}
};

if let Some((frame_terminal_characters, vte_output)) = self
.pane
.render_frame(client_id, frame_params, client_mode)
.with_context(err_context)?
{
self.output.add_character_chunks_to_client(
client_id,
frame_terminal_characters,
self.z_index,
);
self.output
.add_character_chunks_to_client(client_id, frame_terminal_characters, self.z_index)
.with_context(err_context)?;
if let Some(vte_output) = vte_output {
self.output
.add_post_vte_instruction_to_client(client_id, &vte_output);
Expand Down

0 comments on commit 366a6c3

Please sign in to comment.