Skip to content

Commit af4c564

Browse files
Remove callback option
1 parent 9974b02 commit af4c564

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"printableName": "Cache Web Terminal",
66
"description": "Web-based terminal emulator for Caché administering.",
77
"author": "ZitRo",
8-
"version": "4.5.0",
8+
"version": "4.6.0",
99
"gaID": "UA-83005064-2",
1010
"releaseNumber": 26,
1111
"scripts": {

readme.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@ The next table demonstrates available API. Left column are `terminal` object pro
143143
with one of the terminal mode constants, such as <code>MODE_PROMPT</code>.
144144
</td>
145145
</tr>
146+
<tr>
147+
<td>removeCallback(<b>callback</b>)</td>
148+
<td>
149+
Remove any previously assigned <b>callback</b>. Any function which accepts callback
150+
returns it, and you can pass the callback here once you no longer need it to stop it
151+
from firing.
152+
</td>
153+
</tr>
146154
<tr>
147155
<td>print(<b>text</b>)</td>
148156
<td>

src/client/js/index.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,36 @@ Terminal.prototype.execute = function (command, options, callback) {
162162
bufferOutput: +(typeof callback === "function")
163163
});
164164
if (typeof callback === "function") {
165-
executeCallback = callback;
165+
return executeCallback = callback;
166166
}
167167
};
168168

169+
/**
170+
* Remove previously assigned callback.
171+
* @param {function} callback
172+
* @returns {boolean} - If callback was removed.
173+
*/
174+
Terminal.prototype.removeCallback = function (callback) {
175+
let i,
176+
deleted = false;
177+
if ((i = userInputHandlers.indexOf(callback)) !== -1) {
178+
userInputHandlers.splice(i, 1);
179+
return true;
180+
}
181+
if (typeof executeCallback === "function") {
182+
executeCallback = null;
183+
return true;
184+
}
185+
for (i = 0; i < outputHandlers.length; ++i) {
186+
if (outputHandlers[i].callback !== callback)
187+
continue;
188+
outputHandlers.splice(i, 1);
189+
--i;
190+
deleted = true;
191+
}
192+
return deleted;
193+
};
194+
169195
export function promptCallback (data) {
170196
if (typeof executeCallback === "function") {
171197
executeCallback([ data ]);

0 commit comments

Comments
 (0)