Skip to content

Commit

Permalink
feat(cli): add imgcat
Browse files Browse the repository at this point in the history
  • Loading branch information
CyanSalt committed Nov 1, 2024
1 parent 6c89796 commit 4c26883
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions addons/cli/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"[n-times]#!cli.usage.roll": "[n 次]",
"Preview a file#!cli.description.preview": "预览文件",
"[file]#!cli.usage.preview": "[文件]",
"Display a image in terminal#!cli.description.imgcat": "在终端中显示图片",
"<file>#!cli.usage.imgcat": "<文件>",
"Terminate all processes on a port#!cli.description.free": "终止端口上的所有进程",
"<port>#!cli.usage.free": "<端口>",
"Get history in current session#!cli.description.history": "获取当前会话的历史",
Expand Down
15 changes: 13 additions & 2 deletions addons/cli/src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import type EventEmitter from 'node:events'
import * as fs from 'node:fs'
import * as os from 'node:os'
import * as path from 'node:path'
import * as util from 'node:util'
import * as vm from 'node:vm'
import ipc from '@achrinza/node-ipc'
import * as cfonts from 'cfonts'
import chalk from 'chalk'
Expand Down Expand Up @@ -245,6 +243,19 @@ ${
},
})

commas.context.provide('cli.command', {
command: 'imgcat',
description: 'Display a image in terminal#!cli.description.imgcat',
usage: '<file>#!cli.usage.imgcat',
async handler({ argv, cwd }) {
if (!argv.length) return
const relativePath = argv[0]
const file = path.resolve(cwd, relativePath)
const image = await fs.promises.readFile(file)
return `\u001B]1337;File=inline=1;size=${image.length};name=${relativePath}:${image.toString('base64')}`
},
})

commas.context.provide('cli.command', {
command: 'free',
description: 'Terminate all processes on a port#!cli.description.free',
Expand Down

0 comments on commit 4c26883

Please sign in to comment.