blessed 是一个不错的npm 包,可以帮助我们开发出带有丰富ui界面的cli 应用,类似的有subzero

测试环境准备

  • 项目结构
├── README.md
├── app.js
├── my-program-icon.png
├── package.json
└── yarn.lock
  • package.json 说明

    主要是依赖以及打包npm 的配置

{
"name": "blessed-project",
"version": "1.0.0",
"main": "index.js",
"bin": "app.js",
"license": "MIT",
"dependencies": {
"blessed": "^0.1.81"
},
"scripts": {
"start": "node app",
"build": "pkg ."
},
"pkg": {
"scripts": "app.js"
},
"devDependencies": {
"pkg": "^4.3.4"
}
}
  • app.js

    简单的cli 开发代码,来自官方文档

var blessed = require('blessed');

// Create a screen object.
var screen = blessed.screen({
smartCSR: true
}); screen.title = 'blessed test'; // Create a box perfectly centered horizontally and vertically.
var box = blessed.box({
top: 'center',
left: 'center',
width: '50%',
height: '50%',
content: 'hello blessed {bold}world{/bold}!',
tags: true,
border: {
type: 'line'
},
style: {
fg: 'white',
bg: 'magenta',
border: {
fg: '#f0f0f0'
},
hover: {
bg: 'green'
}
}
}); // Append our box to the screen.
screen.append(box); // Add a png icon to the box
var icon = blessed.image({
parent: box,
top: 0,
left: 0,
type: 'overlay',
width: 'shrink',
height: 'shrink',
file: __dirname + '/my-program-icon.png',
search: false
}); // If our box is clicked, change the content.
box.on('click', function(data) {
box.setContent('{center}Some different {red-fg}content{/red-fg}.{/center}');
screen.render();
}); // If box is focused, handle `enter`/`return` and give us some more content.
box.key('enter', function(ch, key) {
box.setContent('{right}Even different {black-fg}content{/black-fg}.{/right}\n');
box.setLine(1, 'bar');
box.insertLine(1, 'foo');
screen.render();
}); // Quit on Escape, q, or Control-C.
screen.key(['escape', 'q', 'C-c'], function(ch, key) {
return process.exit(0);
}); // Focus our element.
box.focus(); // Render the screen.
screen.render();

运行

  • 直接使用node
node app
or
yarn start
  • 使用二进制文件

    pkg 打包的二进制文件

yarn build
linux && mac
./blessed-project-{linux|mac}
windows
blessed-project-win.exe
  • 效果

说明

使用blessed 我们可以开发出支持丰富界面的cli工具,集成oclif 很更强大,同时也有一个直接可以使用vue react 的插件,这样开发就更简单了

 
 
 
 

使用blessed 开发丰富的cli 应用的更多相关文章

  1. 如何用node开发自己的cli工具

    如何用node开发自己的cli工具 灵感 写这个工具的灵感以及场景源于youtube的一次闲聊 github 地址 blog首发 使用场景 原本我们写博客展示shell,例如:安装运转docker,一 ...

  2. Ink——一款使用React风格开发命令行界面应用(CLI App)的nodejs工具

    Github: https://github.com/vadimdemedes/ink Ink introduction: React for CLIs. Build and test your CL ...

  3. atitit.基于  Commons CLI 的命令行原理与 开发

    atitit.基于  Commons CLI 的命令行原理与 开发 1. 命令行支持的格式有以下几种: 1 2. json化,map化的命令行参数内部表示 1 3. Ati cli 2 4. CLI库 ...

  4. APICloud提供适用于命令行的开发工具,开发更具极客精神!

    APICloud近期大动作不断,上周刚刚支持Atom编辑器,并推出核心开发工具库.本周又为开发者提供了一款超轻便的新开发工具--CLI工具! 操作系统: Mac/Windows/Linux nodej ...

  5. 轻松掌握VS Code开发.Net Core及创建Xunit单元测试

    前言 本篇文章主要还是介绍使用 VS Code 进行.Net Core开发和常用 CLI命令的使用,至于为啥要用VS Code ,因为它是真的是好看又好用 :) ,哈哈,主要还是为了跨平台开发做准备. ...

  6. click python cli 开发包

    python click 包是一个方便的cli 开发包,我们可以用来开发强大的cli 应用 使用venv 进行环境准备,示例代码来自官方 venv 环境准备 python3 -m venv demoa ...

  7. ubuntu 18.04安装clojure工程的cli工具lein

    官网的安装过程https://leiningen.org/#install 是文字描述,并不够lazy. 我仿照code,chrome nodejs的方式,给出下面的命令行安装过程 wget http ...

  8. 使用阿里云cli管理安全组

    相比于python SDK方式,阿里云基于GO SDK开发了一整套CLI工具,可以通过调用RPC API来管理云资源,对编程能力不够的人来说是个福音. 而且,阿里云CLI的文档比SDK的文档更加全面, ...

  9. vorpal 又一个方便的cli 开发包

    vorpal 是一个npm 包,我们可以用来开发专业的cli 程序 简单使用 初始化项目 yarn init -y 添加依赖 yarn add vorpal 简单demo app.js // cons ...

随机推荐

  1. antd-pro1.0使用jest对react组件进行单元测试

    前言 基于React+Ant Design(以下用Antd表示)的项目,在对于自己封装的,或者基于Antd封装的公共组件的自动化测试技术的选型和实践. 背景 随着前端项目越来越大,业务逻辑日益繁杂,协 ...

  2. Oracle HRMS APIs

    Oracle HRMS APIs..... Here I will be sharing all the Oracle HRMS APIs related articles. 参考地址: Oracle ...

  3. spring--boot数据库连接以及class建表

    Spring-Boot  数据库连接以及class建表 提前在pom.xml文件中添加:jpa,mysql资源 <dependency> <groupId>org.spring ...

  4. iOS-UI篇—简单的浏览器查看程序和Tomcat简单实现

    #import "ViewController.h" @interface ViewController () @property (retain, nonatomic) NSAr ...

  5. 使用kubernetes的deployment进行RollingUpdate

    rolling update,可以使得服务近乎无缝地平滑升级,即在不停止对外服务的前提下完成应用的更新. replication controller与deployment的区别 replicatio ...

  6. 062——VUE中vue-router之命名视图的实例

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. linux make virtual memory more efficient three components

    Page Cache This is used to speed up access to images and data on disk. As pages are read into memory ...

  8. download fomat install rootfs script

    download.sh #!/bin/sh # check the network first serverip=$(cat /tmp/serverip) while true; do ping -c ...

  9. 给构造函数(constructor)创建对象(object)

    (来源http://www.cnblogs.com/dongjc/p/5179561.html) javascript是一种“基于prototype的面向对象语言“,与java有非常大的区别,无法通过 ...

  10. git HEAD游离状态问题解决

    最近在迭代一个版本的时候,出现 HEAD detached at xxx 提示,应该是我切换分支的时候,哪里没弄对.   那么可以通过如下办法解决 git checkout 05 # 先checkou ...