GSI - Employe Self Service Mobile
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
2.9 KiB

2 months ago
  1. # cliui
  2. ![ci](https://github.com/yargs/cliui/workflows/ci/badge.svg)
  3. [![NPM version](https://img.shields.io/npm/v/cliui.svg)](https://www.npmjs.com/package/cliui)
  4. [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
  5. ![nycrc config on GitHub](https://img.shields.io/nycrc/yargs/cliui)
  6. easily create complex multi-column command-line-interfaces.
  7. ## Example
  8. ```js
  9. const ui = require('cliui')()
  10. ui.div('Usage: $0 [command] [options]')
  11. ui.div({
  12. text: 'Options:',
  13. padding: [2, 0, 1, 0]
  14. })
  15. ui.div(
  16. {
  17. text: "-f, --file",
  18. width: 20,
  19. padding: [0, 4, 0, 4]
  20. },
  21. {
  22. text: "the file to load." +
  23. chalk.green("(if this description is long it wraps).")
  24. ,
  25. width: 20
  26. },
  27. {
  28. text: chalk.red("[required]"),
  29. align: 'right'
  30. }
  31. )
  32. console.log(ui.toString())
  33. ```
  34. ## Deno/ESM Support
  35. As of `v7` `cliui` supports [Deno](https://github.com/denoland/deno) and
  36. [ESM](https://nodejs.org/api/esm.html#esm_ecmascript_modules):
  37. ```typescript
  38. import cliui from "https://deno.land/x/cliui/deno.ts";
  39. const ui = cliui({})
  40. ui.div('Usage: $0 [command] [options]')
  41. ui.div({
  42. text: 'Options:',
  43. padding: [2, 0, 1, 0]
  44. })
  45. ui.div({
  46. text: "-f, --file",
  47. width: 20,
  48. padding: [0, 4, 0, 4]
  49. })
  50. console.log(ui.toString())
  51. ```
  52. <img width="500" src="screenshot.png">
  53. ## Layout DSL
  54. cliui exposes a simple layout DSL:
  55. If you create a single `ui.div`, passing a string rather than an
  56. object:
  57. * `\n`: characters will be interpreted as new rows.
  58. * `\t`: characters will be interpreted as new columns.
  59. * `\s`: characters will be interpreted as padding.
  60. **as an example...**
  61. ```js
  62. var ui = require('./')({
  63. width: 60
  64. })
  65. ui.div(
  66. 'Usage: node ./bin/foo.js\n' +
  67. ' <regex>\t provide a regex\n' +
  68. ' <glob>\t provide a glob\t [required]'
  69. )
  70. console.log(ui.toString())
  71. ```
  72. **will output:**
  73. ```shell
  74. Usage: node ./bin/foo.js
  75. <regex> provide a regex
  76. <glob> provide a glob [required]
  77. ```
  78. ## Methods
  79. ```js
  80. cliui = require('cliui')
  81. ```
  82. ### cliui({width: integer})
  83. Specify the maximum width of the UI being generated.
  84. 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 `80`.
  85. ### cliui({wrap: boolean})
  86. Enable or disable the wrapping of text in a column.
  87. ### cliui.div(column, column, column)
  88. Create a row with any number of columns, a column
  89. can either be a string, or an object with the following
  90. options:
  91. * **text:** some text to place in the column.
  92. * **width:** the width of a column.
  93. * **align:** alignment, `right` or `center`.
  94. * **padding:** `[top, right, bottom, left]`.
  95. * **border:** should a border be placed around the div?
  96. ### cliui.span(column, column, column)
  97. Similar to `div`, except the next row will be appended without
  98. a new line being created.
  99. ### cliui.resetOutput()
  100. Resets the UI elements of the current cliui instance, maintaining the values
  101. set for `width` and `wrap`.