Added event buffering, need to figure out a proper fix
This commit is contained in:
parent
9cefeb08e1
commit
4d8cd6d8ea
1 changed files with 24 additions and 11 deletions
|
@ -12,12 +12,9 @@ use alacritty_terminal::{
|
||||||
Term,
|
Term,
|
||||||
};
|
};
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
use futures::{
|
use futures::channel::mpsc::{unbounded, UnboundedReceiver, UnboundedSender};
|
||||||
channel::mpsc::{unbounded, UnboundedReceiver, UnboundedSender},
|
|
||||||
StreamExt,
|
|
||||||
};
|
|
||||||
use settings::{Settings, Shell};
|
use settings::{Settings, Shell};
|
||||||
use std::{collections::HashMap, fmt::Display, path::PathBuf, sync::Arc};
|
use std::{collections::HashMap, fmt::Display, path::PathBuf, sync::Arc, time::Duration};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use gpui::{keymap::Keystroke, ClipboardItem, CursorStyle, Entity, ModelContext};
|
use gpui::{keymap::Keystroke, ClipboardItem, CursorStyle, Entity, ModelContext};
|
||||||
|
@ -234,18 +231,34 @@ impl TerminalBuilder {
|
||||||
|
|
||||||
pub fn subscribe(mut self, cx: &mut ModelContext<Terminal>) -> Terminal {
|
pub fn subscribe(mut self, cx: &mut ModelContext<Terminal>) -> Terminal {
|
||||||
cx.spawn_weak(|this, mut cx| async move {
|
cx.spawn_weak(|this, mut cx| async move {
|
||||||
//Listen for terminal events
|
'outer: loop {
|
||||||
while let Some(event) = self.events_rx.next().await {
|
let delay = cx.background().timer(Duration::from_secs_f32(1.0 / 30.));
|
||||||
|
|
||||||
|
let mut events = vec![];
|
||||||
|
|
||||||
|
loop {
|
||||||
|
match self.events_rx.try_next() {
|
||||||
|
//Have a buffered event
|
||||||
|
Ok(Some(e)) => events.push(e),
|
||||||
|
//Ran out of buffered events
|
||||||
|
Ok(None) => break,
|
||||||
|
//Channel closed, exit
|
||||||
|
Err(_) => break 'outer,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
match this.upgrade(&cx) {
|
match this.upgrade(&cx) {
|
||||||
Some(this) => {
|
Some(this) => {
|
||||||
this.update(&mut cx, |this, cx| {
|
this.update(&mut cx, |this, cx| {
|
||||||
|
for event in events {
|
||||||
this.process_terminal_event(event, cx);
|
this.process_terminal_event(event, cx);
|
||||||
|
}
|
||||||
cx.notify();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
None => break,
|
None => break 'outer,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delay.await;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue