diff options
author | Yusuke Endoh <[email protected]> | 2021-06-30 12:28:22 +0900 |
---|---|---|
committer | git <[email protected]> | 2021-06-30 12:49:18 +0900 |
commit | f428ced69c70473b8405aae9c98828aa6f69b254 (patch) | |
tree | 9504ebbb01cc7333381c3fd06430c72f99fbbb3f /lib/error_highlight/formatter.rb | |
parent | db7e9b1aac7752259e60e09b92ea2d2e74b0886d (diff) |
[ruby/error_highlight] Experimentally support a custom formatter
https://github.com/ruby/error_highlight/commit/f40a1de20e
Diffstat (limited to 'lib/error_highlight/formatter.rb')
-rw-r--r-- | lib/error_highlight/formatter.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/error_highlight/formatter.rb b/lib/error_highlight/formatter.rb new file mode 100644 index 0000000000..a3d6510dc2 --- /dev/null +++ b/lib/error_highlight/formatter.rb @@ -0,0 +1,24 @@ +module ErrorHighlight + class DefaultFormatter + def message_for(spot) + # currently only a one-line code snippet is supported + if spot[:first_lineno] == spot[:last_lineno] + marker = " " * spot[:first_column] + "^" * (spot[:last_column] - spot[:first_column]) + + "\n\n#{ spot[:snippet] }#{ marker }" + else + "" + end + end + end + + def self.formatter + @@formatter + end + + def self.formatter=(formatter) + @@formatter = formatter + end + + self.formatter = DefaultFormatter.new +end |