| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2383501 commit ffaa114
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -283,6 +283,15 @@ added: v0.1.98 | |||
| 283 | 283 | The `rl.setPrompt()` method sets the prompt that will be written to `output` | |
| 284 | 284 | whenever `rl.prompt()` is called. | |
| 285 | 285 | ||
| 286 | + ### `rl.getPrompt()` | ||
| 287 | + <!-- YAML | ||
| 288 | + added: REPLACEME | ||
| 289 | + --> | ||
| 290 | + | ||
| 291 | + * Returns: {string} the current prompt string | ||
| 292 | + | ||
| 293 | + The `rl.getPrompt()` method returns the current prompt used by `rl.prompt()`. | ||
| 294 | + | ||
| 286 | 295 | ### `rl.write(data[, key])` | |
| 287 | 296 | <!-- YAML | |
| 288 | 297 | added: v0.1.98 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -144,7 +144,7 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) { | |||
| 144 | 144 | let escaped = null; | |
| 145 | 145 | ||
| 146 | 146 | function getPreviewPos() { | |
| 147 | - const displayPos = repl._getDisplayPos(`${repl._prompt}${repl.line}`); | ||
| 147 | + const displayPos = repl._getDisplayPos(`${repl.getPrompt()}${repl.line}`); | ||
| 148 | 148 | const cursorPos = repl.line.length !== repl.cursor ? | |
| 149 | 149 | repl.getCursorPos() : | |
| 150 | 150 | displayPos; | |
@@ -177,7 +177,7 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) { | |||
| 177 | 177 | rows = pos.displayPos.rows - pos.cursorPos.rows; | |
| 178 | 178 | moveCursor(repl.output, 0, rows); | |
| 179 | 179 | } | |
| 180 | - const totalLine = `${repl._prompt}${repl.line}${completionPreview}`; | ||
| 180 | + const totalLine = `${repl.getPrompt()}${repl.line}${completionPreview}`; | ||
| 181 | 181 | const newPos = repl._getDisplayPos(totalLine); | |
| 182 | 182 | // Minimize work for the terminal. It is enough to clear the right part of | |
| 183 | 183 | // the current line in case the preview is visible on a single line. | |
@@ -263,7 +263,7 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) { | |||
| 263 | 263 | } | |
| 264 | 264 | repl.output.write(result); | |
| 265 | 265 | cursorTo(repl.output, cursorPos.cols); | |
| 266 | - const totalLine = `${repl._prompt}${repl.line}${suffix}`; | ||
| 266 | + const totalLine = `${repl.getPrompt()}${repl.line}${suffix}`; | ||
| 267 | 267 | const newPos = repl._getDisplayPos(totalLine); | |
| 268 | 268 | const rows = newPos.rows - cursorPos.rows - (newPos.cols === 0 ? 1 : 0); | |
| 269 | 269 | moveCursor(repl.output, 0, -rows); | |
@@ -611,7 +611,7 @@ function setupReverseSearch(repl) { | |||
| 611 | 611 | let rows = 0; | |
| 612 | 612 | if (lastMatch !== -1) { | |
| 613 | 613 | const line = repl.history[lastMatch].slice(0, lastCursor); | |
| 614 | - rows = repl._getDisplayPos(`${repl._prompt}${line}`).rows; | ||
| 614 | + rows = repl._getDisplayPos(`${repl.getPrompt()}${line}`).rows; | ||
| 615 | 615 | cursorTo(repl.output, promptPos.cols); | |
| 616 | 616 | } else if (isInReverseSearch && repl.line !== '') { | |
| 617 | 617 | rows = repl.getCursorPos().rows; | |
@@ -631,7 +631,7 @@ function setupReverseSearch(repl) { | |||
| 631 | 631 | ||
| 632 | 632 | // To know exactly how many rows we have to move the cursor back we need the | |
| 633 | 633 | // cursor rows, the output rows and the input rows. | |
| 634 | - const prompt = repl._prompt; | ||
| 634 | + const prompt = repl.getPrompt(); | ||
| 635 | 635 | const cursorLine = `${prompt}${outputLine.slice(0, cursor)}`; | |
| 636 | 636 | const cursorPos = repl._getDisplayPos(cursorLine); | |
| 637 | 637 | const outputPos = repl._getDisplayPos(`${prompt}${outputLine}`); | |
@@ -682,7 +682,7 @@ function setupReverseSearch(repl) { | |||
| 682 | 682 | if (!isInReverseSearch) { | |
| 683 | 683 | if (key.ctrl && checkAndSetDirectionKey(key.name)) { | |
| 684 | 684 | historyIndex = repl.historyIndex; | |
| 685 | - promptPos = repl._getDisplayPos(`${repl._prompt}`); | ||
| 685 | + promptPos = repl._getDisplayPos(`${repl.getPrompt()}`); | ||
| 686 | 686 | print(repl.line, `${labels[dir]}_`); | |
| 687 | 687 | isInReverseSearch = true; | |
| 688 | 688 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -291,6 +291,11 @@ Interface.prototype.setPrompt = function(prompt) { | |||
| 291 | 291 | }; | |
| 292 | 292 | ||
| 293 | 293 | ||
| 294 | + Interface.prototype.getPrompt = function() { | ||
| 295 | + return this._prompt; | ||
| 296 | + }; | ||
| 297 | + | ||
| 298 | + | ||
| 294 | 299 | Interface.prototype._setRawMode = function(mode) { | |
| 295 | 300 | const wasInRawMode = this.input.isRaw; | |
| 296 | 301 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -898,6 +898,16 @@ for (let i = 0; i < 12; i++) { | |||
| 898 | 898 | }); | |
| 899 | 899 | } | |
| 900 | 900 | ||
| 901 | + // Calling the getPrompt method | ||
| 902 | + { | ||
| 903 | + const expectedPrompts = ['$ ', '> ']; | ||
| 904 | + const [rli] = getInterface({ terminal }); | ||
| 905 | + for (const prompt of expectedPrompts) { | ||
| 906 | + rli.setPrompt(prompt); | ||
| 907 | + assert.strictEqual(rli.getPrompt(), prompt); | ||
| 908 | + } | ||
| 909 | + } | ||
| 910 | + | ||
| 901 | 911 | { | |
| 902 | 912 | const expected = terminal ? | |
| 903 | 913 | ['\u001b[1G', '\u001b[0J', '$ ', '\u001b[3G'] : | |
@@ -920,7 +930,7 @@ for (let i = 0; i < 12; i++) { | |||
| 920 | 930 | ||
| 921 | 931 | rl.prompt(); | |
| 922 | 932 | ||
| 923 | - assert.strictEqual(rl._prompt, '$ '); | ||
| 933 | + assert.strictEqual(rl.getPrompt(), '$ '); | ||
| 924 | 934 | } | |
| 925 | 935 | ||
| 926 | 936 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -120,7 +120,7 @@ assert.throws(r3, { | |||
| 120 | 120 | // 4, Verify that defaults are used when no arguments are provided | |
| 121 | 121 | const r4 = repl.start(); | |
| 122 | 122 | ||
| 123 | - assert.strictEqual(r4._prompt, '> '); | ||
| 123 | + assert.strictEqual(r4.getPrompt(), '> '); | ||
| 124 | 124 | assert.strictEqual(r4.input, process.stdin); | |
| 125 | 125 | assert.strictEqual(r4.output, process.stdout); | |
| 126 | 126 | assert.strictEqual(r4.terminal, !!r4.output.isTTY); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments