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シーケンス取得時に画像の大きさを指定できるようにした #107

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions denops/traqvim/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,26 @@ export async function main(denops: Denops) {
// oauthの仮オブジェクト
let oauth: OAuth;
denops.dispatcher = {
async getFile(fileId: unknown): Promise<unknown> {
async getFile(
fileId: unknown,
opts?: unknown,
): Promise<unknown> {
assert(fileId, is.String);
assert(
opts,
is.OptionalOf(is.ObjectOf({
maxWidth: is.Number,
maxHeight: is.Number,
})),
);
const file: Uint8Array = await downloadFile(fileId);
// denops-sixel-view.vimのsixel_viewがUint8Arrayを受け取れる必要がある
const sixel = await denops.dispatch("sixel_view", "img2sixel", file);
const sixel = await denops.dispatch(
"sixel_view",
"img2sixel",
file,
opts,
);
assert(
sixel,
is.ObjectOf({
Expand Down
12 changes: 11 additions & 1 deletion doc/traqvim.jax
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,18 @@ https://github.com/gw31415/denops-sixel-view.vim
endfunction

function s:preview_img(fileId) abort
let font_height = 12
let font_width = font_height / 2
let retina_scale = 2
" download the file and convert it to sixel data
let sixel = denops#request("traqvim", "getFile", [a:fileId])
let sixel = denops#request("traqvim", "getFile",
\[
\ a:fileId,
\ #{
\ maxWidth: winwidth('.') * font_width / 2 * retina_scale,
\ maxHeight: winheight('.') * font_height / 2 * retina_scale,
\ }
\])
call sixel_view#view_sixel(sixel['data'], 0, 0)
endfunction

Expand Down
Loading