Guest User

Untitled

a guest
May 28th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. From 9f1be1c0ef3fd0a21a85256ff076622f356f98f9 Mon Sep 17 00:00:00 2001
  2. From: Lue <lue@twigil.drangle.com>
  3. Date: Fri, 11 Jun 2010 16:01:49 -0700
  4. Subject: [PATCH] Fancy Colo[u]red Errors hath come!
  5. [If your terminal supports ANSI, that is :)]
  6.  
  7. ---
  8. src/Perl6/BacktracePrinter.pm | 21 +++++++++++----------
  9. src/builtins/Num.pir | 10 +++++-----
  10. 2 files changed, 16 insertions(+), 15 deletions(-)
  11.  
  12. diff --git a/src/Perl6/BacktracePrinter.pm b/src/Perl6/BacktracePrinter.pm
  13. index 52f2b5c..89ffe26 100644
  14. --- a/src/Perl6/BacktracePrinter.pm
  15. +++ b/src/Perl6/BacktracePrinter.pm
  16. @@ -3,9 +3,10 @@ class Perl6::BacktracePrinter;
  17. # Drives the overall backtrace production process.
  18. method backtrace_for($exception) {
  19. my @backtrace := $exception.backtrace();
  20. + my @errorprefix := ("Achtung!", "DON'T PANIC!", "Error!", "Attention!", "Oi!", "Errm...", "Owie!", "FAIL");
  21. if self.is_runtime(@backtrace) {
  22. # Runtime error. Start with the error message.
  23. - my $trace := pir::getattribute__pps($exception, 'message');
  24. + my $trace := "\e[31;1m" ~ @errorprefix[pir::rand__II(7)] ~ " \e[22;31m" ~ pir::getattribute__pps($exception, 'message')~"\e[00m";
  25.  
  26. # If top frame is 'die' or warn, drop it from the top.
  27. if ~@backtrace[0]<sub> eq '&die' || ~@backtrace[0]<sub> eq '&warn' {
  28. @@ -16,10 +17,10 @@ method backtrace_for($exception) {
  29. # file to the error and be done.
  30. if self.is_warning($exception) {
  31. my $location := @backtrace[0]<annotations>;
  32. - $trace := $trace ~ " at " ~
  33. + $trace := $trace ~ " at \e[33m" ~
  34. ($location<line> ?? 'line ' ~ $location<line> !! '<unknown line>') ~
  35. ($location<file> ?? ':' ~ $location<file> !! '' ) ~
  36. - "\n";
  37. + "\e[00m\n";
  38. return $trace;
  39. }
  40.  
  41. @@ -35,7 +36,7 @@ method backtrace_for($exception) {
  42. # If we hit the end of the user's code, we're done; emit last
  43. # annotations and say we're in main program body.
  44. if ~$_<sub> eq '!UNIT_START' {
  45. - $trace := $trace ~ self.backtrace_line(0, $cur_annotations);
  46. + $trace := $trace ~ "\e[34;1m" ~ self.backtrace_line(0, $cur_annotations) ~ "\e[00m";
  47. last;
  48. }
  49.  
  50. @@ -45,7 +46,7 @@ method backtrace_for($exception) {
  51. # informative line numbers.
  52. if !pir::isnull(pir::getprop__psp('$!p6type', $_<sub>))
  53. || pir::substr(~$_<sub>, 0, 6) eq '&infix' {
  54. - $trace := $trace ~ self.backtrace_line($_<sub>, $cur_annotations);
  55. + $trace := $trace ~ "\e[34;1m" ~ self.backtrace_line($_<sub>, $cur_annotations) ~ "\e[00m";
  56. $cur_annotations := 0;
  57. }
  58. }
  59. @@ -53,8 +54,8 @@ method backtrace_for($exception) {
  60. } else {
  61. # For parse time exceptions, we just want the message, with no
  62. # back trace beyond this.
  63. - return "===SORRY!===\n" ~
  64. - pir::getattribute__pps($exception, 'message') ~ "\n";
  65. + return "\e[41;37;1m===SORRY!===\e[00m\n" ~
  66. + "\e[31m" ~ pir::getattribute__pps($exception, 'message') ~ "\e[00m\n";
  67. }
  68. }
  69.  
  70. @@ -78,12 +79,12 @@ method is_warning($exception) {
  71. # Renders one line in the backtrace, using the given sub name and
  72. # annotations set.
  73. method backtrace_line($sub, $location) {
  74. - " in " ~
  75. + " in \e[22;32m" ~
  76. ($sub ?? self.fullname($sub) !! 'main program body') ~
  77. - " at " ~
  78. + "\e[34;1m at \e[22;33m" ~
  79. ($location<line> ?? 'line ' ~ $location<line> !! '<unknown line>' ) ~
  80. ($location<file> ?? ':' ~ $location<file> !! '' ) ~
  81. - "\n"
  82. + "\e[00m\n"
  83. }
  84.  
  85. # Generates the fully qualified name of the sub.
  86. diff --git a/src/builtins/Num.pir b/src/builtins/Num.pir
  87. index c77a2b7..eeb4563 100644
  88. --- a/src/builtins/Num.pir
  89. +++ b/src/builtins/Num.pir
  90. @@ -231,15 +231,15 @@ finish:
  91.  
  92. #errors
  93. ERANGE:
  94. - die "DON'T PANIC! The radix is out of range (2..36 only)"
  95. + die "The radix is out of range (2..36 only)"
  96. EINVALIDCHAR:
  97. - $S0 = concat "DON'T PANIC! Invalid character (", $S0
  98. - $S0 = concat $S0, ")! Please try again :) "
  99. + $S0 = concat "Invalid character (", $S0
  100. + $S0 = concat $S0, ")"
  101. die $S0
  102. EBASENOEXP:
  103. - die "DON'T PANIC! You gave us a base for the magnitude, but you forgot the exponent."
  104. + die "You gave us a base for the magnitude, but you forgot the exponent."
  105. EEXPNOBASE:
  106. - die "DON'T PANIC! You gave us an exponent for the magnitude, but you forgot the base."
  107. + die "You gave us an exponent for the magnitude, but you forgot the base."
  108. .end
  109.  
  110.  
  111. --
  112. 1.6.0.4
Add Comment
Please, Sign In to add comment