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 e1844c4

Browse filesBrowse files
committed
Fixes for sdether#1
Squashed commit of the following: commit a1994a2 Author: Arne Claassen <arne@claassen.net> Date: Sun Jan 20 10:25:46 2013 -0800 updated readme commit 6b3a08b Author: Arne Claassen <arne@claassen.net> Date: Sun Jan 20 10:11:55 2013 -0800 killring behavior has landed commit 0dea368 Author: Arne Claassen <arne@claassen.net> Date: Sat Jan 19 00:41:06 2013 -0800 word kills and the beginnings of the killring commit 5732aa7 Author: Arne Claassen <arne@claassen.net> Date: Thu Jan 17 10:16:22 2013 -0800 fixed lack of config default commit c78ac23 Author: Arne Claassen <arne@claassen.net> Date: Mon Jan 14 18:12:15 2013 -0800 - added supported key bindings for readline to README - added hook for C-l so shell clear command can be triggered by it - fixed word forward/back logic to consider only alphanumeric as word chars, and extracted logic for this so it can be used for word deletes commit e6da4f4 Merge: 1d719ab cb674b3 Author: Arne Claassen <arne@claassen.net> Date: Mon Jan 14 10:39:20 2013 -0800 Merge branch 'master' into dev commit 1d719ab Author: Arne Claassen <arne@claassen.net> Date: Mon Jan 14 10:31:40 2013 -0800 more completion work, and discovered some readline handler omissions commit 531ba41 Author: Arne Claassen <arne@claassen.net> Date: Mon Jan 14 10:20:29 2013 -0800 wip on fixing path completions commit a26daf2 Merge: eef5195 34be423 Author: Arne Claassen <arne@claassen.net> Date: Sun Jan 13 15:18:59 2013 -0800 Merge branch 'master' into dev commit eef5195 Author: Arne Claassen <arne@claassen.net> Date: Sun Jan 13 14:41:56 2013 -0800 removed _exec and made _default do it all commit 56c88d5 Author: Arne Claassen <arne@claassen.net> Date: Sun Jan 13 14:15:26 2013 -0800 re-vamping how default/exec handling is done
1 parent cb674b3 commit e1844c4
Copy full SHA for e1844c4

File tree

Expand file treeCollapse file tree

8 files changed

+366
-75
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+366
-75
lines changed

‎.idea/vcs.xml

Copy file name to clipboardExpand all lines: .idea/vcs.xml
+1Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎README.md

Copy file name to clipboardExpand all lines: README.md
+68-7Lines changed: 68 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ http://sdether.github.com/josh.js/
99
* `shell.js` - visual presentation of the shell and command handling
1010
* `pathhandler.js` - provide cd, ls, pwd and path completion toolikit
1111
* `history.js` - localStorage backed command history
12+
* `killring.js` - killring for kill & yank handling in readline
1213

1314
## License
1415
josh.js is licensed under the Apache 2.0 License
@@ -24,25 +25,82 @@ josh.js is licensed under the Apache 2.0 License
2425
* base shell UI should get some basic behaviors
2526
* `more`-like handling for output that exceeds the shell viewport size
2627
* resizing and close chrome
27-
* scrollwheel support
28-
* Readline Issues/Omissions
29-
* Not handling spaces in path completion
30-
* Missing support for Alt-Backspace & Alt-D in readline.js
31-
* ***Word***-commands do not have path separator awareness
28+
* Readline has not been tested with non-ascii.
29+
3230

3331
## Usage
3432

3533
Until documentation is written, refer to `index.html` and `example.js` for a sample implementation of a shell with path completion.
3634

3735
## Components
38-
***josh*** is built from 4 components and can be used in part or in full.
36+
***josh*** is built from 5 components and can be used in part or in full.
3937

4038
### readline.js
4139

42-
`readline.js` has no dependencies on any outside libraries, although it requires either `history.js` or an object implementing the same calls.
40+
`readline.js` has no dependencies on any outside libraries, although it requires either `history.js` and `killring.js` or objects implementing the same calls.
4341

4442
It implements key trapping to bring [GNU Readline](http://cnswww.cns.cwru.edu/php/chet/readline/readline.html) like line editing to the browser. It can be used by itself to bring readline support to custom data entry fields or in conjunction with `shell.js` to create a full console.
4543

44+
#### Line Editing
45+
In the below `C-x` refers to the `Ctrl-x` keystroke, while `M-x` refers to the `Meta-x` which is mapped to `Alt`, `` and `Left Windows`.
46+
47+
<dl>
48+
<dt><em>Movement</em></dt>
49+
<dt><code>C-b</code> or <code>Left Arrow</code></dt>
50+
<dd>Move back one character</dd>
51+
<dt><code>M-b</code> or <code>Right Arrow</code></dt>
52+
<dd>Move back one word</dd>
53+
<dt><code>C-f</code></dt>
54+
<dd>Move forward one character</dd>
55+
<dt><code>M-f</code></dt>
56+
<dd>Move forward one word</dd>
57+
<dt><code>C-a</code> or <code>Home</code></dt>
58+
<dd>Move to the beginning of the line</dd>
59+
<dt><code>C-e</code> or <code>End</code></dt>
60+
<dd>Move to the end of the line</dd>
61+
62+
<br/>
63+
<dt><em>Edit/Kill</em></dt>
64+
<dt><code>Backspace</code></dt>
65+
<dd>Delete one character back</dd>
66+
<dt><code>C-d</code> or <code>Delete</code></dt>
67+
<dd>Delete character under cursor</dd>
68+
<dt><code>C-k</code></dt>
69+
<dd><em>Kill</em> (i.e. put in kill ring) text to the end of the line</dd>
70+
<dt><code>M-Backspace</code></dt>
71+
<dd><em>Kill</em> one word back</dd>
72+
<dt><code>M-d</code></dt>
73+
<dd><em>Kill</em> word under cursor</dd>
74+
<dt><code>C-y</code></dt>
75+
<dd><em>Yank</em> (i.e. pull from kill ring) the most recently <em>killed</em> text</dd>
76+
<dt><code>M-y</code></dt>
77+
<dd>Rotate to the next item in killring and yank it. Must be preceded by <em>yank</em></dd>
78+
79+
<br/>
80+
<dt><em>History</em></dt>
81+
<dt><code>C-r</code></dt>
82+
<dd>Reverse search through history</dd>
83+
<dt><code>C-p</code> or <code>Up Arrow</code></dt>
84+
<dd>Previous entry in history</dd>
85+
<dt><code>C-n</code> or <code>Down Arrow</code></dt>
86+
<dd>Next entry in history</dd>
87+
<dt><code>Page Up</code></dt>
88+
<dd>Top of history</dd>
89+
<dt><code>Page Down</code></dt>
90+
<dd>Bottom of history</dd>
91+
92+
<br/>
93+
<dt><em>Misc</em></dt>
94+
<dt><code>C-l</code></dt>
95+
<dd>refresh line (clear screen in shell)</dd>
96+
<dt><code>Tab</code></dt>
97+
<dd>Invoke completion handler for text under cursor</dd>
98+
<dt><code>C-c</code> or <code>Esc</code></dt>
99+
<dd>Deactivate Readline (closes the shell)</dd>
100+
<dt><code>~</code></dt>
101+
<dd>Activate Readline (opens the shell)</dd>
102+
</dl>
103+
46104
### shell.js
47105
`shell.js` has external dependencies of [jQuery](http://jquery.com/), [Underscore](http://underscorejs.org/) and internal dependencies of `readline.js` and `history.js`.
48106

@@ -61,6 +119,9 @@ By implementing the functions `getNode` and `getChildNodes`, this library adds p
61119
### history.js
62120
`history.js` implements a localStorage back command history storage that persists over page changes and reloads. It is used by the `shell.js` history command to list all executed commands, and by `readline.js` for up/down arrow and reverse search capabilities.
63121

122+
### killring.js
123+
`killing.js` implements the kill and yank behavior as well as state tracking, i.e. multiple consecutive kills are combined as a single kill and killring rotation tracks the previous yank, so that the `readline.js` can remove the previous yank and replace it with the rotated text.
124+
64125
## Changelog
65126

66127
**0.2.4** -- 2013/01/14

‎index.html

Copy file name to clipboardExpand all lines: index.html
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.2/underscore-min.js"></script>
1010
<script>Josh = {Debug: true };</script>
1111
<script src="js/history.js"></script>
12+
<script src="js/killring.js"></script>
1213
<script src="js/readline.js"></script>
1314
<script src="js/shell.js"></script>
1415
<script src="js/pathhandler.js"></script>
@@ -17,17 +18,20 @@
1718
#shell-panel {
1819
display: none;
1920
height: 400px;
20-
width: 100%;
21+
width: 97.0%;
2122
opacity: 0.9;
2223
background-color: #002f05;
2324
color: #00fe00;
2425
position: fixed;
2526
padding: 20px 20px 20px 20px;
2627
top: 0;
28+
left: 0;
2729
z-index: 1000;
2830
font-family: 'Source Code Pro', sans-serif;
2931
font-size: 0.9em;
30-
overflow: hidden;
32+
overflow:scroll;
33+
overflow-x:hidden;
34+
overflow-y: scroll;
3135
}</style>
3236
</head>
3337
<body>

‎js/example.js

Copy file name to clipboardExpand all lines: js/example.js
+22-3Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,25 @@
128128
);
129129
root.path = '/';
130130
var history = Josh.History();
131-
var shell = Josh.Shell({history: history, console: _console});
131+
var killring = new Josh.KillRing();
132+
var readline = new Josh.ReadLine({history: history, killring: killring, console: _console });
133+
var shell = Josh.Shell({readline: readline, history: history, console: _console});
134+
var killringItemTemplate = _.template("<div><%- i %>&nbsp;<%- cmd %></div>");
135+
136+
shell.setCommandHandler("killring", {
137+
exec: function(cmd, args, callback) {
138+
if(args[0] == "-c") {
139+
killring.clear();
140+
callback();
141+
return;
142+
}
143+
var content = $('<div></div>');
144+
_.each(killring.items(), function(cmd, i) {
145+
content.append(killringItemTemplate({cmd: cmd, i: i}));
146+
});
147+
callback(content);
148+
}
149+
});
132150
var pathhandler = Josh.PathHandler(shell, {console: _console});
133151
pathhandler.current = root;
134152
pathhandler.getNode = function(path, callback) {
@@ -167,10 +185,11 @@
167185
hideConsole();
168186
});
169187
});
170-
return {
188+
Josh.Instance = {
171189
Tree: root,
172190
Shell: shell,
173-
PathHandler: pathhandler
191+
PathHandler: pathhandler,
192+
KillRing: killring
174193
};
175194
})(root, $, _);
176195
})(this, $, _);

‎js/killring.js

Copy file name to clipboard
+104Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/* ------------------------------------------------------------------------*
2+
* Copyright 2013 Arne F. Claassen
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*-------------------------------------------------------------------------*/
16+
17+
var Josh = Josh || {};
18+
(function(root) {
19+
Josh.KillRing = function(config) {
20+
config = config || {};
21+
22+
var _console = Josh.Debug && root.console ? root.console : {log: function() {
23+
}};
24+
var _ring = config.ring || [];
25+
var _cursor = config.cursor || 0;
26+
var _uncommitted = false;
27+
var _yanking = false;
28+
if(_ring.length == 0) {
29+
_cursor = -1;
30+
} else if(_cursor >= _ring.length) {
31+
_cursor = _ring.length - 1;
32+
}
33+
var self = {
34+
isinkill: function() {
35+
return _uncommitted;
36+
},
37+
lastyanklength: function() {
38+
if(!_yanking) {
39+
return 0;
40+
}
41+
return _ring[_cursor].length;
42+
},
43+
append: function(value) {
44+
_yanking = false;
45+
if(!value) {
46+
return;
47+
}
48+
if(_ring.length == 0 || !_uncommitted) {
49+
_ring.push('');
50+
}
51+
_cursor = _ring.length - 1;
52+
_console.log("appending: " + value);
53+
_uncommitted = true;
54+
_ring[_cursor] += value;
55+
},
56+
prepend: function(value) {
57+
_yanking = false;
58+
if(!value) {
59+
return;
60+
}
61+
if(_ring.length == 0 || !_uncommitted) {
62+
_ring.push('');
63+
}
64+
_cursor = _ring.length - 1;
65+
_console.log("prepending: " + value);
66+
_uncommitted = true;
67+
_ring[_cursor] = value + _ring[_cursor];
68+
},
69+
commit: function() {
70+
_console.log("committing");
71+
_yanking = false;
72+
_uncommitted = false;
73+
},
74+
yank: function() {
75+
self.commit();
76+
if(_ring.length == 0) {
77+
return null;
78+
}
79+
_yanking = true;
80+
return _ring[_cursor];
81+
},
82+
rotate: function() {
83+
if(!_yanking || _ring.length == 0) {
84+
return null;
85+
}
86+
--_cursor;
87+
if(_cursor < 0) {
88+
_cursor = _ring.length - 1;
89+
}
90+
return self.yank();
91+
},
92+
items: function() {
93+
return _ring.slice(0);
94+
},
95+
clear: function() {
96+
_ring = [];
97+
_cursor = -1;
98+
_yanking = false;
99+
_uncommited = false;
100+
}
101+
};
102+
return self;
103+
}
104+
})(this);

‎js/pathhandler.js

Copy file name to clipboardExpand all lines: js/pathhandler.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
var Josh = Josh || {};
1818
(function(root, $, _) {
1919
Josh.PathHandler = function(shell, config) {
20+
config = config || {};
2021
var _console = config.console || (Josh.Debug && root.console ? root.console : {
2122
log: function() {
2223
}

0 commit comments

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