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 6b3a08b

Browse filesBrowse files
committed
killring behavior has landed
1 parent 0dea368 commit 6b3a08b
Copy full SHA for 6b3a08b

File tree

Expand file treeCollapse file tree

5 files changed

+265
-187
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+265
-187
lines changed

‎README.md

Copy file name to clipboardExpand all lines: README.md
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ josh.js is licensed under the Apache 2.0 License
2828
* Readline has not been tested with non-ascii.
2929
* [Readline Issues/Omissions](https://github.com/sdether/josh.js/issues/1)
3030

31+
## Known Issues without
32+
3133
## Usage
3234

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

‎index.html

Copy file name to clipboardExpand all lines: index.html
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,20 @@
1818
#shell-panel {
1919
display: none;
2020
height: 400px;
21-
width: 100%;
21+
width: 97.0%;
2222
opacity: 0.9;
2323
background-color: #002f05;
2424
color: #00fe00;
2525
position: fixed;
2626
padding: 20px 20px 20px 20px;
2727
top: 0;
28+
left: 0;
2829
z-index: 1000;
2930
font-family: 'Source Code Pro', sans-serif;
3031
font-size: 0.9em;
31-
overflow: hidden;
32+
overflow:scroll;
33+
overflow-x:hidden;
34+
overflow-y: scroll;
3235
}</style>
3336
</head>
3437
<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 clipboardExpand all lines: js/killring.js
+51-25Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,62 +15,88 @@
1515
*-------------------------------------------------------------------------*/
1616

1717
var Josh = Josh || {};
18-
(function (root) {
19-
Josh.KillRing = function (config) {
18+
(function(root) {
19+
Josh.KillRing = function(config) {
2020
config = config || {};
2121

22-
var _console = Josh.Debug && root.console ? root.console : {log:function () {
22+
var _console = Josh.Debug && root.console ? root.console : {log: function() {
2323
}};
2424
var _ring = config.ring || [];
2525
var _cursor = config.cursor || 0;
26-
var _current = '';
26+
var _uncommitted = false;
2727
var _yanking = false;
28-
if (_ring.length == 0) {
28+
if(_ring.length == 0) {
2929
_cursor = -1;
30-
} else if (_cursor >= _ring.length) {
30+
} else if(_cursor >= _ring.length) {
3131
_cursor = _ring.length - 1;
3232
}
3333
var self = {
34-
append:function (value) {
35-
_yanking = false;
36-
if (!value) {
37-
return;
34+
isinkill: function() {
35+
return _uncommitted;
36+
},
37+
lastyanklength: function() {
38+
if(!_yanking) {
39+
return 0;
3840
}
39-
_current += value;
41+
return _ring[_cursor].length;
4042
},
41-
prepend:function (value) {
43+
append: function(value) {
4244
_yanking = false;
43-
if (!value) {
45+
if(!value) {
4446
return;
4547
}
46-
_current = value + _current;
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;
4755
},
48-
commit:function () {
56+
prepend: function(value) {
4957
_yanking = false;
50-
if (!_current) {
58+
if(!value) {
5159
return;
5260
}
53-
_ring.push(_current);
61+
if(_ring.length == 0 || !_uncommitted) {
62+
_ring.push('');
63+
}
5464
_cursor = _ring.length - 1;
55-
_current = '';
65+
_console.log("prepending: " + value);
66+
_uncommitted = true;
67+
_ring[_cursor] = value + _ring[_cursor];
5668
},
57-
yank:function () {
69+
commit: function() {
70+
_console.log("committing");
71+
_yanking = false;
72+
_uncommitted = false;
73+
},
74+
yank: function() {
5875
self.commit();
59-
if (_ring.length == 0) {
60-
return;
76+
if(_ring.length == 0) {
77+
return null;
6178
}
6279
_yanking = true;
6380
return _ring[_cursor];
6481
},
65-
rotate:function () {
66-
if (!_yanking || _ring.length == 0) {
67-
return;
82+
rotate: function() {
83+
if(!_yanking || _ring.length == 0) {
84+
return null;
6885
}
6986
--_cursor;
70-
if (_cursor < 0) {
87+
if(_cursor < 0) {
7188
_cursor = _ring.length - 1;
7289
}
7390
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;
74100
}
75101
};
76102
return self;

0 commit comments

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