From c2c9560e0782c024d109569fbcd5113cc33d797d Mon Sep 17 00:00:00 2001 From: Dmitry Date: Sun, 26 Apr 2026 12:59:07 +0300 Subject: [PATCH] Fix saved GIF preview rendering --- src/app.h | 2 ++ src/app_attachments.cpp | 11 +++++++-- src/app_shell.cpp | 51 +++++++++++++++++++++++++++++++++-------- 3 files changed, 53 insertions(+), 11 deletions(-) diff --git a/src/app.h b/src/app.h index 7ae1a6f..85ee9c4 100644 --- a/src/app.h +++ b/src/app.h @@ -108,6 +108,8 @@ class App { [[nodiscard]] bool has_inline_attachment_preview(const AttachmentInfo &attachment, int width, int height) const; void clear_attachment_preview_graphics(); + void render_attachment_preview_graphics(const AttachmentInfo &attachment, bool animated, + int top, int left, int width, int height); void render_attachment_preview_graphics(int top, int left, int width, int height); void reset_attachment_viewer_send_preview(); [[nodiscard]] std::vector forward_target_chat_ids() const; diff --git a/src/app_attachments.cpp b/src/app_attachments.cpp index 2c0c698..103a187 100644 --- a/src/app_attachments.cpp +++ b/src/app_attachments.cpp @@ -987,12 +987,19 @@ void App::render_attachment_preview_graphics(int top, int left, int width, int h return; } - const AttachmentInfo &attachment = *attachment_viewer_attachment_; + render_attachment_preview_graphics(*attachment_viewer_attachment_, + attachment_viewer_is_animated_, top, left, width, + height); +} + +void App::render_attachment_preview_graphics(const AttachmentInfo &attachment, bool animated, + int top, int left, int width, int height) { const std::string preview_path = attachment_preview_path(attachment); - if (preview_path.empty() || attachment_viewer_is_animated_) { + if (preview_path.empty() || animated) { clear_attachment_preview_graphics(); return; } + const std::string forced_protocol = configured_image_protocol(); const bool want_kitty = forced_protocol == "kitty" || (forced_protocol.empty() && terminal_supports_kitty_graphics()); diff --git a/src/app_shell.cpp b/src/app_shell.cpp index d38fbbf..8d51025 100644 --- a/src/app_shell.cpp +++ b/src/app_shell.cpp @@ -168,7 +168,6 @@ void App::draw() { } else if (attachment_action_menu_open_) { draw_attachment_action_menu(height, width); } else if (saved_animation_menu_open_) { - clear_attachment_preview_graphics(); draw_saved_animation_menu(height, width); } else if (attachments_menu_open_) { draw_attachments_menu(height, width); @@ -335,6 +334,7 @@ void App::draw_saved_animation_menu(int height, int width) { mvwvline(window, 3, preview_left - 1, ACS_VLINE, menu_height - 4); if (saved_animations_.empty()) { + clear_attachment_preview_graphics(); mvwaddnstr(window, 4, preview_left, "No saved GIFs on this account.", preview_width); } else { const SavedAnimationInfo &animation = saved_animations_[static_cast( @@ -362,20 +362,53 @@ void App::draw_saved_animation_menu(int height, int width) { preview_attachment.can_be_deleted = animation.can_be_deleted; preview_attachment.is_downloaded = animation.is_downloaded; - const std::string preview = render_attachment_preview( - preview_attachment, preview_width, std::max(4, list_height - 4)); - const std::vector preview_lines = split_preview_lines(preview); - for (std::size_t i = 0; i < preview_lines.size() && - static_cast(i) < list_height - 3; - ++i) { - mvwaddnstr(window, 6 + static_cast(i), preview_left, - truncate_to_width(preview_lines[i], preview_width).c_str(), preview_width); + const int preview_top = 6; + const int preview_height = std::max(4, list_height - 4); + if (has_inline_attachment_preview(preview_attachment, preview_width, preview_height)) { + for (int row = 0; row < preview_height; ++row) { + mvwhline(window, preview_top + row, preview_left, ' ', preview_width); + } + } else { + clear_attachment_preview_graphics(); + const std::string preview = + render_attachment_preview(preview_attachment, preview_width, preview_height); + const std::vector preview_lines = split_preview_lines(preview); + for (std::size_t i = 0; i < preview_lines.size() && + static_cast(i) < list_height - 3; + ++i) { + mvwaddnstr(window, preview_top + static_cast(i), preview_left, + truncate_to_width(preview_lines[i], preview_width).c_str(), + preview_width); + } } } mvwaddnstr(window, menu_height - 2, 2, "Enter send r refresh Up/Down move Esc close", menu_width - 4); wrefresh(window); + if (!saved_animations_.empty()) { + const SavedAnimationInfo &animation = saved_animations_[static_cast( + saved_animation_selection_index_)]; + AttachmentInfo preview_attachment; + preview_attachment.type = AttachmentType::Animation; + preview_attachment.name = animation.name; + preview_attachment.size_bytes = animation.size_bytes; + preview_attachment.downloaded_size = animation.downloaded_size; + preview_attachment.file_id = animation.file_id; + preview_attachment.local_path = animation.local_path; + preview_attachment.is_downloading_active = animation.is_downloading_active; + preview_attachment.can_be_downloaded = animation.can_be_downloaded; + preview_attachment.can_be_deleted = animation.can_be_deleted; + preview_attachment.is_downloaded = animation.is_downloaded; + if (has_inline_attachment_preview(preview_attachment, preview_width, + std::max(4, list_height - 4))) { + render_attachment_preview_graphics(preview_attachment, false, top + 6, + left + preview_left, preview_width, + std::max(4, list_height - 4)); + } else { + clear_attachment_preview_graphics(); + } + } delwin(window); }