How to use the moveCursor function from readline

Find comprehensive JavaScript readline.moveCursor code examples handpicked from public code repositorys.

readline.moveCursor is a function in Node.js that moves the cursor on a readline interface a specified number of rows and columns.

1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
f.emitKeypressEvents(t, s), t.isTTY && t.setRawMode(true);
const C2 = (D2, { name: i }) => {
  if (String(D2) === "" && process.exit(0), !F2)
    return;
  let E2 = i === "return" ? 0 : -1, a2 = i === "return" ? -1 : 0;
  f.moveCursor(u2, E2, a2, () => {
    f.clearLine(u2, 1, () => {
      t.once("keypress", C2);
    });
  });
fork icon1
star icon6
watch icon4

+ 3 other calls in file

19
20
21
22
23
24
25
26
27
28
if (editor.last_exit_status !== 0) {
  process.stderr.write("WARN: The editor exited with a non-zero status\n\n")
}

if (response.length === 0) {
  readline.moveCursor(process.stdout, 0, -1);
  process.stdout.write('Your message was empty, please try again. (press enter to launch your preferred editor)');
} else {
  process.stdout.write('Your Message:\n');
  process.stdout.write(response);
fork icon0
star icon0
watch icon0

How does readline.moveCursor work?

readline.moveCursor is a Node.js function that moves the cursor position in the current output stream by a specified number of columns and rows. It does not modify the text currently displayed in the console.

96
97
98
99
100
101
102
103
104
105
106
107
  assert.deepStrictEqual(writable.data, set[2]);
});


// Verify that moveCursor() throws on invalid callback.
assert.throws(() => {
  readline.moveCursor(writable, 1, 1, null);
}, /ERR_INVALID_CALLBACK/);


// Verify that moveCursor() does not throw on null or undefined stream.
assert.strictEqual(readline.moveCursor(null, 1, 1), true);
fork icon0
star icon0
watch icon0

+ 11 other calls in file

29
30
31
32
33
34
35
36
37
38
//     process.stdout.write(prefix + depKey + "\t" + dependencies[key][depKey] + "\n");
//   });
// };

const printDependencies = () => {
  readline.moveCursor(process.stdout, 0, -1000); // 将光标移动到屏幕最上方
  readline.clearScreenDown(process.stdout); // 清除屏幕
  const key = keys[currentKeyIndex];
  console.log(key.toUpperCase() + ":");
  const depKeys = Object.keys(dependencies[key]);
fork icon0
star icon0
watch icon0

+ 3 other calls in file

Ai Example

1
2
3
4
5
6
7
8
9
10
const readline = require("readline");

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});

// Move the cursor up 2 lines and to the left 5 columns
rl.output.write("Hello\nWorld!\n");
readline.moveCursor(rl.output, -5, -2);

In this example, the readline.moveCursor method is used to move the cursor position of the output stream of the readline interface. It is used to move the cursor up 2 lines and to the left 5 columns after writing the strings 'Hello' and 'World!' to the output stream.