mirror of
https://github.com/alexpasmantier/television.git
synced 2025-06-06 19:45:23 +00:00
perf: trying things with the preview
This commit is contained in:
parent
cb77f5c663
commit
4a62feb524
@ -156,39 +156,43 @@ impl Previewer {
|
|||||||
debug!("Preview already in cache");
|
debug!("Preview already in cache");
|
||||||
return Some(preview);
|
return Some(preview);
|
||||||
}
|
}
|
||||||
// if we've already acknowledged the request
|
// if we haven't acknowledged the request yet, acknowledge it
|
||||||
if let Some(initial_request) = self.requests.get(entry) {
|
if !self.requests.contains_key(entry) {
|
||||||
debug!("Request already acknowledged");
|
self.requests.insert(entry.clone(), Instant::now());
|
||||||
// and we're past the debounce duration
|
}
|
||||||
if initial_request.elapsed() > DEBOUNCE_DURATION {
|
|
||||||
debug!("Past debounce duration");
|
let initial_request = self.requests.get(entry).unwrap();
|
||||||
// forward the request to the appropriate previewer
|
// if we're past the debounce duration
|
||||||
let preview = match &entry.preview_type {
|
if initial_request.elapsed() > DEBOUNCE_DURATION {
|
||||||
PreviewType::Basic => Some(self.basic.preview(entry)),
|
debug!("Past debounce duration");
|
||||||
PreviewType::EnvVar => Some(self.env_var.preview(entry)),
|
// forward the request to the appropriate previewer
|
||||||
PreviewType::Files => self.file.preview(entry),
|
let preview = match &entry.preview_type {
|
||||||
PreviewType::Command(cmd) => {
|
PreviewType::Basic => Some(self.basic.preview(entry)),
|
||||||
self.command.preview(entry, cmd)
|
PreviewType::EnvVar => Some(self.env_var.preview(entry)),
|
||||||
}
|
PreviewType::Files => self.file.preview(entry),
|
||||||
PreviewType::None => Some(Arc::new(Preview::default())),
|
PreviewType::Command(cmd) => self.command.preview(entry, cmd),
|
||||||
};
|
PreviewType::None => Some(Arc::new(Preview::default())),
|
||||||
// if we got a preview, cache it
|
};
|
||||||
if let Some(preview) = preview {
|
// if we got a preview, cache it
|
||||||
self.cache.lock().insert(entry.name.clone(), &preview);
|
if let Some(preview) = preview {
|
||||||
Some(preview)
|
self.cache.lock().insert(entry.name.clone(), &preview);
|
||||||
} else {
|
Some(preview)
|
||||||
None
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
debug!("Not past debounce duration");
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
// if we haven't acknowledged the request yet
|
debug!("Not past debounce duration");
|
||||||
else {
|
// partial preview
|
||||||
debug!("Request not acknowledged, acknowledging");
|
let preview = match &entry.preview_type {
|
||||||
self.requests.insert(entry.clone(), Instant::now());
|
PreviewType::Basic => Some(self.basic.preview(entry)),
|
||||||
None
|
PreviewType::EnvVar => Some(self.env_var.preview(entry)),
|
||||||
|
PreviewType::Files => self.file.preview(entry),
|
||||||
|
PreviewType::Command(cmd) => {
|
||||||
|
self.command.partial_preview(entry, cmd)
|
||||||
|
}
|
||||||
|
PreviewType::None => Some(Arc::new(Preview::default())),
|
||||||
|
};
|
||||||
|
Some(preview)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,10 +150,11 @@ pub fn try_preview(
|
|||||||
Ok(file) => {
|
Ok(file) => {
|
||||||
// compute the highlighted version in the background
|
// compute the highlighted version in the background
|
||||||
let mut reader = BufReader::new(file);
|
let mut reader = BufReader::new(file);
|
||||||
|
|
||||||
reader.seek(std::io::SeekFrom::Start(0)).unwrap();
|
reader.seek(std::io::SeekFrom::Start(0)).unwrap();
|
||||||
let preview = compute_highlighted_text_preview(
|
let preview = compute_highlighted_text_preview(
|
||||||
entry,
|
entry,
|
||||||
reader,
|
reader.lines().map_while(Result::ok).collect(),
|
||||||
syntax_set,
|
syntax_set,
|
||||||
syntax_theme,
|
syntax_theme,
|
||||||
);
|
);
|
||||||
@ -176,7 +177,7 @@ pub fn try_preview(
|
|||||||
|
|
||||||
fn compute_highlighted_text_preview(
|
fn compute_highlighted_text_preview(
|
||||||
entry: &entry::Entry,
|
entry: &entry::Entry,
|
||||||
reader: BufReader<File>,
|
lines: Vec<&str>,
|
||||||
syntax_set: &SyntaxSet,
|
syntax_set: &SyntaxSet,
|
||||||
syntax_theme: &Theme,
|
syntax_theme: &Theme,
|
||||||
) -> Arc<Preview> {
|
) -> Arc<Preview> {
|
||||||
@ -184,9 +185,8 @@ fn compute_highlighted_text_preview(
|
|||||||
"Computing highlights in the background for {:?}",
|
"Computing highlights in the background for {:?}",
|
||||||
entry.name
|
entry.name
|
||||||
);
|
);
|
||||||
let lines: Vec<String> = reader
|
let lines: Vec<String> = lines
|
||||||
.lines()
|
.iter()
|
||||||
.map_while(Result::ok)
|
|
||||||
// we need to add a newline here because sublime syntaxes expect one
|
// we need to add a newline here because sublime syntaxes expect one
|
||||||
// to be present at the end of each line
|
// to be present at the end of each line
|
||||||
.map(|line| preprocess_line(&line).0 + "\n")
|
.map(|line| preprocess_line(&line).0 + "\n")
|
||||||
|
@ -561,6 +561,18 @@ impl Television {
|
|||||||
{
|
{
|
||||||
// preview content
|
// preview content
|
||||||
let maybe_preview = self.previewer.preview(&selected_entry);
|
let maybe_preview = self.previewer.preview(&selected_entry);
|
||||||
|
//// preload the next 3 previews
|
||||||
|
//if let Some(i) = self.results_picker.selected() {
|
||||||
|
// for j in 1..=5 {
|
||||||
|
// if let Some(entry) =
|
||||||
|
// self.channel.get_result((i + j).try_into().unwrap())
|
||||||
|
// {
|
||||||
|
// let _ = self.previewer.preview(&entry);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
let _ = self.previewer.preview(&selected_entry);
|
||||||
|
|
||||||
if let Some(preview) = &maybe_preview {
|
if let Some(preview) = &maybe_preview {
|
||||||
self.current_preview_total_lines = preview.total_lines();
|
self.current_preview_total_lines = preview.total_lines();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user