file-prompt
Version:
An interactive prompt for selecting files from a directory.
1 lines • 1.98 kB
JavaScript
;function _interopRequireDefault(t){return t&&t.__esModule?t:{"default":t}}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}var _createClass=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}();Object.defineProperty(exports,"__esModule",{value:!0});var _transform_action=require("../transform_action"),_transform_action2=_interopRequireDefault(_transform_action),_stream=require("stream"),StdinReader=function(t){function e(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];_classCallCheck(this,e);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(e).call(this,{objectMode:!0}));return r.listener=null,r.stdin=process.stdin,r.stdout=process.stdout,r.stdin.setEncoding("utf8"),t.stdin&&(r.stdin=t.stdin),t.stdout&&(r.stdout=t.stdout),r}return _inherits(e,t),_createClass(e,[{key:"addListeners",value:function(){var t=this;this.stdin.removeAllListeners("data"),this.stdin.on("data",function(e){t.push(new _transform_action2["default"]({creator:"prompt",type:"string",data:String(e).trim()})),t.stdin.pause(),t.push(null)}),this.listener=!0}},{key:"_read",value:function(){this.listener||this.addListeners(),this.stdin.resume()}}]),e}(_stream.Readable);exports["default"]=StdinReader;