Comparing version 2.4.0 to 2.4.1
@@ -46,2 +46,3 @@ "use strict"; | ||
this.cursor = Number(!!this.initial); | ||
this.cursorOffset = 0; | ||
this.clear = clear(``, this.out.columns); | ||
@@ -71,2 +72,3 @@ this.render(); | ||
this.cursor = Number(!!this.initial); | ||
this.cursorOffset = 0; | ||
this.fire(); | ||
@@ -111,2 +113,4 @@ this.render(); | ||
_this2.value = _this2.value || _this2.initial; | ||
_this2.cursorOffset = 0; | ||
_this2.cursor = _this2.rendered.length; | ||
yield _this2.validate(); | ||
@@ -148,2 +152,3 @@ | ||
this.cursor = this.cursor + n; | ||
this.cursorOffset += n; | ||
} | ||
@@ -161,3 +166,3 @@ | ||
delete() { | ||
if (this.cursor === 0) return this.bell(); | ||
if (this.isCursorAtStart()) return this.bell(); | ||
let s1 = this.value.slice(0, this.cursor - 1); | ||
@@ -167,3 +172,10 @@ let s2 = this.value.slice(this.cursor); | ||
this.red = false; | ||
this.moveCursor(-1); | ||
if (this.isCursorAtStart()) { | ||
this.cursorOffset = 0; | ||
} else { | ||
this.cursorOffset++; | ||
this.moveCursor(-1); | ||
} | ||
this.render(); | ||
@@ -178,2 +190,9 @@ } | ||
this.red = false; | ||
if (this.isCursorAtEnd()) { | ||
this.cursorOffset = 0; | ||
} else { | ||
this.cursorOffset++; | ||
} | ||
this.render(); | ||
@@ -204,2 +223,10 @@ } | ||
isCursorAtStart() { | ||
return this.cursor === 0 || this.placeholder && this.cursor === 1; | ||
} | ||
isCursorAtEnd() { | ||
return this.cursor === this.rendered.length || this.placeholder && this.cursor === this.rendered.length + 1; | ||
} | ||
render() { | ||
@@ -221,3 +248,3 @@ if (this.closed) return; | ||
this.out.write(erase.line + cursor.to(0) + this.outputText + cursor.save + this.outputError + cursor.restore); | ||
this.out.write(erase.line + cursor.to(0) + this.outputText + cursor.save + this.outputError + cursor.restore + cursor.move(this.cursorOffset, 0)); | ||
} | ||
@@ -224,0 +251,0 @@ |
@@ -28,2 +28,3 @@ const color = require('kleur'); | ||
this.cursor = Number(!!this.initial); | ||
this.cursorOffset = 0; | ||
this.clear = clear(``, this.out.columns); | ||
@@ -52,2 +53,3 @@ this.render(); | ||
this.cursor = Number(!!this.initial); | ||
this.cursorOffset = 0; | ||
this.fire(); | ||
@@ -83,2 +85,4 @@ this.render(); | ||
this.value = this.value || this.initial; | ||
this.cursorOffset = 0; | ||
this.cursor = this.rendered.length; | ||
await this.validate(); | ||
@@ -110,2 +114,3 @@ if (this.error) { | ||
this.cursor = this.cursor+n; | ||
this.cursorOffset += n; | ||
} | ||
@@ -123,3 +128,3 @@ | ||
delete() { | ||
if (this.cursor === 0) return this.bell(); | ||
if (this.isCursorAtStart()) return this.bell(); | ||
let s1 = this.value.slice(0, this.cursor-1); | ||
@@ -129,3 +134,8 @@ let s2 = this.value.slice(this.cursor); | ||
this.red = false; | ||
this.moveCursor(-1); | ||
if (this.isCursorAtStart()) { | ||
this.cursorOffset = 0 | ||
} else { | ||
this.cursorOffset++; | ||
this.moveCursor(-1); | ||
} | ||
this.render(); | ||
@@ -140,2 +150,7 @@ } | ||
this.red = false; | ||
if (this.isCursorAtEnd()) { | ||
this.cursorOffset = 0; | ||
} else { | ||
this.cursorOffset++; | ||
} | ||
this.render(); | ||
@@ -166,2 +181,10 @@ } | ||
isCursorAtStart() { | ||
return this.cursor === 0 || (this.placeholder && this.cursor === 1); | ||
} | ||
isCursorAtEnd() { | ||
return this.cursor === this.rendered.length || (this.placeholder && this.cursor === this.rendered.length + 1) | ||
} | ||
render() { | ||
@@ -189,6 +212,6 @@ if (this.closed) return; | ||
this.out.write(erase.line + cursor.to(0) + this.outputText + cursor.save + this.outputError + cursor.restore); | ||
this.out.write(erase.line + cursor.to(0) + this.outputText + cursor.save + this.outputError + cursor.restore + cursor.move(this.cursorOffset, 0)); | ||
} | ||
} | ||
module.exports = TextPrompt; | ||
module.exports = TextPrompt; |
{ | ||
"name": "prompts", | ||
"version": "2.4.0", | ||
"version": "2.4.1", | ||
"description": "Lightweight, beautiful and user-friendly prompts", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
186703
4617