cliui命令行工具 - 模具行业软件开发参考——模具行业从业者必备知识手册
-
<h2>cliui</h2>
<p>!<a href="upload://cKQ68nDVtRFf8SzbSFWsrlA99IO.svg">cliui命令行工具 - 模具行业软件开发参考</a></p>
<p><a href="upload://sqAcau9485c9sUQUtGlsn5HxPiO.svg"><img src="https://www.npmjs.com/package/cliui" alt="NPM version</a>"></p>
<p><a href="upload://Vr7nfdL10iISSygdp04NZo87Wx.svg"><img src="https://conventionalcommits.org" alt="Conventional Commits</a>"></p>
<p>!<a href="upload://9dbJJzFss7MHNlBoCCNmLDGGETp.svg">nycrc config on GitHub</a></p><p>easily create complex multi-column command-line-interfaces.</p>
<h3>Example</h3>
<pre><code>
const ui = require('cliui')()ui.div('Usage: $0 [command] [options]')
ui.div({
text: 'Options:',
padding: [2, 0, 1, 0]
})ui.div(
{
text: "-f, --file",
width: 20,
padding: [0, 4, 0, 4]
},
{
text: "the file to load." +
chalk.green("(if this description is long it wraps).")
,
width: 20
},
{
text: chalk.red("[required]"),
align: 'right'
}
)console.log(ui.toString())
</code></pre><h3>Deno/ESM Support</h3>
<p>As of <code>v7</code> <code>cliui</code> supports <a href="https://github.com/denoland/deno">Deno</a> and</p>
<p><a href="https://nodejs.org/api/esm.html#esm_ecmascript_modules">ESM</a>:</p><pre><code>
import cliui from "https://deno.land/x/cliui/deno.ts";const ui = cliui({})
ui.div('Usage: $0 [command] [options]')
ui.div({
text: 'Options:',
padding: [2, 0, 1, 0]
})ui.div({
text: "-f, --file",
width: 20,
padding: [0, 4, 0, 4]
})console.log(ui.toString())
</code></pre><p><img width="500" src="screenshot.png"></p>
<h3>Layout DSL</h3>
<p>cliui exposes a simple layout DSL:</p>
<p>If you create a single <code>ui.div</code>, passing a string rather than an</p>
<p>object:</p><ul>
<li><code>\n</code>: characters will be interpreted as new rows.</li>
<li><code>\t</code>: characters will be interpreted as new columns.</li>
<li><code>\s</code>: characters will be interpreted as padding.</li>
</ul><p><strong>as an example...</strong></p>
<pre><code>
var ui = require('./')({
width: 60
})ui.div(
'Usage: node ./bin/foo.js\n' +
' <regex>\t provide a regex\n' +
' <glob>\t provide a glob\t [required]'
)console.log(ui.toString())
</code></pre><p><strong>will output:</strong></p>
<pre><code>
Usage: node ./bin/foo.js
<regex> provide a regex
<glob> provide a glob [required]
</code></pre><h3>Methods</h3>
<pre><code>
cliui = require('cliui')
</code></pre><h4>cliui({width: integer})</h4>
<p>Specify the maximum width of the UI being generated.</p>
<p>If no width is provided, cliui will try to get the current window's width and use it, and if that doesn't work, width will be set to <code>80</code>.</p><h4>cliui({wrap: boolean})</h4>
<p>Enable or disable the wrapping of text in a column.</p>
<h4>cliui.div(column, column, column)</h4>
<p>Create a row with any number of columns, a column</p>
<p>can either be a string, or an object with the following</p>
<p>options:</p><ul>
<li><strong>text:</strong> some text to place in the column.</li>
<li><strong>width:</strong> the width of a column.</li>
<li><strong>align:</strong> alignment, <code>right</code> or <code>center</code>.</li>
<li><strong>padding:</strong> <code>[top, right, bottom, left]</code>.</li>
<li><strong>border:</strong> should a border be placed around the div?</li>
</ul><h4>cliui.span(column, column, column)</h4>
<p>Similar to <code>div</code>, except the next row will be appended without</p>
<p>a new line being created.</p><h4>cliui.resetOutput()</h4>
<p>Resets the UI elements of the current cliui instance, maintaining the values</p>
<p>set for <code>width</code> and <code>wrap</code>.</p><hr>
<p>本文由模极社发布</p>
<hr>
<h4>
相关标准参考</h4>
<ul>
<li>GB/T 12555 塑料注射模模架</li>
</ul><hr>
<h4>
你可能还感兴趣</h4>
<ul>
<li><a href="/t/3869/3869">手动发布63篇内容操作步骤</a></li>
<li><a href="/t/4382/4382">unimport</a></li>
<li><a href="/t/4278/4278">Security Policies and Procedures</a></li>
</ul><hr>
<p><strong>相关推荐:</strong></p>
<ul>
<li><a href="https://www.mj7.cn/t/4836-4836">北京模具产业 — 科技研发驱动型模具基地</a></li>
<li><a href="https://www.mj7.cn/t/4835-4835">上海模具产业 — 高端精密模具研发中心</a></li>
<li><a href="https://www.mj7.cn/t/4834-4834">产业集群与模具产业发展的关系</a></li>
</ul><hr>
<p>各位师傅觉得这个方案怎么样?有更好的做法吗?</p>