Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

画像を取得して、sixelで表示できるようにする #84

Merged
merged 3 commits into from
Aug 30, 2024

Conversation

kamecha
Copy link
Owner

@kamecha kamecha commented Jul 13, 2024

https://github.com/gw31415/denops-sixel-view.vim

↑を使ってsixelを表示するようにしてみた
本家の方がUint8Arrayを受け付けるようにしたり、色々手を加える必要があるため一旦保留

Close #7

Summary by CodeRabbit

  • New Features

    • Introduced a new method for downloading files, enabling users to retrieve and display images via sixel graphics.
    • Added a comprehensive FAQ section in the documentation to assist users with image display using the plugin.
  • Bug Fixes

    • Improved error handling during file downloads to enhance user experience by preventing application crashes.

@kamecha kamecha added the enhancement New feature or request label Jul 13, 2024
@kamecha kamecha self-assigned this Jul 13, 2024
Copy link

coderabbitai bot commented Jul 13, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The recent changes enhance the denops functionality by introducing an asynchronous method getFile for downloading files and processing them for image rendering using the sixel graphics protocol. Additionally, a new downloadFile function has been implemented to facilitate file fetching, and documentation has been updated to guide users on utilizing these features effectively.

Changes

Files Change Summary
denops/traqvim/main.ts Added async getFile(fileId: unknown) method to download files and process them for sixel rendering.
denops/traqvim/model.ts Introduced async downloadFile(fileId: string): Promise<Uint8Array> for fetching files based on file IDs.
doc/traqvim.jax Added an FAQ section on displaying images using sixel graphics, including installation steps and usage examples for user guidance.

Assessment against linked issues

Objective Addressed Explanation
Sixel対応端末での画像表示 (Issue #7)
メッセージでの画像表示やスタンプ表示をやってみる (Issue #7)

Poem

In the denops land where images play,
A rabbit hops by, brightening the day.
With sixel magic, we’ll show our art,
Downloading wonders, a true work of heart.
So let’s celebrate, with joy and glee,
For every file brings new sights to see! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@kamecha
Copy link
Owner Author

kamecha commented Jul 13, 2024

画像がでか過ぎたりするとその一部しか表示されないので、補完ウィンドウみたいな感じで適切な大きさにするようにしたい

@kamecha kamecha removed their assignment Aug 8, 2024
@kamecha
Copy link
Owner Author

kamecha commented Aug 18, 2024

gw31415/denops-sixel-view.vim#1

PR出してみた
ワクo(´∇`o)(o´∇`)oワク

@kamecha
Copy link
Owner Author

kamecha commented Aug 18, 2024

sixel用プラグインがちゃんと認識されてるかチェックを入れとく

@kamecha kamecha marked this pull request as ready for review August 18, 2024 14:35
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Outside diff range, codebase verification and nitpick comments (1)
doc/traqvim.jax (1)

208-237: Well-structured FAQ section.

The new FAQ section provides clear instructions on using the sixel graphics protocol with the denops-sixel-view.vim plugin. The example functions and key mapping are well-documented, making it easy for users to implement the image display feature. Ensure that the plugin's installation instructions are up-to-date and consider adding a brief explanation of sixel for users unfamiliar with the format.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ed398bb and cd5d8cd.

Files selected for processing (3)
  • denops/traqvim/main.ts (3 hunks)
  • denops/traqvim/model.ts (1 hunks)
  • doc/traqvim.jax (1 hunks)

Comment on lines +296 to +388
export const downloadFile = async (
fileId: string,
): Promise<Uint8Array> => {
try {
const fileRes = await api.fetchWithToken(
"GET",
"/files/" + fileId,
{},
);
const blob = await fileRes.blob();
return new Uint8Array(await blob.arrayBuffer());
} catch (e) {
console.error(e);
}
return new Uint8Array();
};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure comprehensive error handling in downloadFile.

The downloadFile function correctly uses try-catch for error handling. However, consider providing more context in the error message or logging additional details to aid in debugging. Additionally, ensure that the API endpoint and response handling are robust and handle potential edge cases, such as network failures or unexpected response formats.

-    console.error(e);
+    console.error('Failed to download file:', e);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const downloadFile = async (
fileId: string,
): Promise<Uint8Array> => {
try {
const fileRes = await api.fetchWithToken(
"GET",
"/files/" + fileId,
{},
);
const blob = await fileRes.blob();
return new Uint8Array(await blob.arrayBuffer());
} catch (e) {
console.error(e);
}
return new Uint8Array();
};
export const downloadFile = async (
fileId: string,
): Promise<Uint8Array> => {
try {
const fileRes = await api.fetchWithToken(
"GET",
"/files/" + fileId,
{},
);
const blob = await fileRes.blob();
return new Uint8Array(await blob.arrayBuffer());
} catch (e) {
console.error('Failed to download file:', e);
}
return new Uint8Array();
};

Comment on lines 43 to 61
async getFile(fileId: unknown): Promise<unknown> {
ensureString(fileId);
const file: Uint8Array = await downloadFile(fileId);
// denops-sixel-view.vimのsixel_viewがUint8Arrayを受け取れる必要がある
const sixel = denops.dispatch("sixel_view", "img2sixel", file);
ensureObject<{ data: string; height: number; width: number }>(sixel);
return sixel;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validate sixel_view dispatch result thoroughly.

The getFile method ensures the fileId is a string and handles the Uint8Array correctly. However, the validation of the sixel object could be more robust. Consider checking if the sixel object is not only an object but also contains the expected properties with valid values to prevent runtime errors.

-      ensureObject<{ data: string; height: number; width: number }>(sixel);
+      const { data, height, width } = ensureObject<{ data: string; height: number; width: number }>(sixel);
+      if (typeof data !== 'string' || typeof height !== 'number' || typeof width !== 'number') {
+        throw new Error('Invalid sixel object structure');
+      }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async getFile(fileId: unknown): Promise<unknown> {
ensureString(fileId);
const file: Uint8Array = await downloadFile(fileId);
// denops-sixel-view.vimのsixel_viewがUint8Arrayを受け取れる必要がある
const sixel = denops.dispatch("sixel_view", "img2sixel", file);
ensureObject<{ data: string; height: number; width: number }>(sixel);
return sixel;
async getFile(fileId: unknown): Promise<unknown> {
ensureString(fileId);
const file: Uint8Array = await downloadFile(fileId);
// denops-sixel-view.vimのsixel_viewがUint8Arrayを受け取れる必要がある
const sixel = denops.dispatch("sixel_view", "img2sixel", file);
const { data, height, width } = ensureObject<{ data: string; height: number; width: number }>(sixel);
if (typeof data !== 'string' || typeof height !== 'number' || typeof width !== 'number') {
throw new Error('Invalid sixel object structure');
}
return sixel;

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between cd5d8cd and 26db8b3.

Files selected for processing (1)
  • doc/traqvim.jax (1 hunks)
Additional comments not posted (1)
doc/traqvim.jax (1)

207-246: Review of New FAQ Section and Associated Functions and Key Mappings

  1. FAQ Section:

    • The FAQ section provides a clear guide on how to display images using the sixel format. This aligns well with the PR objectives and linked issues.
    • The instructions are concise and direct users to install the necessary plugin and set up functions.
    • The FAQ section is well-written and serves its purpose effectively.
  2. Function s:clear:

    • This function is designed to clear the displayed image, similar to clearing the screen in a terminal.
    • The implementation directly calls a function from the sixel_view plugin, which is appropriate.
    • The function is correctly implemented and documented.
  3. Function s:preview_img:

    • This function handles the downloading and conversion of files to sixel format for display.
    • It uses the denops#request function to fetch the file, which is a good use of asynchronous capabilities in Vim plugins.
    • The function is well-implemented and serves its intended purpose.
  4. Function s:preview_cursor_img:

    • This function is triggered by cursor movement and is designed to preview an image based on the URL at the cursor position.
    • It extracts the file ID from the URL and calls s:preview_img.
    • The use of an autocommand to clear the image on cursor movement or buffer leave is a thoughtful addition.
    • The function is innovative and enhances user interaction with images.
  5. Key Mapping:

    • The key mapping for K is set to trigger the s:preview_cursor_img function.
    • This choice of key is intuitive for Vim users, as K is often associated with looking up documentation or related information.
    • The key mapping is appropriately set and documented.

Overall, the changes are well-aligned with the objectives of the PR and enhance the documentation significantly. The implementation of functions and key mappings is robust, ensuring a good user experience.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 26db8b3 and 4467409.

Files selected for processing (3)
  • denops/traqvim/main.ts (2 hunks)
  • denops/traqvim/model.ts (1 hunks)
  • doc/traqvim.jax (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • doc/traqvim.jax
Additional comments not posted (1)
denops/traqvim/model.ts (1)

345-360: Enhance error handling in downloadFile.

The basic functionality of the downloadFile function is implemented correctly. However, the error handling could be more informative to aid in debugging. Consider adding more context to the error message and ensuring that the API endpoint and response handling are robust enough to handle potential edge cases, such as network failures or unexpected response formats.

Apply this diff to enhance the error message:

-    console.error(e);
+    console.error('Failed to download file:', e);

Likely invalid or redundant comment.

Comment on lines +44 to +62
async getFile(fileId: unknown): Promise<unknown> {
assert(fileId, is.String);
const file: Uint8Array = await downloadFile(fileId);
// denops-sixel-view.vimのsixel_viewがUint8Arrayを受け取れる必要がある
const sixel = await denops.dispatch("sixel_view", "img2sixel", file);
assert(
sixel,
is.ObjectOf({
data: is.String,
height: is.Number,
width: is.Number,
}),
);
return sixel;
},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enhance validation of sixel object in getFile.

The getFile method correctly handles file fetching and initial processing. However, the validation of the sixel object could be more robust to prevent runtime errors. Consider checking if the sixel object not only exists but also contains the expected properties with valid values.

Apply this diff to enhance the validation:

-      ensureObject<{ data: string; height: number; width: number }>(sixel);
+      const { data, height, width } = ensureObject<{ data: string; height: number; width: number }>(sixel);
+      if (typeof data !== 'string' || typeof height !== 'number' || typeof width !== 'number') {
+        throw new Error('Invalid sixel object structure');
+      }

Committable suggestion was skipped due to low confidence.

@kamecha kamecha merged commit 8c6fce9 into master Aug 30, 2024
1 check passed
@kamecha kamecha deleted the feature/view-file-sixel branch August 30, 2024 14:33
@kamecha
Copy link
Owner Author

kamecha commented Aug 30, 2024

windows terminalもpreviewだとsixel対応したし、mergeしてドッグフーディングとやらをやってきたい

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sixel対応端末での画像表示
1 participant