Skip to content

Commit

Permalink
Merge pull request #107 from kamecha/feature/view-file-sixel
Browse files Browse the repository at this point in the history
sixelシーケンス取得時に画像の大きさを指定できるようにした
  • Loading branch information
kamecha authored Aug 30, 2024
2 parents 8c6fce9 + 82bf5e6 commit a2e3ee9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
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

0 comments on commit a2e3ee9

Please sign in to comment.