From d910756cafd6fbf449589e4012e344f0304f1527 Mon Sep 17 00:00:00 2001 From: nialljames Date: Mon, 8 Sep 2025 07:29:01 +0100 Subject: [PATCH 1/4] add wrapper method for colour to allow multiple colour in string --- lib/dvla/herodotus/string.rb | 93 ++++++++++++------------------ spec/dvla/herodotus/string_spec.rb | 51 ++++++++-------- 2 files changed, 62 insertions(+), 82 deletions(-) diff --git a/lib/dvla/herodotus/string.rb b/lib/dvla/herodotus/string.rb index b2d2fd1..7c337e8 100644 --- a/lib/dvla/herodotus/string.rb +++ b/lib/dvla/herodotus/string.rb @@ -1,61 +1,40 @@ class String - def black = "\e[30m#{self}\e[0m" - - def red = "\e[31m#{self}\e[0m" - - def green = "\e[32m#{self}\e[0m" - - def brown = "\e[33m#{self}\e[0m" - - def blue = "\e[34m#{self}\e[0m" - - def magenta = "\e[35m#{self}\e[0m" - - def cyan = "\e[36m#{self}\e[0m" - - def gray = "\e[37m#{self}\e[0m" - + def colourise(code, reset_code = 39) + "\e[#{code}m#{self}\e[#{reset_code}m" + end + + def black = colourise(30) + def red = colourise(31) + def green = colourise(32) + def brown = colourise(33) + def yellow = colourise(33) + def blue = colourise(34) + def magenta = colourise(35) + def cyan = colourise(36) + def gray = colourise(37) alias grey gray - def bright_black = "\e[90m#{self}\e[0m" - - def bright_red = "\e[91m#{self}\e[0m" - - def bright_green = "\e[92m#{self}\e[0m" - - def bright_yellow = "\e[93m#{self}\e[0m" - - def bright_blue = "\e[94m#{self}\e[0m" - - def bright_magenta = "\e[95m#{self}\e[0m" - - def bright_cyan = "\e[96m#{self}\e[0m" - - def white = "\e[97m#{self}\e[0m" - - def bg_black = "\e[40m#{self}\e[0m" - - def bg_red = "\e[41m#{self}\e[0m" - - def bg_green = "\e[42m#{self}\e[0m" - - def bg_brown = "\e[43m#{self}\e[0m" - - def bg_blue = "\e[44m#{self}\e[0m" - - def bg_magenta = "\e[45m#{self}\e[0m" - - def bg_cyan = "\e[46m#{self}\e[0m" - - def bg_gray = "\e[47m#{self}\e[0m" - - def bold = "\e[1m#{self}\e[22m" - - def italic = "\e[3m#{self}\e[23m" - - def underline = "\e[4m#{self}\e[24m" - - def blink = "\e[5m#{self}\e[25m" - - def reverse_color = "\e[7m#{self}\e[27m" + def bright_black = colourise(90) + def bright_red = colourise(91) + def bright_green = colourise(92) + def bright_yellow = colourise(93) + def bright_blue = colourise(94) + def bright_magenta = colourise(95) + def bright_cyan = colourise(96) + def white = colourise(97) + + def bg_black = colourise(40, 49) + def bg_red = colourise(41, 49) + def bg_green = colourise(42, 49) + def bg_brown = colourise(43, 49) + def bg_blue = colourise(44, 49) + def bg_magenta = colourise(45, 49) + def bg_cyan = colourise(46, 49) + def bg_gray = colourise(47, 49) + + def bold = colourise(1, 22) + def italic = colourise(3, 23) + def underline = colourise(4, 24) + def blink = colourise(5, 25) + def reverse_color = colourise(7, 27) end diff --git a/spec/dvla/herodotus/string_spec.rb b/spec/dvla/herodotus/string_spec.rb index f0e83ef..cb179f1 100644 --- a/spec/dvla/herodotus/string_spec.rb +++ b/spec/dvla/herodotus/string_spec.rb @@ -2,31 +2,32 @@ RSpec.describe String do [ - { method: :black, expected_output: "\e[30mTest String\e[0m" }, - { method: :red, expected_output: "\e[31mTest String\e[0m" }, - { method: :green, expected_output: "\e[32mTest String\e[0m" }, - { method: :brown, expected_output: "\e[33mTest String\e[0m" }, - { method: :blue, expected_output: "\e[34mTest String\e[0m" }, - { method: :magenta, expected_output: "\e[35mTest String\e[0m" }, - { method: :cyan, expected_output: "\e[36mTest String\e[0m" }, - { method: :gray, expected_output: "\e[37mTest String\e[0m" }, - { method: :grey, expected_output: "\e[37mTest String\e[0m" }, - { method: :bright_black, expected_output: "\e[90mTest String\e[0m" }, - { method: :bright_red, expected_output: "\e[91mTest String\e[0m" }, - { method: :bright_green, expected_output: "\e[92mTest String\e[0m" }, - { method: :bright_yellow, expected_output: "\e[93mTest String\e[0m" }, - { method: :bright_blue, expected_output: "\e[94mTest String\e[0m" }, - { method: :bright_magenta, expected_output: "\e[95mTest String\e[0m" }, - { method: :bright_cyan, expected_output: "\e[96mTest String\e[0m" }, - { method: :white, expected_output: "\e[97mTest String\e[0m" }, - { method: :bg_black, expected_output: "\e[40mTest String\e[0m" }, - { method: :bg_red, expected_output: "\e[41mTest String\e[0m" }, - { method: :bg_green, expected_output: "\e[42mTest String\e[0m" }, - { method: :bg_brown, expected_output: "\e[43mTest String\e[0m" }, - { method: :bg_blue, expected_output: "\e[44mTest String\e[0m" }, - { method: :bg_magenta, expected_output: "\e[45mTest String\e[0m" }, - { method: :bg_cyan, expected_output: "\e[46mTest String\e[0m" }, - { method: :bg_gray, expected_output: "\e[47mTest String\e[0m" }, + { method: :black, expected_output: "\e[30mTest String\e[39m" }, + { method: :red, expected_output: "\e[31mTest String\e[39m" }, + { method: :green, expected_output: "\e[32mTest String\e[39m" }, + { method: :brown, expected_output: "\e[33mTest String\e[39m" }, + { method: :yellow, expected_output: "\e[33mTest String\e[39m" }, + { method: :blue, expected_output: "\e[34mTest String\e[39m" }, + { method: :magenta, expected_output: "\e[35mTest String\e[39m" }, + { method: :cyan, expected_output: "\e[36mTest String\e[39m" }, + { method: :gray, expected_output: "\e[37mTest String\e[39m" }, + { method: :grey, expected_output: "\e[37mTest String\e[39m" }, + { method: :bright_black, expected_output: "\e[90mTest String\e[39m" }, + { method: :bright_red, expected_output: "\e[91mTest String\e[39m" }, + { method: :bright_green, expected_output: "\e[92mTest String\e[39m" }, + { method: :bright_yellow, expected_output: "\e[93mTest String\e[39m" }, + { method: :bright_blue, expected_output: "\e[94mTest String\e[39m" }, + { method: :bright_magenta, expected_output: "\e[95mTest String\e[39m" }, + { method: :bright_cyan, expected_output: "\e[96mTest String\e[39m" }, + { method: :white, expected_output: "\e[97mTest String\e[39m" }, + { method: :bg_black, expected_output: "\e[40mTest String\e[49m" }, + { method: :bg_red, expected_output: "\e[41mTest String\e[49m" }, + { method: :bg_green, expected_output: "\e[42mTest String\e[49m" }, + { method: :bg_brown, expected_output: "\e[43mTest String\e[49m" }, + { method: :bg_blue, expected_output: "\e[44mTest String\e[49m" }, + { method: :bg_magenta, expected_output: "\e[45mTest String\e[49m" }, + { method: :bg_cyan, expected_output: "\e[46mTest String\e[49m" }, + { method: :bg_gray, expected_output: "\e[47mTest String\e[49m" }, { method: :bold, expected_output: "\e[1mTest String\e[22m" }, { method: :italic, expected_output: "\e[3mTest String\e[23m" }, { method: :underline, expected_output: "\e[4mTest String\e[24m" }, From 354a7dc811af32f3bf15c4cfd38d2fc0b0d24042 Mon Sep 17 00:00:00 2001 From: nialljames Date: Mon, 8 Sep 2025 07:32:35 +0100 Subject: [PATCH 2/4] alias yellow to brown --- lib/dvla/herodotus/string.rb | 3 ++- lib/dvla/herodotus/version.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/dvla/herodotus/string.rb b/lib/dvla/herodotus/string.rb index 7c337e8..1dada00 100644 --- a/lib/dvla/herodotus/string.rb +++ b/lib/dvla/herodotus/string.rb @@ -7,7 +7,8 @@ def black = colourise(30) def red = colourise(31) def green = colourise(32) def brown = colourise(33) - def yellow = colourise(33) + alias yellow brown + def blue = colourise(34) def magenta = colourise(35) def cyan = colourise(36) diff --git a/lib/dvla/herodotus/version.rb b/lib/dvla/herodotus/version.rb index e71da0d..86f55ec 100644 --- a/lib/dvla/herodotus/version.rb +++ b/lib/dvla/herodotus/version.rb @@ -1,5 +1,5 @@ module DVLA module Herodotus - VERSION = '2.1.0'.freeze + VERSION = '2.2.0'.freeze end end From 99310de5e145c9f21bbf3505ceb90e4b25c927c8 Mon Sep 17 00:00:00 2001 From: nialljames Date: Mon, 8 Sep 2025 07:46:19 +0100 Subject: [PATCH 3/4] alias colour --- lib/dvla/herodotus/string.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/dvla/herodotus/string.rb b/lib/dvla/herodotus/string.rb index 1dada00..ba3fc96 100644 --- a/lib/dvla/herodotus/string.rb +++ b/lib/dvla/herodotus/string.rb @@ -2,6 +2,7 @@ class String def colourise(code, reset_code = 39) "\e[#{code}m#{self}\e[#{reset_code}m" end + alias colourise colorize def black = colourise(30) def red = colourise(31) @@ -38,4 +39,5 @@ def italic = colourise(3, 23) def underline = colourise(4, 24) def blink = colourise(5, 25) def reverse_color = colourise(7, 27) + alias reverse_colour reverse_color end From 34a8d3644b87d0e6566e2be50da1ed3f79b9d249 Mon Sep 17 00:00:00 2001 From: nialljames Date: Mon, 8 Sep 2025 07:50:26 +0100 Subject: [PATCH 4/4] alias fix --- lib/dvla/herodotus/string.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/dvla/herodotus/string.rb b/lib/dvla/herodotus/string.rb index ba3fc96..bd0109b 100644 --- a/lib/dvla/herodotus/string.rb +++ b/lib/dvla/herodotus/string.rb @@ -2,7 +2,7 @@ class String def colourise(code, reset_code = 39) "\e[#{code}m#{self}\e[#{reset_code}m" end - alias colourise colorize + alias colorize colourise def black = colourise(30) def red = colourise(31)