{"id":13701460,"url":"https://github.com/nathanpeck/clui","last_synced_at":"2025-05-14T13:06:03.738Z","repository":{"id":15740967,"uuid":"18479542","full_name":"nathanpeck/clui","owner":"nathanpeck","description":"Command Line UI toolkit for Node.js","archived":false,"fork":false,"pushed_at":"2020-09-08T16:00:37.000Z","size":79,"stargazers_count":1664,"open_issues_count":7,"forks_count":40,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-05-05T00:45:00.613Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nathanpeck.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-04-06T00:15:44.000Z","updated_at":"2025-04-18T21:40:29.000Z","dependencies_parsed_at":"2022-09-26T20:31:12.285Z","dependency_job_id":null,"html_url":"https://github.com/nathanpeck/clui","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanpeck%2Fclui","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanpeck%2Fclui/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanpeck%2Fclui/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanpeck%2Fclui/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nathanpeck","download_url":"https://codeload.github.com/nathanpeck/clui/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253231318,"owners_count":21875080,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T20:01:39.796Z","updated_at":"2025-05-14T13:06:03.708Z","avatar_url":"https://github.com/nathanpeck.png","language":"JavaScript","readme":"clui\n=============\n\nThis is a Node.js toolkit for quickly building nice looking command line interfaces which can respond to changing terminal sizes. It also includes the following easy to use components:\n\n* Gauges\n* Progress Bars\n* Sparklines\n* Spinners\n\n__Updates__\n\n[Changelog](https://changelogs.md/github/nathanpeck/clui/)\n\n_October 8, 2014_ - Adding Line.contents() for fetching the contents of a line as a string.\n\n_June 2, 2014_ - Fixed a crash caused by inability to locate the required trim helper in the latest version of cli-color. (And locked down the version of the cli-color dependency to stop this from ever happening again.) Also removed lodash as a dependency in favor of vanilla JS, to keep installs faster and smaller than ever.\n\n\u003ca name=\"line-buffer\"\u003e\u003c/a\u003e\n### LineBuffer(options)\n\nCreates an object for buffering a group of text lines and then outputting them. When printing lines using `LineBuffer` it will crop off extra width and height so that the lines will fit into a specific space.\n\n__Options__\n\nThe following options can be passed in on creation of the `LineBuffer`\n\n* `x` - The X location of where to draw the lines in this buffer.\n* `y` - The Y location of where the draw the lines.\n* `width` - How wide the buffer is in columns. Any lines longer than this will be cropped. You can specify either an integer value or `'console'` in order to let the width of the console determine the width of the `LineBuffer`.\n* `height` - How high the buffer is in rows. You can either pass in an integer value or\n  `'console'` to let the height on the console determine the height of the `LineBuffer`.\n* `scroll` - Where the user is scrolled to in the buffer\n\n__Functions__\n\n* `height()` - Return the height of the `LineBuffer`, in case you specified it as `'console'`\n* `width()` - Return the width of the `LineBuffer`, in case you specified it as `'console'`\n* `addLine(Line)` - Put a `Line` object into the `LineBuffer`.\n* `fill()` - If you don't have enough lines in the buffer this will fill the rest of the lines\n   with empty space.\n* `output()` - Draw the `LineBuffer` to screen.\n\n__Example__\n\n```js\nvar CLI = require('clui'),\n    clc = require('cli-color');\n\nvar Line          = CLI.Line,\n    LineBuffer    = CLI.LineBuffer;\n\nvar outputBuffer = new LineBuffer({\n  x: 0,\n  y: 0,\n  width: 'console',\n  height: 'console'\n});\n\nvar message = new Line(outputBuffer)\n  .column('Title Placehole', 20, [clc.green])\n  .fill()\n  .store();\n\nvar blankLine = new Line(outputBuffer)\n  .fill()\n  .store();\n\nvar header = new Line(outputBuffer)\n  .column('Suscipit', 20, [clc.cyan])\n  .column('Voluptatem', 20, [clc.cyan])\n  .column('Nesciunt', 20, [clc.cyan])\n  .column('Laudantium', 11, [clc.cyan])\n  .fill()\n  .store();\n\nvar line;\nfor(var l = 0; l \u003c 20; l++)\n{\n  line = new Line(outputBuffer)\n    .column((Math.random()*100).toFixed(3), 20)\n    .column((Math.random()*100).toFixed(3), 20)\n    .column((Math.random()*100).toFixed(3), 20)\n    .column((Math.random()*100).toFixed(3), 11)\n    .fill()\n    .store();\n}\n\noutputBuffer.output();\n```\n\n\u003ca name=\"line\"\u003e\u003c/a\u003e\n### Line(outputBuffer)\n\nThis chainable object can be used to generate a line of text with columns, padding, and fill. The parameter `outputBuffer` can be provided to save the line of text into a `LineBuffer` object for future outputting, or you can use `LineBuffer.addLine()` to add a `Line` object into a `LineBuffer`.\n\nAlternatively if you do not wish to make use of a `LineBuffer` you can just use `Line.output()` to output the `Line` immediately rather than buffering it.\n\n__Chainable Functions__\n\n* `padding(width)` - Output `width` characters of blank space.\n* `column(text, width, styles)` - Output text within a column of the specified width. If the text is longer than `width` it will be truncated, otherwise extra padding will be added until it is `width` characters long. The `styles` variable is a list of [cli-color](https://github.com/medikoo/cli-color) styles to apply to this column.\n* `fill()` - At the end of a line fill the rest of the columns to the right edge of the\n  terminal with whitespace to erase any content there.\n* `output()` - Print the generated line of text to the console.\n* `contents()` - Return the contents of this line as a string.\n\n__Example__\n\n```js\nvar clui = require('clui'),\n    clc = require('cli-color'),\n    Line = clui.Line;\n\nvar headers = new Line()\n  .padding(2)\n  .column('Column One', 20, [clc.cyan])\n  .column('Column Two', 20, [clc.cyan])\n  .column('Column Three', 20, [clc.cyan])\n  .column('Column Four', 20, [clc.cyan])\n  .fill()\n  .output();\n\nvar line = new Line()\n  .padding(2)\n  .column((Math.random()*100).toFixed(3), 20)\n  .column((Math.random()*100).toFixed(3), 20)\n  .column((Math.random()*100).toFixed(3), 20)\n  .column((Math.random()*100).toFixed(3), 20)\n  .fill()\n  .output();\n```\n\n\u003ca name=\"gauge\"\u003e\u003c/a\u003e\n### Gauge(value, maxValue, gaugeWidth, dangerZone, suffix)\n\n![Picture of two gauges](https://raw.githubusercontent.com/nathanpeck/clui/master/docs/gauges.png)\n\nDraw a basic horizontal gauge to the screen.\n\n__Parameters__\n\n* `value` - The current value of the metric being displayed by this gauge\n* `maxValue` - The highest possible value of the metric being displayed\n* `gaugeWidth` - How many columns wide to draw the gauge\n* `dangerZone` - The point after which the value will be drawn in red because it is too high\n* `suffix` - A value to output after the gauge itself.\n\n__Example__\n\n```js\nvar os   = require('os'),\n    clui = require('clui');\n\nvar Gauge = clui.Gauge;\n\nvar total = os.totalmem();\nvar free = os.freemem();\nvar used = total - free;\nvar human = Math.ceil(used / 1000000) + ' MB';\n\nconsole.log(Gauge(used, total, 20, total * 0.8, human));\n```\n\n\u003ca name=\"sparkline\"\u003e\u003c/a\u003e\n### Sparkline(values, suffix)\n\n![Picture of two sparklines](https://raw.githubusercontent.com/nathanpeck/clui/master/docs/sparklines.png)\n\nA simple command line sparkline that draws a series of values, and highlights the peak for the period. It also automatically outputs the current value and the peak value at the end of the sparkline.\n\n__Parameters__\n\n* `values` - An array of values to go into the sparkline\n* `suffix` - A suffix to use when drawing the current and max values at the end of sparkline\n\n__Example__\n\n```js\nvar Sparkline = require('clui').Sparkline;\nvar reqsPerSec = [10,12,3,7,12,9,23,10,9,19,16,18,12,12];\n\nconsole.log(Sparkline(reqsPerSec, 'reqs/sec'));\n```\n\n\u003ca name=\"progress\"\u003e\u003c/a\u003e\n### Progress(length)\n\n![Picture of a few progress bars](https://raw.githubusercontent.com/nathanpeck/clui/master/docs/progress.png)\n\n__Parameters__\n\n* `length` - The desired length of the progress bar in characters.\n\n__Methods__\n\n* `update(currentValue, maxValue)` - Returns the progress bar min/max content to write to stdout. Allows for dynamic max values.\n* `update(percent)` - Returns the progress bar content as a percentage to write to stdout. `0.0 \u003e value \u003c 1.0`.\n\n__Example__\n\n```js\nvar clui = require('clui');\n\nvar Progress = clui.Progress;\n\nvar thisProgressBar = new Progress(20);\nconsole.log(thisProgressBar.update(10, 30));\n\n// or\n\nvar thisPercentBar = new Progress(20);\nconsole.log(thisPercentBar.update(0.4));\n\n```\n\n\u003ca name=\"spinner\"\u003e\u003c/a\u003e\n### Spinner(statusText)\n\n![Picture of a spinner](https://raw.githubusercontent.com/nathanpeck/clui/master/docs/spinner.gif)\n\n__Parameters__\n\n* `statusText` - The default status text to display while the spinner is spinning.\n* `style` - Array of graphical characters used to draw the spinner. By default,\n  on Windows: ['|', '/', '-', '\\'], on other platforms: ['◜','◠','◝','◞','◡','◟']\n\n__Methods__\n\n* `start()` - Show the spinner on the screen.\n* `message(statusMessage)` - Update the status message that follows the spinner.\n* `stop()` - Erase the spinner from the screen.\n\n*Note: The spinner is slightly different from other Clui controls in that it outputs\ndirectly to the screen, instead of just returning a string that you output yourself.*\n\n__Example__\n\n```js\nvar CLI = require('clui'),\n    Spinner = CLI.Spinner;\n\nvar countdown = new Spinner('Exiting in 10 seconds...  ', ['⣾','⣽','⣻','⢿','⡿','⣟','⣯','⣷']);\n\ncountdown.start();\n\nvar number = 10;\nsetInterval(function () {\n  number--;\n  countdown.message('Exiting in ' + number + ' seconds...  ');\n  if (number === 0) {\n    process.stdout.write('\\n');\n    process.exit(0);\n  }\n}, 1000);\n```\n\nLicense\n=======\n\nCopyright (C) 2014 Nathan Peck (https://github.com/nathanpeck)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n","funding_links":[],"categories":["3. 命令行程序","JavaScript"],"sub_categories":["3.1 开发库"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnathanpeck%2Fclui","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnathanpeck%2Fclui","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnathanpeck%2Fclui/lists"}