Skip to content

Commit 56a0ab3

Browse files
Redesign REPL
Shorter prompt. Individual results as their own element with a heading and more visual dilineation for each.
1 parent b1f707d commit 56a0ab3

File tree

8 files changed

+103
-62
lines changed

8 files changed

+103
-62
lines changed

lib/better_errors/repl/basic.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ def initialize(binding, _exception)
66
end
77

88
def send_input(str)
9-
[execute(str), ">>", ""]
9+
[execute(str), ">", ""]
1010
end
1111

1212
private
1313
def execute(str)
14-
"=> #{@binding.eval(str).inspect}\n"
14+
"=> #{CGI.escapeHTML(@binding.eval(str).inspect)}\n"
1515
rescue Exception => e
1616
"!! #{e.inspect rescue e.class.to_s rescue "Exception"}\n"
1717
end

lib/better_errors/repl/pry.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ def prompt
6464
if indent = @pry.instance_variable_get(:@indent) and !indent.indent_level.empty?
6565
["..", indent.indent_level]
6666
else
67-
[">>", ""]
67+
[">", ""]
6868
end
6969
rescue
70-
[">>", ""]
70+
[">", ""]
7171
end
7272

7373
private

lib/better_errors/templates/main.css

Lines changed: 72 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ ul.frames .icon.application:before {
373373
* Monospace
374374
* --------------------------------------------------------------------- */
375375

376-
pre, code, .be-repl input, .be-repl .command-line span, textarea, .code_linenums, .title .name,
376+
pre, code, .be-repl .command-line input, .be-repl .command-line .prompt, .be-repl .output .command, textarea, .code_linenums, .title .name,
377377
ul.frames li .method {
378378
font-family: menlo, lucida console, monospace;
379379
}
@@ -436,7 +436,6 @@ ul.frames li .method {
436436

437437
.code, .be-console, .unavailable {
438438
background: #fff;
439-
padding: 5px;
440439
}
441440

442441
.code_linenums{
@@ -506,35 +505,65 @@ p.unavailable:before {
506505
animation: highlight 400ms linear 1;
507506
}
508507

508+
h3 {
509+
background-color: #38a;
510+
color: white;
511+
padding: 4px;
512+
font-size: 8pt;
513+
margin-top: 1rem;
514+
515+
-webkit-font-smoothing: antialiased;
516+
}
517+
509518
/* REPL shell */
510519
.be-console {
511-
padding: 0 1px 10px 1px;
512-
border-bottom-left-radius: 2px;
513-
border-bottom-right-radius: 2px;
514520
}
515521

516-
.be-console pre {
517-
padding: 10px 10px 0 10px;
518-
max-height: 400px;
522+
.be-console .output {
523+
max-height: 15rem;
519524
overflow-x: none;
520525
overflow-y: auto;
521-
margin-bottom: -3px;
526+
527+
padding: 8px;
528+
margin-bottom: 8px;
529+
border-bottom: 1px solid #ccc;
530+
}
531+
.be-console .output:not(.used) {
532+
padding-bottom: 0;
533+
border-bottom: 0;
534+
margin-bottom: 0;
535+
}
536+
@media screen and (min-height: 800px) {
537+
.be-console .output {
538+
max-height: 25rem;
539+
}
540+
}
541+
542+
.be-console .output pre, .be-console .output h4 {
543+
font-size: 9pt;
522544
word-wrap: break-word;
523545
white-space: pre-wrap;
546+
width: 100%;
547+
}
548+
.be-console .output h4 {
549+
background-color: #ddd;
550+
padding: 5px 0;
551+
margin-top: 10px;
524552
}
525553

526554
/* .command-line > span + input */
527555
.be-console .command-line {
528556
display: table;
529-
width: 100%;
530557
}
531558

532-
.be-console .command-line span,
559+
.be-console .command-line .prompt,
533560
.be-console .command-line input {
534561
display: table-cell;
562+
line-height: 12px;
563+
font-size: 9pt;
535564
}
536565

537-
.be-console .command-line span {
566+
.be-console .command-line .prompt {
538567
width: 1%;
539568
padding-right: 5px;
540569
padding-left: 10px;
@@ -563,26 +592,10 @@ p.unavailable:before {
563592
padding-left: 20px;
564593
}
565594

566-
.hint:before {
567-
content: '\25b2';
568-
margin-right: 5px;
569-
opacity: 0.5;
570-
}
571-
572595
/* ---------------------------------------------------------------------
573596
* Variable infos
574597
* --------------------------------------------------------------------- */
575598

576-
.variables h3 {
577-
background-color: #38a;
578-
color: white;
579-
padding: 4px;
580-
font-size: 8pt;
581-
margin-top: 1rem;
582-
583-
-webkit-font-smoothing: antialiased;
584-
}
585-
586599
.variables h4 {
587600
margin-top: 5px;
588601
padding-left: 5px;
@@ -646,3 +659,34 @@ nav.sidebar:hover::-webkit-scrollbar-thumb {
646659
.code:hover::-webkit-scrollbar-thumb {
647660
background: #888;
648661
}
662+
663+
.bold {
664+
font-weight: bold;
665+
}
666+
.black {
667+
color: black;
668+
}
669+
.red {
670+
color: red;
671+
}
672+
.green {
673+
color: green;
674+
}
675+
.yellow {
676+
color: yellow;
677+
}
678+
.blue {
679+
color: blue;
680+
}
681+
.magenta {
682+
color: magenta;
683+
}
684+
.cyan {
685+
color: cyan;
686+
}
687+
.white {
688+
color: white;
689+
}
690+
.green {
691+
color: green;
692+
}

lib/better_errors/templates/main.erb

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,14 @@
130130

131131
this.promptElement = this.container.querySelector(".command-line .prompt");
132132
this.inputElement = this.container.querySelector("input");
133-
this.outputElement = this.container.querySelector("pre");
133+
this.outputElement = this.container.querySelector(".output");
134134

135135
var self = this;
136136
this.inputElement.onkeydown = function(ev) {
137137
self.onKeyDown(ev);
138138
};
139139

140-
this.setPrompt(">>");
140+
this.setPrompt(">");
141141

142142
REPL.all[this.index] = this;
143143
}
@@ -164,24 +164,28 @@
164164
}
165165
};
166166

167-
REPL.prototype.writeRawOutput = function(output) {
168-
this.outputElement.innerHTML += output;
169-
this.outputElement.scrollTop = this.outputElement.scrollHeight;
167+
REPL.prototype.writeErrorOutput = function(error) {
168+
this.writeOutput("<pre class='error'>" + error + "</pre>");
170169
};
171170

172-
REPL.prototype.writeOutput = function(output) {
173-
this.writeRawOutput(escapeHTML(output));
171+
REPL.prototype.writeResultOutput = function(prompt, command, result) {
172+
this.writeOutput("<h4 class='command'>" + prompt + " " + command + "</h4>");
173+
this.writeOutput("<pre class='result'>" + result + "</pre>");
174+
};
175+
176+
REPL.prototype.writeOutput = function(content) {
177+
this.outputElement.className = "output used";
178+
this.outputElement.innerHTML += content;
179+
this.outputElement.scrollTop = this.outputElement.scrollHeight;
174180
};
175181

176182
REPL.prototype.sendInput = function(line) {
177183
var self = this;
178184
apiCall("eval", { "index": this.index, source: line }, function(response) {
179185
if(response.error) {
180-
self.writeOutput(response.error + "\n");
186+
self.writeErrorOutput(response.error);
181187
}
182-
self.writeOutput(self._prompt + " ");
183-
self.writeRawOutput(response.highlighted_input + "\n");
184-
self.writeOutput(response.result);
188+
self.writeResultOutput(self._prompt, response.highlighted_input, response.result);
185189
self.setPrompt(response.prompt);
186190
self.setInput(response.prefilled_input);
187191
});

lib/better_errors/templates/variable_info.erb

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,16 @@
66
<div class="code_block clearfix">
77
<%== html_formatted_code_block @frame %>
88
</div>
9-
10-
<% if BetterErrors.binding_of_caller_available? && @frame.frame_binding %>
11-
<div class="be-repl">
12-
<div class="be-console">
13-
<pre></pre>
14-
<div class="command-line"><span class='prompt'>&gt;&gt;</span> <input tabindex="1"/></div>
15-
</div>
16-
</div>
17-
<% end %>
189
</header>
1910

2011
<% if BetterErrors.binding_of_caller_available? && @frame.frame_binding %>
21-
<div class="hint">
22-
This is a live shell. Type in here.
12+
<div class="be-repl">
13+
<h3>Console</h3>
14+
<div class="be-console">
15+
<div class="output"></div>
16+
<div class="command-line"><span class='prompt'>&gt;</span> <input tabindex="1"/></div>
17+
</div>
2318
</div>
24-
25-
<div class="variable_info"></div>
2619
<% end %>
2720

2821
<% unless BetterErrors.binding_of_caller_available? %>

spec/better_errors/error_page_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def initialize(message = nil)
276276
expect(do_eval).to include(
277277
highlighted_input: /stuff_was_done/,
278278
prefilled_input: '',
279-
prompt: '>>',
279+
prompt: '>',
280280
result: "=> \"response\"\n",
281281
)
282282
end
@@ -309,7 +309,7 @@ def initialize(message = nil)
309309
expect(do_eval).to include(
310310
highlighted_input: /stuff_was_done/,
311311
prefilled_input: '',
312-
prompt: '>>',
312+
prompt: '>',
313313
result: "=> \"response\"\n",
314314
)
315315
end

spec/better_errors/repl/pry_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
it "does line continuation", :aggregate_failures do
2727
output, prompt, filled = repl.send_input ""
2828
expect(output).to eq("=> nil\n")
29-
expect(prompt).to eq(">>")
29+
expect(prompt).to eq(">")
3030
expect(filled).to eq("")
3131

3232
output, prompt, filled = repl.send_input "def f(x)"
@@ -40,7 +40,7 @@
4040
else
4141
expect(output).to eq("=> nil\n")
4242
end
43-
expect(prompt).to eq(">>")
43+
expect(prompt).to eq(">")
4444
expect(filled).to eq("")
4545
end
4646

spec/better_errors/repl/shared_examples.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
it "returns a tuple of output and the new prompt" do
88
output, prompt = repl.send_input("1 + 2")
99
expect(output).to eq("=> 3\n")
10-
expect(prompt).to eq(">>")
10+
expect(prompt).to eq(">")
1111
end
1212

1313
it "doesn't barf if the code throws an exception" do
1414
output, prompt = repl.send_input("raise Exception")
1515
expect(output).to include "Exception: Exception"
16-
expect(prompt).to eq(">>")
16+
expect(prompt).to eq(">")
1717
end
1818
end

0 commit comments

Comments
 (0)