From 57e63f2308cee995307a83cccb30244c00219ffb Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Mon, 19 Aug 2024 11:20:08 -0300 Subject: [PATCH] Make formatter a bit more convenient --- src/formatter.cr | 2 +- src/formatters/ansi.cr | 2 +- src/formatters/html.cr | 2 +- src/formatters/json.cr | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/formatter.cr b/src/formatter.cr index 7c0bf44..b9f8381 100644 --- a/src/formatter.cr +++ b/src/formatter.cr @@ -12,7 +12,7 @@ module Tartrazine property theme : Theme = Tartrazine.theme("default-dark") # Format the text using the given lexer. - def format(text : String, lexer : Lexer, io : IO?) : String? + def format(text : String, lexer : Lexer, io : IO? = nil) : String? raise Exception.new("Not implemented") end diff --git a/src/formatters/ansi.cr b/src/formatters/ansi.cr index fb3e5c5..19d72f3 100644 --- a/src/formatters/ansi.cr +++ b/src/formatters/ansi.cr @@ -11,7 +11,7 @@ module Tartrazine "#{i + 1}".rjust(4).ljust(5) end - def format(text : String, lexer : Lexer, io : IO?) : String? + def format(text : String, lexer : Lexer, io : IO? = nil) : String? outp = io.nil? ? String::Builder.new("") : io tokenizer = Tokenizer.new(lexer, text) i = 0 diff --git a/src/formatters/html.cr b/src/formatters/html.cr index cb33d89..3938820 100644 --- a/src/formatters/html.cr +++ b/src/formatters/html.cr @@ -34,7 +34,7 @@ module Tartrazine @weight_of_bold : Int32 = 600) end - def format(text : String, lexer : Lexer, io : IO?) : String? + def format(text : String, lexer : Lexer, io : IO? = nil) : String? outp = io.nil? ? String::Builder.new("") : io pre, post = wrap_standalone outp << pre if standalone? diff --git a/src/formatters/json.cr b/src/formatters/json.cr index 857723b..39271c8 100644 --- a/src/formatters/json.cr +++ b/src/formatters/json.cr @@ -4,7 +4,7 @@ module Tartrazine class Json < Formatter property name = "json" - def format(text : String, lexer : Lexer, io : IO?) : String? + def format(text : String, lexer : Lexer, io : IO? = nil) : String? outp = io.nil? ? String::Builder.new("") : io tokenizer = Tokenizer.new(lexer, text) outp << Tartrazine::Lexer.collapse_tokens(tokenizer.to_a).to_json