Skip to content

Commit

Permalink
server/os_io: Remove last SpawnTerminalError
Browse files Browse the repository at this point in the history
  • Loading branch information
har7an committed Nov 2, 2022
1 parent 72612d1 commit 147a706
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions zellij-server/src/os_input_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ pub trait ServerOsApi: Send + Sync {
default_editor: Option<PathBuf>,
) -> Result<(u32, RawFd, RawFd)>;
// reserves a terminal id without actually opening a terminal
fn reserve_terminal_id(&self) -> Result<u32, SpawnTerminalError> {
fn reserve_terminal_id(&self) -> Result<u32> {
unimplemented!()
}
/// Read bytes from the standard output of the virtual terminal referred to by `fd`.
Expand Down Expand Up @@ -497,13 +497,16 @@ impl ServerOsApi for ServerOsInputOutput {
None => Err(anyhow!("no more terminal IDs left to allocate")),
}
}
fn reserve_terminal_id(&self) -> Result<u32, SpawnTerminalError> {
fn reserve_terminal_id(&self) -> Result<u32> {
let err_context = || "failed to reserve a terminal ID".to_string();

let mut terminal_id = None;
{
let current_ids: HashSet<u32> = self
.terminal_id_to_raw_fd
.lock()
.unwrap()
.to_anyhow()
.with_context(err_context)?
.keys()
.copied()
.collect();
Expand All @@ -519,11 +522,12 @@ impl ServerOsApi for ServerOsInputOutput {
Some(terminal_id) => {
self.terminal_id_to_raw_fd
.lock()
.unwrap()
.to_anyhow()
.with_context(err_context)?
.insert(terminal_id, None);
Ok(terminal_id)
},
None => Err(SpawnTerminalError::NoMoreTerminalIds),
None => Err(anyhow!("no more terminal IDs available")),
}
}
fn read_from_tty_stdout(&self, fd: RawFd, buf: &mut [u8]) -> Result<usize> {
Expand Down

0 comments on commit 147a706

Please sign in to comment.