Fossil SCM

Fixed Ctrl-D handling in rhino-based shell.

stephan 2011-10-08 14:36 UTC json-multitag-test
Commit 15c6caf29ece4354b90ffd1325ad02e6500b8b7d
1 file changed +22 -3
--- ajax/i-test/rhino-shell.js
+++ ajax/i-test/rhino-shell.js
@@ -107,11 +107,12 @@
107107
importPackage(java.lang);
108108
var stdin = new BufferedReader(new InputStreamReader(System['in']));
109109
var self = this;
110110
return function(prompt) {
111111
if(prompt) print(prompt);
112
- return String(stdin.readLine());
112
+ var x = stdin.readLine();
113
+ return null===x ? x : String(x) /*convert to JS string!*/;
113114
};
114115
}());
115116
116117
FShell.dispatchLine = function(line){
117118
var av = line.split(' '); // FIXME: to shell-like tokenization. Too tired!
@@ -141,19 +142,28 @@
141142
callback(resp,req);
142143
}
143144
};
144145
};
145146
FShell.commandHandlers = {
147
+ "?":function(args){
148
+ var k;
149
+ print("Available commands...\n");
150
+ var o = FShell.commandHandlers;
151
+ for(k in o){
152
+ if(! o.hasOwnProperty(k)) continue;
153
+ print("\t"+k);
154
+ }
155
+ },
146156
"/":function(args){
147157
FShell.fossil.sendCommand('/json'+args[0],undefined,{
148158
beforeSend:function(req,opt){
149159
print("Sending to: "+opt.url);
150160
},
151161
onResponse:FShell.onResponseDefault()
152162
});
153163
},
154
- "e":function(args){
164
+ "eval":function(args){
155165
eval(args.join(' '));
156166
},
157167
"login":function(args){
158168
FShell.fossil.login(args[1], args[2], {
159169
onResponse:FShell.onResponseDefault()
@@ -167,10 +177,11 @@
167177
"HAI":function(args){
168178
FShell.fossil.HAI({
169179
onResponse:FShell.onResponseDefault()
170180
});
171181
}
182
+
172183
};
173184
FShell.commandAliases = {
174185
"li":"login",
175186
"lo":"logout",
176187
"who":"whoami",
@@ -177,13 +188,21 @@
177188
"hi":"HAI",
178189
"tci":"/timeline/ci?limit=3"
179190
};
180191
FShell.mainLoop = function(){
181192
var line;
182
- while( null != (line = this.readline(this.prompt)) ){
193
+ var check = /\S/;
194
+ //var isJavaNull = /java\.lang\.null/;
195
+ //print(typeof java.lang['null']);
196
+ while( null != (line=this.readline(this.prompt)) ){
197
+ if(null===line) break /*EOF*/;
198
+ else if( "" === line ) continue;
183199
//print("Got line: "+line);
200
+ else if(!check.test(line)) continue;
201
+ print('typeof line = '+typeof line);
184202
this.dispatchLine(line);
185203
print("");
186204
}
205
+ print("Bye!");
187206
};
188207
189208
FShell.mainLoop();
190209
--- ajax/i-test/rhino-shell.js
+++ ajax/i-test/rhino-shell.js
@@ -107,11 +107,12 @@
107 importPackage(java.lang);
108 var stdin = new BufferedReader(new InputStreamReader(System['in']));
109 var self = this;
110 return function(prompt) {
111 if(prompt) print(prompt);
112 return String(stdin.readLine());
 
113 };
114 }());
115
116 FShell.dispatchLine = function(line){
117 var av = line.split(' '); // FIXME: to shell-like tokenization. Too tired!
@@ -141,19 +142,28 @@
141 callback(resp,req);
142 }
143 };
144 };
145 FShell.commandHandlers = {
 
 
 
 
 
 
 
 
 
146 "/":function(args){
147 FShell.fossil.sendCommand('/json'+args[0],undefined,{
148 beforeSend:function(req,opt){
149 print("Sending to: "+opt.url);
150 },
151 onResponse:FShell.onResponseDefault()
152 });
153 },
154 "e":function(args){
155 eval(args.join(' '));
156 },
157 "login":function(args){
158 FShell.fossil.login(args[1], args[2], {
159 onResponse:FShell.onResponseDefault()
@@ -167,10 +177,11 @@
167 "HAI":function(args){
168 FShell.fossil.HAI({
169 onResponse:FShell.onResponseDefault()
170 });
171 }
 
172 };
173 FShell.commandAliases = {
174 "li":"login",
175 "lo":"logout",
176 "who":"whoami",
@@ -177,13 +188,21 @@
177 "hi":"HAI",
178 "tci":"/timeline/ci?limit=3"
179 };
180 FShell.mainLoop = function(){
181 var line;
182 while( null != (line = this.readline(this.prompt)) ){
 
 
 
 
 
183 //print("Got line: "+line);
 
 
184 this.dispatchLine(line);
185 print("");
186 }
 
187 };
188
189 FShell.mainLoop();
190
--- ajax/i-test/rhino-shell.js
+++ ajax/i-test/rhino-shell.js
@@ -107,11 +107,12 @@
107 importPackage(java.lang);
108 var stdin = new BufferedReader(new InputStreamReader(System['in']));
109 var self = this;
110 return function(prompt) {
111 if(prompt) print(prompt);
112 var x = stdin.readLine();
113 return null===x ? x : String(x) /*convert to JS string!*/;
114 };
115 }());
116
117 FShell.dispatchLine = function(line){
118 var av = line.split(' '); // FIXME: to shell-like tokenization. Too tired!
@@ -141,19 +142,28 @@
142 callback(resp,req);
143 }
144 };
145 };
146 FShell.commandHandlers = {
147 "?":function(args){
148 var k;
149 print("Available commands...\n");
150 var o = FShell.commandHandlers;
151 for(k in o){
152 if(! o.hasOwnProperty(k)) continue;
153 print("\t"+k);
154 }
155 },
156 "/":function(args){
157 FShell.fossil.sendCommand('/json'+args[0],undefined,{
158 beforeSend:function(req,opt){
159 print("Sending to: "+opt.url);
160 },
161 onResponse:FShell.onResponseDefault()
162 });
163 },
164 "eval":function(args){
165 eval(args.join(' '));
166 },
167 "login":function(args){
168 FShell.fossil.login(args[1], args[2], {
169 onResponse:FShell.onResponseDefault()
@@ -167,10 +177,11 @@
177 "HAI":function(args){
178 FShell.fossil.HAI({
179 onResponse:FShell.onResponseDefault()
180 });
181 }
182
183 };
184 FShell.commandAliases = {
185 "li":"login",
186 "lo":"logout",
187 "who":"whoami",
@@ -177,13 +188,21 @@
188 "hi":"HAI",
189 "tci":"/timeline/ci?limit=3"
190 };
191 FShell.mainLoop = function(){
192 var line;
193 var check = /\S/;
194 //var isJavaNull = /java\.lang\.null/;
195 //print(typeof java.lang['null']);
196 while( null != (line=this.readline(this.prompt)) ){
197 if(null===line) break /*EOF*/;
198 else if( "" === line ) continue;
199 //print("Got line: "+line);
200 else if(!check.test(line)) continue;
201 print('typeof line = '+typeof line);
202 this.dispatchLine(line);
203 print("");
204 }
205 print("Bye!");
206 };
207
208 FShell.mainLoop();
209

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button