web浏览器停止运行此脚本 在浏览器里面运行命令行,真香!
之前我写过一篇《》,这个项目就是把一些脚本的执行结果输出到了网页里面。
但是这个还是有很多改进空间,比如说 UI 能好看些,甚至能执行交互命令该多好,最后思来想去,它的究极形态不就是一个 Web 版的 Terminal (终端)吗?
然后本来我还想着对项目进行改造来着,但是想想,最终如果要改造成一个 Web 版的 Terminal,这个肯定已经有开源实现了。
于是我就开始搜,最后搜到几个还不错的。
Web Terminal
经过一番试用,我个人首推的还是 ttyd,其他的几个要么是基于 SSH 的,要么不怎么好用或停止维护了。
下面我就来介绍下 ttyd 的简单用法。
安装
安装其实非常简单,我用的是 Mac,所以用 HomeBrew 直接安装即可:
brew install ttyd
如果你用的是 Windows、Linux,依然也可以支持,安装可以参考#installation章节。
使用
ttyd 支持不少功能配置,完整命令如下:
ttyd is a tool for sharing terminal over the web
USAGE:
    ttyd [options]  []
VERSION:
    1.6.3
OPTIONS:
    -p, --port              Port to listen (default: 7681, use `0` for random port)
    -i, --interface         Network interface to bind (eg: eth0), or UNIX domain socket path (eg: /var/run/ttyd.sock)
    -c, --credential        Credential for Basic Authentication (format: username:password)
    -u, --uid               User id to run with
    -g, --gid               Group id to run with
    -s, --signal            Signal to send to the command when exit it (default: 1, SIGHUP)
    -a, --url-arg           Allow client to send command line arguments in URL (eg: http://localhost:7681?arg=foo&arg=bar)
    -R, --readonly          Do not allow clients to write to the TTY
    -t, --client-option     Send option to client (format: key=value), repeat to add more options
    -T, --terminal-type     Terminal type to report, default: xterm-256color
    -O, --check-origin      Do not allow websocket connection from different origin
    -m, --max-clients       Maximum clients to support (default: 0, no limit)
    -o, --once              Accept only one client and exit on disconnection
    -B, --browser           Open terminal with the default system browser
    -I, --index             Custom index.html path
    -b, --base-path         Expected base path for requests coming from a reverse proxy (eg: /mounted/here)
    -P, --ping-interval     Websocket ping interval(sec) (default: 300)
    -6, --ipv6              Enable IPv6 support
    -S, --ssl               Enable SSL
    -C, --ssl-cert          SSL certificate file path
    -K, --ssl-key           SSL key file path
    -A, --ssl-ca            SSL CA file path for client certificate verification
    -d, --debug             Set log level (default: 7)
    -v, --version           Print the version and exit
    -h, --help              Print this text and exit
Visit https://github.com/tsl0922/ttyd to get more information and report bugs.
   
  
  
  
  
 