Permalink
Browse files

for multiline input, change prompt and don't print result till the end

  • Loading branch information...
1 parent 006f4ae commit 28b9b8e1ca48872f62f231b4736373e07dc381ed @cldwalker cldwalker committed Aug 14, 2011
Showing with 25 additions and 4 deletions.
  1. +4 −1 lib/rack/webconsole/repl.rb
  2. +10 −0 lib/rack/webconsole/shell.rb
  3. +4 −0 public/webconsole.css
  4. +7 −3 public/webconsole.js
@@ -69,7 +69,10 @@ def call(env)
$sandbox ||= Sandbox.new
result = Shell.eval_query params['query']
- response_body = MultiJson.encode(:result => result)
+ response_body = MultiJson.encode(:result => result,
+ :multi_line => Ripl.shell.multi_line?,
+ :previous_multi_line => Ripl.shell.previous_multi_line?,
+ :prompt => Ripl.shell.previous_multi_line? ? "|| " : ">> ")
headers = {}
headers['Content-Type'] = 'application/json'
headers['Content-Length'] = response_body.bytesize.to_s
@@ -8,7 +8,17 @@ def self.eval_query(query)
Ripl.shell.return_result
end
+ # TODO: move to plugin
+ def multi_line?
+ @buffer.is_a?(Array)
+ end
+
+ def previous_multi_line?
+ @old_buffer.is_a?(Array)
+ end
+
def get_input
+ @old_buffer = @buffer
history << @input
@input
end
@@ -23,6 +23,10 @@
border-top: 1px dashed #333;
margin-bottom: 5px;
}
+#rack-webconsole div.query_multiline{
+ font-weight: bold;
+ margin-bottom: 5px;
+}
#rack-webconsole div.query:first-child{
margin-top: 0px;
padding-top: 0px;
View
@@ -29,9 +29,13 @@
dataType: 'json',
data: ({query: webconsole.query.val(), token: "$TOKEN"}),
success: function (data) {
- var q = "<div class='query'>" + escapeHTML(">> " + webconsole.query.val()) + "</div>";
- var r = "<div class='result'>" + escapeHTML("=> " + data.result) + "</div>";
- $("#rack-webconsole .results").append(q + r);
+ var query_class = data.previous_multi_line ? 'query_multiline' : 'query';
+ var result = "<div class='" + query_class + "'>" +
+ escapeHTML(data.prompt + webconsole.query.val()) + "</div>";
+ if (!data.multi_line) {
+ result += "<div class='result'>" + escapeHTML("=> " + data.result) + "</div>";
+ }
+ $("#rack-webconsole .results").append(result);
$("#rack-webconsole .results_wrapper").scrollTop(
$("#rack-webconsole .results").height()
);

0 comments on commit 28b9b8e

Please sign in to comment.