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 6679ba4

Browse filesBrowse files
committed
- console wrapper to allow debug logging to be turned on and off
- refactored how pathhandler attaches to shell because it needs to keep a reference to the shell - refactored how prompts are set. now uses dedicated callback rather than returning the prompt in the onEnter callback - working on cross-browser compatibility. still having issues with Firefox handling keypress/keydown just a bit differently from every other browser
1 parent c2c7b0e commit 6679ba4
Copy full SHA for 6679ba4

File tree

Expand file treeCollapse file tree

8 files changed

+257
-184
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+257
-184
lines changed

‎.idea/dictionaries/Administrator.xml

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

‎LICENSE

Copy file name to clipboard
+53Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
Apache License
2+
3+
Version 2.0, January 2004
4+
5+
http://www.apache.org/licenses/
6+
7+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8+
9+
1. Definitions.
10+
11+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
12+
13+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
14+
15+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
16+
17+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
18+
19+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
20+
21+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
22+
23+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
24+
25+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
26+
27+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
28+
29+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
30+
31+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
32+
33+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
34+
35+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
36+
37+
You must give any other recipients of the Work or Derivative Works a copy of this License; and
38+
39+
You must cause any modified files to carry prominent notices stating that You changed the files; and
40+
41+
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
42+
43+
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
44+
45+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
46+
47+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
48+
49+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
50+
51+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
52+
53+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.

‎README.md

Copy file name to clipboardExpand all lines: README.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ josh.js is licensed under the Apache 2.0 License
1515

1616
* code is ready for experimental use
1717
* Only confirmed to work on chrome so far.
18+
* API is not yet stable
1819
* needs minified versions of complete toolkit and just readline.js
1920
* needs code documentation and documenation site
2021

‎js/example.js

Copy file name to clipboardExpand all lines: js/example.js
+128-121Lines changed: 128 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -14,134 +14,141 @@
1414
* limitations under the License.
1515
*-------------------------------------------------------------------------*/
1616

17-
var fs = {
18-
bin: {},
19-
boot: {},
20-
dev: {},
21-
etc: {
22-
default: {},
23-
'rc.d': {},
24-
sysconfig: {},
25-
x11: {}
26-
},
27-
home: {
28-
bob: {},
29-
jane: {}
30-
},
31-
lib: {},
32-
'lost+found': {},
33-
misc: {},
34-
mnt: {
35-
cdrom: {},
36-
sysimage: {}
37-
},
38-
net: {},
39-
opt: {},
40-
proc: {},
41-
root: {},
42-
sbin: {},
43-
usr: {
44-
x11: {},
17+
(function(root, $, _) {
18+
Josh.Debug = true;
19+
var fs = {
4520
bin: {},
46-
include: {},
47-
lib: {},
48-
local: {},
49-
man: {},
50-
sbin: {},
51-
share: {
52-
doc: {}
21+
boot: {},
22+
dev: {},
23+
etc: {
24+
default: {},
25+
'rc.d': {},
26+
sysconfig: {},
27+
x11: {}
28+
},
29+
home: {
30+
bob: {},
31+
jane: {}
5332
},
54-
src: {}
55-
},
56-
var: {
5733
lib: {},
58-
lock: {},
59-
run: {},
60-
log: {
61-
httpd: {
62-
access_log: {},
63-
error_log: {}
34+
'lost+found': {},
35+
misc: {},
36+
mnt: {
37+
cdrom: {},
38+
sysimage: {}
39+
},
40+
net: {},
41+
opt: {},
42+
proc: {},
43+
root: {},
44+
sbin: {},
45+
usr: {
46+
x11: {},
47+
bin: {},
48+
include: {},
49+
lib: {},
50+
local: {},
51+
man: {},
52+
sbin: {},
53+
share: {
54+
doc: {}
6455
},
65-
'boot.log': {},
66-
cron: {},
67-
messages: {}
56+
src: {}
57+
},
58+
var: {
59+
lib: {},
60+
lock: {},
61+
run: {},
62+
log: {
63+
httpd: {
64+
access_log: {},
65+
error_log: {}
66+
},
67+
'boot.log': {},
68+
cron: {},
69+
messages: {}
70+
}
6871
}
69-
}
70-
};
71-
function buildTree(parent, node) {
72-
parent.childnodes = _.map(_.pairs(node), function(pair) {
73-
var child = {
74-
name: pair[0],
75-
path: parent.path + "/" + pair[0],
76-
parent: parent
77-
};
78-
buildTree(child, pair[1]);
79-
return child;
80-
});
81-
parent.children = _.keys(node);
82-
return parent;
83-
}
84-
function findNode(current, parts, callback) {
85-
if(!parts || parts.length == 0) {
86-
return callback(current);
87-
}
88-
if(parts[0] == ".") {
89-
// carry on
90-
} else if(parts[0] == "..") {
91-
current = current.parent;
92-
} else {
93-
current = _.first(_.filter(current.childnodes, function(node) {
94-
return node.name == parts[0];
95-
}));
96-
}
97-
if(!current) {
98-
return callback();
99-
}
100-
return findNode(current, _.rest(parts), callback);
101-
}
102-
var root = buildTree({
103-
name: "",
104-
path: ""
105-
},
106-
fs
107-
);
108-
root.path = '/';
109-
var history = Josh.History();
110-
var shell = Josh.Shell({history: history});
111-
var pathhandler = Josh.PathHandler();
112-
pathhandler.current = root;
113-
pathhandler.attach(shell);
114-
pathhandler.getNode = function(path, callback) {
115-
if(!path) {
116-
return callback(pathhandler.current);
117-
}
118-
var parts = _.filter(path.split('/'), function(x) { return x; });
119-
var start = ((path || '')[0] == '/') ? root : pathhandler.current;
120-
console.log('start: '+start.path+', parts: '+JSON.stringify(parts));
121-
return findNode(start, parts, callback);
122-
};
123-
pathhandler.getChildNodes = function(node, callback) {
124-
console.log("children for "+node.name);
125-
callback(node.childnodes);
126-
};
72+
};
12773

128-
$(document).ready(function() {
129-
var console = $('#shell-panel');
130-
shell.onActivate(function() {
131-
showConsole();
132-
});
133-
shell.onDeactivate(function() {
134-
hideConsole();
135-
});
136-
function showConsole() {
137-
console.slideDown();
138-
console.focus();
74+
function buildTree(parent, node) {
75+
parent.childnodes = _.map(_.pairs(node), function(pair) {
76+
var child = {
77+
name: pair[0],
78+
path: parent.path + "/" + pair[0],
79+
parent: parent
80+
};
81+
buildTree(child, pair[1]);
82+
return child;
83+
});
84+
parent.children = _.keys(node);
85+
return parent;
13986
}
14087

141-
function hideConsole() {
142-
console.slideUp();
143-
console.blur();
88+
function findNode(current, parts, callback) {
89+
if(!parts || parts.length == 0) {
90+
return callback(current);
91+
}
92+
if(parts[0] == ".") {
93+
// carry on
94+
} else if(parts[0] == "..") {
95+
current = current.parent;
96+
} else {
97+
current = _.first(_.filter(current.childnodes, function(node) {
98+
return node.name == parts[0];
99+
}));
100+
}
101+
if(!current) {
102+
return callback();
103+
}
104+
return findNode(current, _.rest(parts), callback);
144105
}
145106

146-
shell.activate();
147-
});
107+
var root = buildTree({
108+
name: "",
109+
path: ""
110+
},
111+
fs
112+
);
113+
root.path = '/';
114+
var history = Josh.History();
115+
var shell = Josh.Shell({history: history});
116+
var pathhandler = Josh.PathHandler(shell);
117+
pathhandler.current = root;
118+
pathhandler.getNode = function(path, callback) {
119+
if(!path) {
120+
return callback(pathhandler.current);
121+
}
122+
var parts = _.filter(path.split('/'), function(x) {
123+
return x;
124+
});
125+
var start = ((path || '')[0] == '/') ? root : pathhandler.current;
126+
console.log('start: ' + start.path + ', parts: ' + JSON.stringify(parts));
127+
return findNode(start, parts, callback);
128+
};
129+
pathhandler.getChildNodes = function(node, callback) {
130+
console.log("children for " + node.name);
131+
callback(node.childnodes);
132+
};
133+
134+
$(document).ready(function() {
135+
var console = $('#shell-panel');
136+
shell.onActivate(function() {
137+
showConsole();
138+
});
139+
shell.onDeactivate(function() {
140+
hideConsole();
141+
});
142+
function showConsole() {
143+
console.slideDown();
144+
console.focus();
145+
}
146+
147+
function hideConsole() {
148+
console.slideUp();
149+
console.blur();
150+
}
151+
152+
shell.activate();
153+
});
154+
})(this, $, _);

‎js/history.js

Copy file name to clipboardExpand all lines: js/history.js
+7-6Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var Josh = Josh || {};
1919
Josh.History = function (config) {
2020
config = config || {};
2121

22+
var _console = Josh.Debug && root.console ? root.console : {log: function() {}};
2223
var _history = config.history || [''];
2324
var _cursor = config.cursor || 0;
2425
var _searchCursor = _cursor;
@@ -49,22 +50,22 @@ var Josh = Josh || {};
4950

5051
return {
5152
update:function (text) {
52-
console.log("updating history to " + text);
53+
_console.log("updating history to " + text);
5354
_history[_cursor] = text;
5455
save();
5556
},
5657
accept:function (text) {
57-
console.log("accepting history " + text);
58+
_console.log("accepting history " + text);
5859
var last = _history.length - 1;
5960
if (text) {
6061
if (_cursor == last) {
61-
console.log("we're at the end already, update last position");
62+
_console.log("we're at the end already, update last position");
6263
_history[_cursor] = text;
6364
} else if (!_history[last]) {
64-
console.log("we're not at the end, but the end was blank, so update last position");
65+
_console.log("we're not at the end, but the end was blank, so update last position");
6566
_history[last] = text;
6667
} else {
67-
console.log("appending to end");
68+
_console.log("appending to end");
6869
_history.push(text);
6970
}
7071
_history.push('');
@@ -132,7 +133,7 @@ var Josh = Josh || {};
132133
},
133134
applySearch:function () {
134135
if (_lastSearchTerm) {
135-
console.log("setting history to position" + _searchCursor + "(" + _cursor + "): " + _history[_searchCursor]);
136+
_console.log("setting history to position" + _searchCursor + "(" + _cursor + "): " + _history[_searchCursor]);
136137
_cursor = _searchCursor;
137138
return _history[_cursor];
138139
}

0 commit comments

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