UNPKG

file-prompt

Version:

An interactive prompt for selecting files from a directory.

1 lines 1.61 kB
"use strict";function _interopRequireDefault(t){return t&&t.__esModule?t:{"default":t}}function _typeof(t){return t&&"undefined"!=typeof Symbol&&t.constructor===Symbol?"symbol":typeof t}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}();Object.defineProperty(exports,"__esModule",{value:!0});var _chalk=require("chalk"),_chalk2=_interopRequireDefault(_chalk),_stdin_reader=require("./streams/stdin_reader"),_stdin_reader2=_interopRequireDefault(_stdin_reader),Prompt=function(){function t(e){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];_classCallCheck(this,t),this.text="",this.options={stdin:process.stdin,stdout:process.stdout},e&&"string"==typeof e&&(this.text=e),"object"===("undefined"==typeof e?"undefined":_typeof(e))&&(n=e,e=null),n&&(this.options=Object.assign(this.options,n))}return _createClass(t,[{key:"beckon",value:function(t){return t&&(this.text=t),this.options.stdin.setEncoding("utf8"),this.options.stdout.write(this.formatText()+this.formatPrompt()),new _stdin_reader2["default"](this.options)}},{key:"close",value:function(){this.options.stdin.end()}},{key:"formatPrompt",value:function(){return _chalk2["default"].magenta.bold(" > ")}},{key:"formatText",value:function(){return _chalk2["default"].blue.bold(this.text)}}]),t}();exports["default"]=Prompt;