mirror of
https://github.com/alexpasmantier/television.git
synced 2025-07-23 10:30:02 +00:00
fix: little fix from the previous merge with origin
This commit is contained in:
parent
2aea007007
commit
ad21cbd7b1
@ -241,7 +241,7 @@ impl Previewer {
|
||||
|
||||
// lookup request stack and return the most recent preview available
|
||||
for request in self.requests.back_to_front() {
|
||||
if let Some(preview) = self.dispatch_request(&request) {
|
||||
if let Some(preview) = self.dispatch_request(&request, preview_window) {
|
||||
return Some(preview);
|
||||
}
|
||||
}
|
||||
|
@ -162,6 +162,7 @@ pub fn try_preview(
|
||||
syntax_theme: &Arc<Theme>,
|
||||
concurrent_tasks: &Arc<AtomicU8>,
|
||||
in_flight_previews: &Arc<Mutex<FxHashSet<String>>>,
|
||||
preview_window: Option<Rect>,
|
||||
) {
|
||||
debug!("Computing preview for {:?}", entry.name);
|
||||
let path = PathBuf::from(&entry.name);
|
||||
@ -249,6 +250,53 @@ pub fn try_preview(
|
||||
cache.lock().insert(entry.name.clone(), &p);
|
||||
}
|
||||
}
|
||||
} else if matches!(FileType::from(&path), FileType::Image) {
|
||||
debug!("File is an image: {:?}", entry.name);
|
||||
let (window_height, window_width) = if let Some(preview_window) =
|
||||
preview_window
|
||||
{
|
||||
// it should be a better way to know the size of the border to remove than this magic number
|
||||
let padding_width = 5;
|
||||
let padding_height = 3;
|
||||
(
|
||||
(preview_window.height - padding_height) * 2,
|
||||
preview_window.width - padding_width * 2,
|
||||
)
|
||||
} else {
|
||||
warn!("Error opening image, impossible to display without information about the size of the preview window");
|
||||
let p = meta::not_supported(&entry.name);
|
||||
cache.lock().insert(entry.name.clone(), &p);
|
||||
return;
|
||||
};
|
||||
match ImageReader::open(path).unwrap().decode() {
|
||||
Ok(image) => {
|
||||
cache.lock().insert(
|
||||
entry.name.clone(),
|
||||
&meta::loading(&format!("Loading {}", entry.name)),
|
||||
);
|
||||
let image = Image::from_dynamic_image(
|
||||
image,
|
||||
u32::from(window_height),
|
||||
u32::from(window_width),
|
||||
);
|
||||
let total_lines =
|
||||
image.pixel_grid.len().try_into().unwrap_or(u16::MAX);
|
||||
let content = PreviewContent::Image(image);
|
||||
let preview = Arc::new(Preview::new(
|
||||
entry.name.clone(),
|
||||
content,
|
||||
entry.icon,
|
||||
None,
|
||||
total_lines,
|
||||
));
|
||||
cache.lock().insert(entry.name.clone(), &preview);
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Error opening file: {:?}", e);
|
||||
let p = meta::not_supported(&entry.name);
|
||||
cache.lock().insert(entry.name.clone(), &p);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
debug!("File isn't text-based: {:?}", entry.name);
|
||||
let preview = meta::not_supported(&entry.name);
|
||||
|
@ -4,7 +4,6 @@ use crate::preview::{
|
||||
PREVIEW_NOT_SUPPORTED_MSG, TIMEOUT_MSG,
|
||||
};
|
||||
use crate::screen::{
|
||||
cache::RenderedPreviewCache,
|
||||
colors::{Colorscheme, PreviewColorscheme},
|
||||
};
|
||||
use crate::utils::strings::{
|
||||
@ -20,7 +19,6 @@ use ratatui::{
|
||||
prelude::{Color, Line, Modifier, Span, Style, Stylize, Text},
|
||||
};
|
||||
use std::str::FromStr;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use crate::utils::image::{Image, ImageColor, PIXEL};
|
||||
|
||||
#[allow(dead_code)]
|
||||
@ -250,11 +248,11 @@ fn build_syntect_highlighted_paragraph<'a>(
|
||||
//.scroll((preview_scroll, 0))
|
||||
}
|
||||
|
||||
fn build_image_paragraph(
|
||||
image: &Image,
|
||||
preview_block: Block<'_>,
|
||||
fn build_image_paragraph<'a>(
|
||||
image: &'a Image,
|
||||
preview_block: Block<'a>,
|
||||
colorscheme: PreviewColorscheme,
|
||||
) -> Paragraph<'_> {
|
||||
) -> Paragraph<'a> {
|
||||
let lines = image
|
||||
.pixel_grid
|
||||
.iter()
|
||||
|
@ -20,6 +20,7 @@ use copypasta::{ClipboardContext, ClipboardProvider};
|
||||
use rustc_hash::{FxBuildHasher, FxHashSet};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashSet;
|
||||
use ratatui::layout::Rect;
|
||||
use tokio::sync::mpsc::{Receiver, Sender, UnboundedSender};
|
||||
use tracing::error;
|
||||
|
||||
@ -315,7 +316,7 @@ impl Television {
|
||||
&& !matches!(selected_entry.preview_type, PreviewType::None)
|
||||
{
|
||||
// preview content
|
||||
if let Some(preview) = self.previewer.preview(selected_entry, ) {
|
||||
if let Some(preview) = self.previewer.preview(selected_entry, Some(Rect::new(0,0,50,50))) {
|
||||
if self.preview_state.preview.title != preview.title {
|
||||
self.preview_state.update(
|
||||
preview,
|
||||
@ -583,7 +584,7 @@ impl Television {
|
||||
let selected_entry = self
|
||||
.get_selected_entry(Some(Mode::Channel))
|
||||
.unwrap_or(ENTRY_PLACEHOLDER);
|
||||
;
|
||||
|
||||
self.update_preview_state(&selected_entry)?;
|
||||
|
||||
self.ticks += 1;
|
||||
|
@ -3,7 +3,7 @@ use image::DynamicImage;
|
||||
|
||||
pub const PIXEL: char = '▀';
|
||||
const FILTER: FilterType = FilterType::Triangle;
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, Hash, PartialEq)]
|
||||
pub struct Image {
|
||||
pub pixel_grid: Vec<Vec<(ImageColor, ImageColor)>>,
|
||||
}
|
||||
@ -63,7 +63,7 @@ impl Image {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
#[derive(Clone, Copy, Debug, Hash, PartialEq)]
|
||||
pub struct ImageColor {
|
||||
pub r: u8,
|
||||
pub g: u8,
|
||||
|
Loading…
x
Reference in New Issue
Block a user