Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit b846fb0

Browse files
committed
add popLine function
1 parent ce4b259 commit b846fb0

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "utty-node",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "An impl of utty for nodejs tty.",
55
"main": "build/index.js",
66
"types": "build/index.d.ts",
@@ -40,7 +40,7 @@
4040
"@types/node": "^17.0.8",
4141
"nodeliketty": "^1.0.2",
4242
"strip-ansi": "^7.0.1",
43-
"utty": "^1.0.0"
43+
"utty": "^1.0.1"
4444
},
4545
"jest": {
4646
"extensionsToTreatAsEsm": [

src/index.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ describe("Test UNodeTty", () => {
2626
lines[4] = "";
2727
expect(fake.lines).toEqual(lines);
2828
});
29+
it("should be able to pop a line correctly",()=>{
30+
t.popLine();
31+
lines.pop();
32+
lines.pop();
33+
lines.push("");
34+
lines.push("");
35+
expect(fake.lines).toEqual(lines);
36+
});
2937
it("should be able to be resized correctly", () => {
3038
let called = false;
3139
let fn = () => {

src/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import UTty from "utty";
22
import stripAnsi from "strip-ansi";
3-
import NodeLikeTty from "nodeliketty";
3+
import NodeLikeTty, { Direction } from "nodeliketty";
44

55
export default class UNodeTty implements UTty {
66
constructor(tty: NodeLikeTty) {
@@ -44,7 +44,7 @@ export default class UNodeTty implements UTty {
4444
if (add) this.nLine += dLine;
4545
}
4646

47-
_clearLine(dir: -1 | 0 | 1 = 0): void {
47+
_clearLine(dir: Direction = 0): void {
4848
this.tty.clearLine(dir);
4949
}
5050

@@ -102,6 +102,12 @@ export default class UNodeTty implements UTty {
102102
this._write(str + "\n", true);
103103
}
104104

105+
popLine():void{
106+
this.nLine--;
107+
this._toNewLine();
108+
this._clearLine();
109+
}
110+
105111
getStrDisplayWidth(str: string): number {
106112
return stripAnsi(str).length;
107113
//return str.length;

0 commit comments

Comments
 (0)