Implemcargo
This commit is contained in:
parent
0ccdc64668
commit
8a48a11a00
3 changed files with 42 additions and 7 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -62,7 +62,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "alacritty_config_derive"
|
name = "alacritty_config_derive"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/alacritty?rev=e9b864860ec79cc1b70042aafce100cdd6985a0a#e9b864860ec79cc1b70042aafce100cdd6985a0a"
|
source = "git+https://github.com/zed-industries/alacritty?rev=382e1892c4eaae7d45ec6ea580db47242ec66e31#382e1892c4eaae7d45ec6ea580db47242ec66e31"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
@ -72,7 +72,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "alacritty_terminal"
|
name = "alacritty_terminal"
|
||||||
version = "0.17.0-dev"
|
version = "0.17.0-dev"
|
||||||
source = "git+https://github.com/zed-industries/alacritty?rev=e9b864860ec79cc1b70042aafce100cdd6985a0a#e9b864860ec79cc1b70042aafce100cdd6985a0a"
|
source = "git+https://github.com/zed-industries/alacritty?rev=382e1892c4eaae7d45ec6ea580db47242ec66e31#382e1892c4eaae7d45ec6ea580db47242ec66e31"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"alacritty_config_derive",
|
"alacritty_config_derive",
|
||||||
"base64 0.13.0",
|
"base64 0.13.0",
|
||||||
|
|
|
@ -8,7 +8,7 @@ path = "src/terminal.rs"
|
||||||
doctest = false
|
doctest = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
alacritty_terminal = { git = "https://github.com/zed-industries/alacritty", rev = "e9b864860ec79cc1b70042aafce100cdd6985a0a"}
|
alacritty_terminal = { git = "https://github.com/zed-industries/alacritty", rev = "382e1892c4eaae7d45ec6ea580db47242ec66e31"}
|
||||||
editor = { path = "../editor" }
|
editor = { path = "../editor" }
|
||||||
util = { path = "../util" }
|
util = { path = "../util" }
|
||||||
gpui = { path = "../gpui" }
|
gpui = { path = "../gpui" }
|
||||||
|
|
|
@ -54,7 +54,7 @@ const DEBUG_TERMINAL_WIDTH: f32 = 500.;
|
||||||
const DEBUG_TERMINAL_HEIGHT: f32 = 30.; //This needs to be wide enough that the CI & a local dev's prompt can fill the whole space.
|
const DEBUG_TERMINAL_HEIGHT: f32 = 30.; //This needs to be wide enough that the CI & a local dev's prompt can fill the whole space.
|
||||||
const DEBUG_CELL_WIDTH: f32 = 5.;
|
const DEBUG_CELL_WIDTH: f32 = 5.;
|
||||||
const DEBUG_LINE_HEIGHT: f32 = 5.;
|
const DEBUG_LINE_HEIGHT: f32 = 5.;
|
||||||
const TERM_FRAME_RATE: f32 = 120.;
|
const MAX_FRAME_RATE: f32 = 120.;
|
||||||
|
|
||||||
///Upward flowing events, for changing the title and such
|
///Upward flowing events, for changing the title and such
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
@ -361,7 +361,7 @@ impl TerminalBuilder {
|
||||||
//https://news.ycombinator.com/item?id=17634547#17635856
|
//https://news.ycombinator.com/item?id=17634547#17635856
|
||||||
let delay = cx
|
let delay = cx
|
||||||
.background()
|
.background()
|
||||||
.timer(Duration::from_secs_f32(1.0 / TERM_FRAME_RATE));
|
.timer(Duration::from_secs_f32(1.0 / Terminal::default_fps()));
|
||||||
if frames_to_skip == 0 {
|
if frames_to_skip == 0 {
|
||||||
let mut events = vec![];
|
let mut events = vec![];
|
||||||
|
|
||||||
|
@ -404,12 +404,17 @@ pub struct Terminal {
|
||||||
events: Vec<InternalEvent>,
|
events: Vec<InternalEvent>,
|
||||||
default_title: String,
|
default_title: String,
|
||||||
title: String,
|
title: String,
|
||||||
|
frames_to_skip: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Terminal {
|
impl Terminal {
|
||||||
|
fn default_fps() -> f32 {
|
||||||
|
MAX_FRAME_RATE
|
||||||
|
}
|
||||||
|
|
||||||
///Tells the render loop how many frames to skip before reading from the terminal.
|
///Tells the render loop how many frames to skip before reading from the terminal.
|
||||||
fn frames_to_skip(&self) -> usize {
|
fn frames_to_skip(&self) -> usize {
|
||||||
4
|
self.frames_to_skip
|
||||||
}
|
}
|
||||||
|
|
||||||
fn push_events(&mut self, events: Vec<AlacTermEvent>) {
|
fn push_events(&mut self, events: Vec<AlacTermEvent>) {
|
||||||
|
@ -430,6 +435,7 @@ impl Terminal {
|
||||||
AlacTermEvent::Wakeup => {
|
AlacTermEvent::Wakeup => {
|
||||||
cx.emit(Event::Wakeup);
|
cx.emit(Event::Wakeup);
|
||||||
}
|
}
|
||||||
|
//TODO: Does not need to be in lock context
|
||||||
AlacTermEvent::PtyWrite(out) => self.notify_pty(out.clone()),
|
AlacTermEvent::PtyWrite(out) => self.notify_pty(out.clone()),
|
||||||
AlacTermEvent::MouseCursorDirty => {
|
AlacTermEvent::MouseCursorDirty => {
|
||||||
//Calculate new cursor style.
|
//Calculate new cursor style.
|
||||||
|
@ -445,9 +451,11 @@ impl Terminal {
|
||||||
self.title = self.default_title.clone();
|
self.title = self.default_title.clone();
|
||||||
cx.emit(Event::TitleChanged);
|
cx.emit(Event::TitleChanged);
|
||||||
}
|
}
|
||||||
|
//TODO: Does not need to be in lock context
|
||||||
AlacTermEvent::ClipboardStore(_, data) => {
|
AlacTermEvent::ClipboardStore(_, data) => {
|
||||||
cx.write_to_clipboard(ClipboardItem::new(data.to_string()))
|
cx.write_to_clipboard(ClipboardItem::new(data.to_string()))
|
||||||
}
|
}
|
||||||
|
//TODO: Does not need to be in lock context
|
||||||
AlacTermEvent::ClipboardLoad(_, format) => self.notify_pty(format(
|
AlacTermEvent::ClipboardLoad(_, format) => self.notify_pty(format(
|
||||||
&cx.read_from_clipboard()
|
&cx.read_from_clipboard()
|
||||||
.map(|ci| ci.text().to_string())
|
.map(|ci| ci.text().to_string())
|
||||||
|
@ -557,6 +565,8 @@ impl Terminal {
|
||||||
where
|
where
|
||||||
F: FnOnce(RenderableContent, char) -> T,
|
F: FnOnce(RenderableContent, char) -> T,
|
||||||
{
|
{
|
||||||
|
let back_buffer_size = 5000;
|
||||||
|
|
||||||
let m = self.term.clone(); //Arc clone
|
let m = self.term.clone(); //Arc clone
|
||||||
let mut term = m.lock();
|
let mut term = m.lock();
|
||||||
|
|
||||||
|
@ -564,9 +574,34 @@ impl Terminal {
|
||||||
self.process_terminal_event(&e, &mut term, cx)
|
self.process_terminal_event(&e, &mut term, cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// let overflow_size = term.grid().total_lines()
|
||||||
|
|
||||||
|
//We need something that starts at 0, and grows upward.
|
||||||
|
|
||||||
|
//Concept: Set storage twice as long as is actually available.
|
||||||
|
//Alacritty Default is 10,000, so for now hardcode 5,000 lines for history
|
||||||
|
//and 5,000 for measurement (Later, put this in configuration 😤)
|
||||||
|
//Measure the number of lines over 5,000 and the time since last frame
|
||||||
|
//divide for velocity
|
||||||
|
//This is the velocity of lines. map linearly to [0..10] (with .round())
|
||||||
|
//(Later, perhaps make this an exponential backoff)
|
||||||
|
//Report that number as the skip frames.
|
||||||
|
|
||||||
|
let velocity = term.grid().history_size().saturating_sub(back_buffer_size);
|
||||||
|
|
||||||
|
let fractional_velocity = velocity as f32 / back_buffer_size as f32;
|
||||||
|
|
||||||
|
//3rd power
|
||||||
|
let scaled_fraction = fractional_velocity * fractional_velocity * fractional_velocity;
|
||||||
|
|
||||||
|
self.frames_to_skip = (scaled_fraction * Self::default_fps() / 10.).round() as usize;
|
||||||
|
|
||||||
|
term.grid_mut().update_history(back_buffer_size); //Clear out the measurement space
|
||||||
|
term.grid_mut().update_history(back_buffer_size * 2); //Extra space for measuring
|
||||||
|
|
||||||
let content = term.renderable_content();
|
let content = term.renderable_content();
|
||||||
|
|
||||||
println!("Offset: {}", term.grid().history_size());
|
println!("Offset: {}", term.grid().total_lines());
|
||||||
|
|
||||||
let cursor_text = term.grid()[content.cursor.point].c;
|
let cursor_text = term.grid()[content.cursor.point].c;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue