自定义文件系统
1. 导入导出
import 命令可以导入 json 文件系统
export 命令可以导出当前文件系统
通过 mkdir 和 touch 命令修改当前文件系统,然后通过 export 导出
2. 代码中自定义
格式类似下文
json
{
"name": "/",
"type": 0,
"body": [
{
"name": "usr",
"type": 0,
"body": [
{
"name": "bin",
"type": 0,
"body": []
},
{
"name": "config",
"type": 1,
"body": "{\"user\": \"insorker\",\"version\":\"v1.0.0\",\"hostname\":\"xdsh\",\"wdpathLength\":2}"
}
]
},
{
"name": "xdsh",
"type": 0,
"body": [
{
"name": "docs",
"type": 2,
"body": "https://github.com/xdshell/docs"
},
{
"name": "xdsh",
"type": 2,
"body": "https://github.com/xdshell/xdsh"
}
]
},
{
"name": "insorker",
"type": 0,
"body": [
{
"name": "bilibili",
"type": 2,
"body": "https://space.bilibili.com/434618849/"
},
{
"name": "github",
"type": 2,
"body": "https://github.com/xdshell"
}
]
}
]
}
导入代码
ts
import { Terminal } from './src/js/components/terminal'
import img from './img.json'
let content = <HTMLDivElement>document.getElementsByClassName('content')[0]
let { terminal, xdsh } = Terminal.newTerminal(img)
xdsh.registerCmd({
name: 'test',
manual: 'test',
exec: (args: string[]): boolean => {
xdsh.cli.history.append('test')
return true
}
})
xdsh.registerHotkey('m', (event)=>{
event.preventDefault()
xdsh.cli.history.append('ctrl+m')
}, true)
content.appendChild(terminal)
更多详见源码