| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,10 +33,13 @@ const { | |||
| 33 | 33 | SymbolDispose, | |
| 34 | 34 | } = primordials; | |
| 35 | 35 | ||
| 36 | - const { codes: { | ||
| 37 | - ERR_INVALID_ARG_VALUE, | ||
| 38 | - ERR_USE_AFTER_CLOSE, | ||
| 39 | - } } = require('internal/errors'); | ||
| 36 | + const { | ||
| 37 | + AbortError, | ||
| 38 | + codes: { | ||
| 39 | + ERR_INVALID_ARG_VALUE, | ||
| 40 | + ERR_USE_AFTER_CLOSE, | ||
| 41 | + }, | ||
| 42 | + } = require('internal/errors'); | ||
| 40 | 43 | ||
| 41 | 44 | const { | |
| 42 | 45 | validateAbortSignal, | |
@@ -111,6 +114,7 @@ const kPrompt = Symbol('_prompt'); | |||
| 111 | 114 | const kPushToKillRing = Symbol('_pushToKillRing'); | |
| 112 | 115 | const kPushToUndoStack = Symbol('_pushToUndoStack'); | |
| 113 | 116 | const kQuestionCallback = Symbol('_questionCallback'); | |
| 117 | + const kQuestionReject = Symbol('_questionReject'); | ||
| 114 | 118 | const kRedo = Symbol('_redo'); | |
| 115 | 119 | const kRedoStack = Symbol('_redoStack'); | |
| 116 | 120 | const kRefreshLine = Symbol('_refreshLine'); | |
@@ -1126,6 +1130,7 @@ class Interface extends InterfaceConstructor { | |||
| 1126 | 1130 | } else { | |
| 1127 | 1131 | // This readline instance is finished | |
| 1128 | 1132 | this.close(); | |
| 1133 | + this[kQuestionReject]?.(new AbortError('Aborted with Ctrl+C')); | ||
| 1129 | 1134 | } | |
| 1130 | 1135 | break; | |
| 1131 | 1136 | ||
@@ -1137,6 +1142,7 @@ class Interface extends InterfaceConstructor { | |||
| 1137 | 1142 | if (this.cursor === 0 && this.line.length === 0) { | |
| 1138 | 1143 | // This readline instance is finished | |
| 1139 | 1144 | this.close(); | |
| 1145 | + this[kQuestionReject]?.(new AbortError('Aborted with Ctrl+D')); | ||
| 1140 | 1146 | } else if (this.cursor < this.line.length) { | |
| 1141 | 1147 | this[kDeleteRight](); | |
| 1142 | 1148 | } | |
@@ -1392,6 +1398,7 @@ module.exports = { | |||
| 1392 | 1398 | kQuestion, | |
| 1393 | 1399 | kQuestionCallback, | |
| 1394 | 1400 | kQuestionCancel, | |
| 1401 | + kQuestionReject, | ||
| 1395 | 1402 | kRefreshLine, | |
| 1396 | 1403 | kSawKeyPress, | |
| 1397 | 1404 | kSawReturnAt, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,6 +13,7 @@ const { | |||
| 13 | 13 | Interface: _Interface, | |
| 14 | 14 | kQuestion, | |
| 15 | 15 | kQuestionCancel, | |
| 16 | + kQuestionReject, | ||
| 16 | 17 | } = require('internal/readline/interface'); | |
| 17 | 18 | ||
| 18 | 19 | const { | |
@@ -54,6 +55,8 @@ class Interface extends _Interface { | |||
| 54 | 55 | }; | |
| 55 | 56 | } | |
| 56 | 57 | ||
| 58 | + this[kQuestionReject] = reject; | ||
| 59 | + | ||
| 57 | 60 | this[kQuestion](query, cb); | |
| 58 | 61 | }); | |
| 59 | 62 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -951,6 +951,22 @@ for (let i = 0; i < 12; i++) { | |||
| 951 | 951 | rli.close(); | |
| 952 | 952 | } | |
| 953 | 953 | ||
| 954 | + // Aborting a question with ctrl+C | ||
| 955 | + { | ||
| 956 | + const [rli, fi] = getInterface({ terminal: true }); | ||
| 957 | + assert.rejects(rli.question('hello?'), { name: 'AbortError' }) | ||
| 958 | + .then(common.mustCall()); | ||
| 959 | + fi.emit('keypress', '.', { ctrl: true, name: 'c' }); | ||
| 960 | + } | ||
| 961 | + | ||
| 962 | + // Aborting a question with ctrl+D | ||
| 963 | + { | ||
| 964 | + const [rli, fi] = getInterface({ terminal: true }); | ||
| 965 | + assert.rejects(rli.question('hello?'), { name: 'AbortError' }) | ||
| 966 | + .then(common.mustCall()); | ||
| 967 | + fi.emit('keypress', '.', { ctrl: true, name: 'd' }); | ||
| 968 | + } | ||
| 969 | + | ||
| 954 | 970 | (async () => { | |
| 955 | 971 | const [rli] = getInterface({ terminal }); | |
| 956 | 972 | const signal = AbortSignal.abort('boom'); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments