4
4
ArrayPrototypeJoin,
5
5
ArrayPrototypePush,
6
6
Promise,
7
- PromiseResolve,
8
7
} = primordials ;
9
8
10
9
const { CSI } = require ( 'internal/readline/utils' ) ;
@@ -38,6 +37,7 @@ class Readline {
38
37
* Moves the cursor to the x and y coordinate on the given stream.
39
38
* @param {integer } x
40
39
* @param {integer } [y]
40
+ * @returns {Readline } this
41
41
*/
42
42
cursorTo ( x , y = undefined ) {
43
43
validateInteger ( x , 'x' ) ;
@@ -54,6 +54,7 @@ class Readline {
54
54
* Moves the cursor relative to its current location.
55
55
* @param {integer } dx
56
56
* @param {integer } dy
57
+ * @returns {Readline } this
57
58
*/
58
59
moveCursor ( dx , dy ) {
59
60
if ( dx || dy ) {
@@ -80,10 +81,12 @@ class Readline {
80
81
}
81
82
82
83
/**
83
- * Clears the current line the cursor is on:
84
+ * Clears the current line the cursor is on.
85
+ * @param {-1|0|1 } dir Direction to clear:
84
86
* -1 for left of the cursor
85
87
* +1 for right of the cursor
86
88
* 0 for the entire line
89
+ * @returns {Readline } this
87
90
*/
88
91
clearLine ( dir ) {
89
92
validateInteger ( dir , 'dir' , - 1 , 1 ) ;
@@ -99,6 +102,7 @@ class Readline {
99
102
100
103
/**
101
104
* Clears the screen from the current position of the cursor down.
105
+ * @returns {Readline } this
102
106
*/
103
107
clearScreenDown ( ) {
104
108
if ( this . #autoCommit) {
@@ -109,15 +113,27 @@ class Readline {
109
113
return this ;
110
114
}
111
115
116
+ /**
117
+ * Sends all the pending actions to the associated `stream` and clears the
118
+ * internal list of pending actions.
119
+ * @returns {Promise<void> } Resolves when all pending actions have been
120
+ * flushed to the associated `stream`.
121
+ */
112
122
commit ( ) {
113
123
return new Promise ( ( resolve ) => {
114
124
this . #stream. write ( ArrayPrototypeJoin ( this . #todo, '' ) , resolve ) ;
115
125
this . #todo = [ ] ;
116
126
} ) ;
117
127
}
128
+
129
+ /**
130
+ * Clears the internal list of pending actions without sending it to the
131
+ * associated `stream`.
132
+ * @returns {Readline } this
133
+ */
118
134
rollback ( ) {
119
135
this . #todo = [ ] ;
120
- return PromiseResolve ( ) ;
136
+ return this ;
121
137
}
122
138
}
123
139
0 commit comments