Skip to content
This repository
Browse code

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

  • Loading branch information...
commit 28b9b8e1ca48872f62f231b4736373e07dc381ed 1 parent 006f4ae
Gabriel Horner authored August 14, 2011
5  lib/rack/webconsole/repl.rb
@@ -69,7 +69,10 @@ def call(env)
69 69
 
70 70
         $sandbox ||= Sandbox.new
71 71
         result = Shell.eval_query params['query']
72  
-        response_body = MultiJson.encode(:result => result)
  72
+        response_body = MultiJson.encode(:result => result,
  73
+          :multi_line => Ripl.shell.multi_line?,
  74
+          :previous_multi_line => Ripl.shell.previous_multi_line?,
  75
+          :prompt => Ripl.shell.previous_multi_line? ? "|| " : ">> ")
73 76
         headers = {}
74 77
         headers['Content-Type'] = 'application/json'
75 78
         headers['Content-Length'] = response_body.bytesize.to_s
10  lib/rack/webconsole/shell.rb
@@ -8,7 +8,17 @@ def self.eval_query(query)
8 8
       Ripl.shell.return_result
9 9
     end
10 10
 
  11
+    # TODO: move to plugin
  12
+    def multi_line?
  13
+      @buffer.is_a?(Array)
  14
+    end
  15
+
  16
+    def previous_multi_line?
  17
+      @old_buffer.is_a?(Array)
  18
+    end
  19
+
11 20
     def get_input
  21
+      @old_buffer = @buffer
12 22
       history << @input
13 23
       @input
14 24
     end
4  public/webconsole.css
@@ -23,6 +23,10 @@
23 23
   border-top: 1px dashed #333;
24 24
   margin-bottom: 5px;
25 25
 }
  26
+#rack-webconsole div.query_multiline{
  27
+  font-weight: bold;
  28
+  margin-bottom: 5px;
  29
+}
26 30
 #rack-webconsole div.query:first-child{
27 31
   margin-top: 0px;
28 32
   padding-top: 0px;
10  public/webconsole.js
@@ -29,9 +29,13 @@
29 29
         dataType: 'json',
30 30
         data: ({query: webconsole.query.val(), token: "$TOKEN"}),
31 31
         success: function (data) {
32  
-          var q = "<div class='query'>" + escapeHTML(">> " + webconsole.query.val()) + "</div>";
33  
-          var r = "<div class='result'>" + escapeHTML("=> " + data.result) + "</div>";
34  
-          $("#rack-webconsole .results").append(q + r);
  32
+          var query_class = data.previous_multi_line ? 'query_multiline' : 'query';
  33
+          var result = "<div class='" + query_class + "'>" +
  34
+            escapeHTML(data.prompt + webconsole.query.val()) + "</div>";
  35
+          if (!data.multi_line) {
  36
+            result += "<div class='result'>" + escapeHTML("=> " + data.result) + "</div>";
  37
+          }
  38
+          $("#rack-webconsole .results").append(result);
35 39
           $("#rack-webconsole .results_wrapper").scrollTop(
36 40
             $("#rack-webconsole .results").height()
37 41
           );

0 notes on commit 28b9b8e

Please sign in to comment.
Something went wrong with that request. Please try again.