-
Download
shapeless_errors.rb
to your computer -
Make it executable:
chmod +x /path/to/shapeless_errors.rb
-
Install the
terminal-table
gem:gem install terminal-table
- Note: You might need to
sudo gem install
if you're using system Ruby
- Note: You might need to
-
Run your Scala code and pipe it into
shapeless_errors.rb
:sbt run | /path/to/shapeless_errors.rb
Last active
November 17, 2016 17:32
-
-
Save mrdziuban/c1b8260912329a1ddbdcc8a1dfe15cc4 to your computer and use it in GitHub Desktop.
Ruby script to pretty print Shapeless record errors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
################################################################################ | |
# # | |
# Reads lines from STDIN and matches them against the format in which a # | |
# Shapeless record is printed. # | |
# # | |
# If the line matches the format, the keys and values of the record are # | |
# parsed and displayed using the terminal-table gem # | |
# (https://github.com/tj/terminal-table). # | |
# # | |
# USAGE: sbt run | /path/to/shapeless_errors.rb # | |
# # | |
################################################################################ | |
begin | |
require 'terminal-table' | |
rescue LoadError | |
puts "\033[1;31mFailing to display Shapeless errors correctly without the terminal-table gem!" | |
puts "Please install it with\n\n\tgem install terminal-table\n\n" | |
puts "Displaying output normally...\n\033[0m" | |
end | |
msg = 'Parsed Shapeless record' | |
term_width = `tput cols`.to_i | |
num_stars = (term_width - (msg.length + 2)) / 2 | |
header = "\n\033[1;32m#{'*' * num_stars} #{msg} #{'*' * num_stars}\033[0m\n" | |
footer = "\n\033[1;32m#{'*' * term_width}\033[0m\n" | |
while line = $stdin.gets | |
matches = line.scan(/shapeless\.tag\.Tagged\[([^,]*)\],([^,]*)/) | |
if matches.empty? || defined?(Terminal::Table).nil? | |
puts line | |
next | |
end | |
start = /^(.*?)shapeless\.::/.match(line) | |
matches = matches.map { |m| [m[0], m[1][0..-2]] } | |
table = Terminal::Table.new(headings: ['Key', 'Value'], rows: matches) | |
puts "#{start ? start[1] : ''}#{header}#{table}#{footer}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output:
Before
After