Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6a8bd8f

Browse filesBrowse files
committed
removed activation/deactivation keyhandling and made an external concern
1 parent 129b4bf commit 6a8bd8f
Copy full SHA for 6a8bd8f

File tree

Expand file treeCollapse file tree

5 files changed

+55
-68
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+55
-68
lines changed

‎README.md

Copy file name to clipboardExpand all lines: README.md
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,12 @@ In the below `C-x` refers to the `Ctrl-x` keystroke, while `M-x` refers to the `
9494
<dd>refresh line (clear screen in shell)</dd>
9595
<dt><code>Tab</code></dt>
9696
<dd>Invoke completion handler for text under cursor</dd>
97-
<dt><code>C-c</code> or <code>Esc</code></dt>
98-
<dd>Deactivate Readline (closes the shell)</dd>
99-
<dt><code>~</code></dt>
100-
<dd>Activate Readline (opens the shell)</dd>
97+
<dt><code>Esc</code> in reverse search</dt>
98+
<dd>Cancel search</dd>
99+
<dt><code>C-c</code></dt>
100+
<dd>call <code>onCancel</code> handler</dd>
101+
<dt><code>C-d</code> on empty line</dt>
102+
<dd>call <code>onCancel</code> handler</dd>
101103
</dl>
102104

103105
### shell.js

‎index.html

Copy file name to clipboardExpand all lines: index.html
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
<!doctype html>
12
<html>
23
<head>
34
<meta charset="utf-8">
45
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
56
<title>Shell testbed</title>
67

78
<link href='http://fonts.googleapis.com/css?family=Source+Code+Pro' rel='stylesheet' type='text/css'>
8-
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
9+
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css">
10+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
11+
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
912
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.2/underscore-min.js"></script>
1013
<script>Josh = {Debug: true };</script>
1114
<script src="js/history.js"></script>
@@ -41,5 +44,6 @@
4144
<div>
4245
<p>Press <strong>~</strong> to activate console.</p>
4346
</div>
47+
4448
</body>
4549
</html>

‎js/example.js

Copy file name to clipboardExpand all lines: js/example.js
+24-11Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -166,24 +166,37 @@
166166
};
167167

168168
$(document).ready(function() {
169-
var consolePanel = $('#shell-panel');
170-
169+
$(document).keypress(function(event) {
170+
if(shell.isActive()) {
171+
return;
172+
}
173+
_console.log("activating shell");
174+
if(event.keyCode == 126) {
175+
event.preventDefault();
176+
shell.activate();
177+
showConsole();
178+
}
179+
});
180+
var $consolePanel = $('#shell-panel');
181+
$consolePanel.resizable({ handles: "s"});
171182
function showConsole() {
172-
consolePanel.slideDown();
173-
consolePanel.focus();
183+
$consolePanel.slideDown();
184+
$consolePanel.focus();
174185
}
175186

176187
function hideConsole() {
177-
consolePanel.slideUp();
178-
consolePanel.blur();
188+
$consolePanel.slideUp();
189+
$consolePanel.blur();
179190
}
180191

181-
shell.onActivate(function() {
182-
showConsole();
183-
});
184-
shell.onDeactivate(function() {
192+
function hideAndDeactivate() {
193+
_console.log("deactivating shell")
194+
shell.deactivate();
185195
hideConsole();
186-
});
196+
}
197+
198+
shell.onEOT(hideAndDeactivate);
199+
shell.onCancel(hideAndDeactivate);
187200
});
188201
Josh.Instance = {
189202
Tree: root,

‎js/readline.js

Copy file name to clipboardExpand all lines: js/readline.js
+11-50Lines changed: 11 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*-------------------------------------------------------------------------*/
1616

1717
var Josh = Josh || {};
18+
Josh.Version = "0.2.5";
1819
(function(root) {
1920
var SPECIAL = {
2021
8: 'BACKSPACE',
@@ -45,15 +46,13 @@ var Josh = Josh || {};
4546
}
4647
});
4748
var _history = config.history || new Josh.History();
48-
var _activationKey = config.activationKey || { keyCode: 192, shiftKey: true }; // ~
4949
var _deactivationKey = config.deactivationKey || { keyCode: 27 }; // Esc
5050
var _killring = config.killring || new Josh.KillRing();
5151
var _active = false;
5252
var _onActivate;
5353
var _onDeactivate;
5454
var _onCompletion;
5555
var _onEnter;
56-
var _onKeydown;
5756
var _onChange;
5857
var _onCancel;
5958
var _onEOT;
@@ -73,6 +72,9 @@ var Josh = Josh || {};
7372

7473
// public methods
7574
var self = {
75+
isActive: function() {
76+
return _active;
77+
},
7678
activate: function() {
7779
_active = true;
7880
if(_onActivate) {
@@ -91,9 +93,6 @@ var Josh = Josh || {};
9193
onDeactivate: function(completionHandler) {
9294
_onDeactivate = completionHandler;
9395
},
94-
onKeydown: function(keydownHandler) {
95-
_onKeydown = keydownHandler;
96-
},
9796
onChange: function(changeHandler) {
9897
_onChange = changeHandler;
9998
},
@@ -155,7 +154,7 @@ var Josh = Josh || {};
155154
_console.log('calling: ' + cmd.name + ', previous: ' + _lastCmd);
156155
if(_inSearch && cmd.name != "cmdKeyPress" && cmd.name != "cmdReverseSearch") {
157156
_inSearch = false;
158-
if(cmd.name == 'cmdCancelSearch') {
157+
if(cmd.name == 'cmdEsc') {
159158
_searchMatch = null;
160159
}
161160
if(_searchMatch) {
@@ -192,8 +191,8 @@ var Josh = Josh || {};
192191
resume();
193192
}
194193

195-
function cmdCancelSearch() {
196-
// do nothing.. action for this was already taken in call()
194+
function cmdEsc() {
195+
// no-op, only has an effect on reverse search and that action was taken in call()
197196
}
198197

199198
function cmdBackspace() {
@@ -333,10 +332,7 @@ var Josh = Josh || {};
333332

334333
function cmdKillWordForward() {
335334
if(_text.length == 0) {
336-
if(_onEOT) {
337-
_onEOT();
338-
return;
339-
}
335+
return;
340336
}
341337
if(_cursor == _text.length) {
342338
return;
@@ -451,13 +447,6 @@ var Josh = Josh || {};
451447
updateCursor(_text.length);
452448
}
453449

454-
function checkKeyMatch(a, b) {
455-
return a.keyCode == b.keyCode
456-
&& Boolean(a.shiftKey) == Boolean(b.shiftKey)
457-
&& Boolean(a.ctrlKey) == Boolean(b.ctrlKey)
458-
&& Boolean(a.altKey) == Boolean(b.altKey);
459-
}
460-
461450
function findBeginningOfPreviousWord() {
462451
var position = _cursor - 1;
463452
if(position < 0) {
@@ -534,12 +523,6 @@ var Josh = Josh || {};
534523
root.onkeydown = function(e) {
535524
e = e || window.event;
536525

537-
// check if the keypress is an the activation key
538-
if(!_active && checkKeyMatch(e, _activationKey)) {
539-
self.activate();
540-
return false;
541-
}
542-
543526
// return as unhandled if we're not active or the key is just a modifier key
544527
if(!_active || e.keyCode == 16 || e.keyCode == 17 || e.keyCode == 18 || e.keyCode == 91) {
545528
return true;
@@ -556,11 +539,7 @@ var Josh = Josh || {};
556539
queue(cmdDone);
557540
break;
558541
case 27: // Esc
559-
if(_inSearch) {
560-
queue(cmdCancelSearch);
561-
} else {
562-
handled = false;
563-
}
542+
queue(cmdEsc);
564543
break;
565544
case 33: // Page Up
566545
queue(cmdHistoryTop);
@@ -681,7 +660,7 @@ var Josh = Josh || {};
681660
queue(cmdRotate);
682661
handled = true;
683662
break;
684-
}
663+
}
685664
} else {
686665

687666
// check for some more special keys without Ctrl or Alt
@@ -693,22 +672,7 @@ var Josh = Josh || {};
693672
}
694673
}
695674
if(!handled) {
696-
if(!checkKeyMatch(e, _deactivationKey)) {
697-
return true;
698-
}
699-
self.deactivate();
700-
} else {
701-
var info = getKeyInfo(e);
702-
if(_onKeydown) {
703-
_onKeydown({
704-
code: e.keyCode,
705-
shift: e.shiftKey,
706-
control: e.controlKey,
707-
alt: e.altKey,
708-
name: SPECIAL[e.keyCode],
709-
isChar: false
710-
});
711-
}
675+
return true;
712676
}
713677
e.preventDefault();
714678
e.stopPropagation();
@@ -729,9 +693,6 @@ var Josh = Josh || {};
729693
} else {
730694
addText(key.character);
731695
}
732-
if(_onKeydown) {
733-
_onKeydown(key);
734-
}
735696
});
736697
e.preventDefault();
737698
e.stopPropagation();

‎js/shell.js

Copy file name to clipboardExpand all lines: js/shell.js
+9-2Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ var Josh = Josh || {};
9797
// public methods
9898
var self = {
9999
commands: commands,
100+
isActive: function() {
101+
return _readline.isActive();
102+
},
100103
activate: function() {
101104
if($(_shell_view_id).length == 0) {
102105
_active = false;
@@ -122,6 +125,12 @@ var Josh = Josh || {};
122125
}
123126
self.refresh();
124127
},
128+
onEOT: function(completionHandler) {
129+
_readline.onEOT(completionHandler);
130+
},
131+
onCancel: function(completionHandler) {
132+
_readline.onCancel(completionHandler);
133+
},
125134
onInitialize: function(completionHandler) {
126135
_initializationHandler = completionHandler;
127136
},
@@ -379,8 +388,6 @@ var Josh = Josh || {};
379388
return callback(match.completion);
380389
});
381390
});
382-
_readline.onEOT(self.deactivate);
383-
_readline.onCancel(self.deactivate);
384391
return self;
385392
}
386393
})(this, $, _);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.