Compare commits
	
		
			No commits in common. "master" and "v1.0.1" have entirely different histories.
		
	
	
		
	
		
							
								
								
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -1,3 +0,0 @@ | |||||||
| node_modules |  | ||||||
| npm*.log |  | ||||||
| .*.sw* |  | ||||||
| @ -1,4 +0,0 @@ | |||||||
| v1.0.4 Handle cli forms in node.js |  | ||||||
|   * prompt user for input |  | ||||||
|   * async validation (email, url, etc) |  | ||||||
|   * status messages |  | ||||||
							
								
								
									
										41
									
								
								LICENSE
									
									
									
									
									
								
							
							
						
						
									
										41
									
								
								LICENSE
									
									
									
									
									
								
							| @ -1,41 +0,0 @@ | |||||||
| Copyright 2017 AJ ONeal |  | ||||||
| 
 |  | ||||||
| This is open source software; you can redistribute it and/or modify it under the |  | ||||||
| terms of either: |  | ||||||
| 
 |  | ||||||
|    a) the "MIT License" |  | ||||||
|    b) the "Apache-2.0 License" |  | ||||||
| 
 |  | ||||||
| MIT License |  | ||||||
| 
 |  | ||||||
|    Permission is hereby granted, free of charge, to any person obtaining a copy |  | ||||||
|    of this software and associated documentation files (the "Software"), to deal |  | ||||||
|    in the Software without restriction, including without limitation the rights |  | ||||||
|    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |  | ||||||
|    copies of the Software, and to permit persons to whom the Software is |  | ||||||
|    furnished to do so, subject to the following conditions: |  | ||||||
| 
 |  | ||||||
|    The above copyright notice and this permission notice shall be included in all |  | ||||||
|    copies or substantial portions of the Software. |  | ||||||
| 
 |  | ||||||
|    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |  | ||||||
|    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |  | ||||||
|    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |  | ||||||
|    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |  | ||||||
|    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |  | ||||||
|    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |  | ||||||
|    SOFTWARE. |  | ||||||
| 
 |  | ||||||
| Apache-2.0 License Summary |  | ||||||
| 
 |  | ||||||
|    Licensed under the Apache License, Version 2.0 (the "License"); |  | ||||||
|    you may not use this file except in compliance with the License. |  | ||||||
|    You may obtain a copy of the License at |  | ||||||
| 
 |  | ||||||
|      http://www.apache.org/licenses/LICENSE-2.0 |  | ||||||
| 
 |  | ||||||
|    Unless required by applicable law or agreed to in writing, software |  | ||||||
|    distributed under the License is distributed on an "AS IS" BASIS, |  | ||||||
|    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |  | ||||||
|    See the License for the specific language governing permissions and |  | ||||||
|    limitations under the License. |  | ||||||
							
								
								
									
										61
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										61
									
								
								index.js
									
									
									
									
									
								
							| @ -37,7 +37,6 @@ var form = { | |||||||
|     , _prompt: '' |     , _prompt: '' | ||||||
|     , _input: [] |     , _input: [] | ||||||
|     , _inputIndex: 0 |     , _inputIndex: 0 | ||||||
|     , isTTY: rws.isTTY |  | ||||||
|     , cursorTo: function (x, y) { |     , cursorTo: function (x, y) { | ||||||
|         if ('number' !== typeof x || (0 !== x && !x)) { |         if ('number' !== typeof x || (0 !== x && !x)) { | ||||||
|           throw new Error('cursorTo(x[, y]): x is not optional and must be a number'); |           throw new Error('cursorTo(x[, y]): x is not optional and must be a number'); | ||||||
| @ -170,6 +169,15 @@ var form = { | |||||||
| 
 | 
 | ||||||
|     return new PromiseA(function (resolve) { |     return new PromiseA(function (resolve) { | ||||||
|       var ch; |       var ch; | ||||||
|  | 
 | ||||||
|  |       rrs.setRawMode(true); | ||||||
|  |       rrs.setEncoding('utf8'); | ||||||
|  |       rrs.resume(); | ||||||
|  | 
 | ||||||
|  |       ws.cursorTo(0); | ||||||
|  |       ws.write(ws._prompt); | ||||||
|  |       //ws.cursorTo(0, ws._prompt.length);
 | ||||||
|  | 
 | ||||||
|       var debouncer = { |       var debouncer = { | ||||||
|         set: function () { |         set: function () { | ||||||
|           if (!(cbs.onDebounceAsync||cbs.onDebounce)) { |           if (!(cbs.onDebounceAsync||cbs.onDebounce)) { | ||||||
| @ -216,12 +224,10 @@ var form = { | |||||||
|         rrs.pause(); |         rrs.pause(); | ||||||
| 
 | 
 | ||||||
|         form.PromiseA.resolve((cbs.onReturnAsync||cbs.onReturn)(rrs, ws, ws._input.join(''), ch)).then(function (normalInput) { |         form.PromiseA.resolve((cbs.onReturnAsync||cbs.onReturn)(rrs, ws, ws._input.join(''), ch)).then(function (normalInput) { | ||||||
|           if (!cbs.value) { |           ws.write('\n'); | ||||||
|             ws.write('\n'); |           ws.clearLine(); // person just hit enter, they are on the next line
 | ||||||
|             ws.clearLine(); // person just hit enter, they are on the next line
 |                           // (and this will clear the status, if any)
 | ||||||
|                             // (and this will clear the status, if any)
 |                           // TODO count lines used below and clear all of them
 | ||||||
|                             // TODO count lines used below and clear all of them
 |  | ||||||
|           } |  | ||||||
|           rrs.setRawMode(false); |           rrs.setRawMode(false); | ||||||
| 
 | 
 | ||||||
|           var input = ws._input.join(''); |           var input = ws._input.join(''); | ||||||
| @ -229,14 +235,11 @@ var form = { | |||||||
|           ws._inputIndex = 0; |           ws._inputIndex = 0; | ||||||
|           resolve({ input: input, result: normalInput }); |           resolve({ input: input, result: normalInput }); | ||||||
|         }, function (err) { |         }, function (err) { | ||||||
|  |           rrs.on('data', onData); | ||||||
|  | 
 | ||||||
|           var errmsg = colors.red(err.message); |           var errmsg = colors.red(err.message); | ||||||
|           form.setStatus(rrs, ws, errmsg); |           form.setStatus(rrs, ws, errmsg); | ||||||
|           if (!rrs.isTTY) { |  | ||||||
|             return PromiseA.reject(err); |  | ||||||
|           } |  | ||||||
| 
 | 
 | ||||||
|           rrs.on('data', onData); |  | ||||||
|           rrs.setRawMode(true); |  | ||||||
|           rrs.resume(); |           rrs.resume(); | ||||||
|         }); |         }); | ||||||
|       } |       } | ||||||
| @ -246,6 +249,8 @@ var form = { | |||||||
|         var x; |         var x; | ||||||
| 
 | 
 | ||||||
|         if (CTRL_C === ch) { |         if (CTRL_C === ch) { | ||||||
|  |           console.log(""); | ||||||
|  |           console.log("received CTRL+C and quit"); | ||||||
|           process.exit(0); |           process.exit(0); | ||||||
|           callback(new Error("cancelled")); |           callback(new Error("cancelled")); | ||||||
|         } |         } | ||||||
| @ -310,26 +315,6 @@ var form = { | |||||||
|         // will come in and we have to figure out what to do about that
 |         // will come in and we have to figure out what to do about that
 | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       if (cbs.value) { |  | ||||||
|         ws._input = require('spliddit')(cbs.value); |  | ||||||
|         ws._inputIndex = ws._input.length; |  | ||||||
|         callback(); |  | ||||||
|         return; |  | ||||||
|       } |  | ||||||
| 
 |  | ||||||
|       if (!rrs.isTTY) { |  | ||||||
|         return PromiseA.reject("User input is required but stdio is not a TTY"); |  | ||||||
|       } |  | ||||||
| 
 |  | ||||||
|       rrs.setRawMode(true); |  | ||||||
|       rrs.setEncoding('utf8'); |  | ||||||
|       rrs.resume(); |  | ||||||
| 
 |  | ||||||
|       if (ws.isTTY) { |  | ||||||
|         ws.cursorTo(0); |  | ||||||
|         ws.write(ws._prompt); |  | ||||||
|         //ws.cursorTo(0, ws._prompt.length);
 |  | ||||||
|       } |  | ||||||
|       rrs.on('data', onData); |       rrs.on('data', onData); | ||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
| @ -341,17 +326,13 @@ var form = { | |||||||
|     // TODO write newline?
 |     // TODO write newline?
 | ||||||
|     //ws.moveCursor(0, 1);
 |     //ws.moveCursor(0, 1);
 | ||||||
|     ws.write('\n'); |     ws.write('\n'); | ||||||
|     if (ws.isTTY) { |     ws.clearLine(); | ||||||
|       ws.clearLine(); |     ws.cursorTo(0); | ||||||
|       ws.cursorTo(0); |  | ||||||
|     } |  | ||||||
|     // write from beginning of line
 |     // write from beginning of line
 | ||||||
|     ws.write(msg); |     ws.write(msg); | ||||||
|     // restore position
 |     // restore position
 | ||||||
|     if (ws.isTTY) { |     ws.cursorTo(x); | ||||||
|       ws.cursorTo(x); |     ws.moveCursor(0, -1); | ||||||
|       ws.moveCursor(0, -1); |  | ||||||
|     } |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
| , println: function (rrs, ws, msg) { | , println: function (rrs, ws, msg) { | ||||||
|  | |||||||
							
								
								
									
										12
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								package.json
									
									
									
									
									
								
							| @ -1,6 +1,6 @@ | |||||||
| { | { | ||||||
|   "name": "terminal-forms.js", |   "name": "terminal-forms.js", | ||||||
|   "version": "1.0.4", |   "version": "1.0.1", | ||||||
|   "description": "A terminal input library for node.js JavaScript", |   "description": "A terminal input library for node.js JavaScript", | ||||||
|   "main": "index.js", |   "main": "index.js", | ||||||
|   "scripts": { |   "scripts": { | ||||||
| @ -8,7 +8,7 @@ | |||||||
|   }, |   }, | ||||||
|   "repository": { |   "repository": { | ||||||
|     "type": "git", |     "type": "git", | ||||||
|     "url": "git@git.oauth3.org:OAuth3/terminal-forms.js.git" |     "url": "git@git.daplie.com:OAuth3/terminal-forms.js.git" | ||||||
|   }, |   }, | ||||||
|   "keywords": [ |   "keywords": [ | ||||||
|     "terminal", |     "terminal", | ||||||
| @ -20,11 +20,5 @@ | |||||||
|     "fields" |     "fields" | ||||||
|   ], |   ], | ||||||
|   "author": "AJ ONeal <aj@daplie.com> (https://daplie.com/)", |   "author": "AJ ONeal <aj@daplie.com> (https://daplie.com/)", | ||||||
|   "license": "(MIT OR Apache-2.0)", |   "license": "(MIT OR Apache-2.0)" | ||||||
|   "dependencies": { |  | ||||||
|     "bluebird": "^3.5.0", |  | ||||||
|     "colors": "^1.1.2", |  | ||||||
|     "spliddit": "^2.1.1", |  | ||||||
|     "strip-ansi": "^3.0.1" |  | ||||||
|   } |  | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user