From 954259a513f01e27ca72958d4d8157df1708d9f7 Mon Sep 17 00:00:00 2001 From: r-obert Date: Mon, 23 Oct 2017 22:46:32 +0200 Subject: [PATCH] Add utility functions for drawing colorised (#1673) text on a colorised background. --- CHANGELOG.md | 3 +++ lib/pry/helpers/text.rb | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8483977..3251927d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ * Add `mac_osx?` and `linux?` utility functions to Pry::Helpers::BaseHelpers. [#1668](https://github.com/pry/pry/pull/1668) +* Add utility functions for drawing colorised text on a colorised background. +[#1673](https://github.com/pry/pry/pull/1673) + #### Bug fixes * Fix `String#pp` output color. [#1674](https://github.com/pry/pry/pull/1674) diff --git a/lib/pry/helpers/text.rb b/lib/pry/helpers/text.rb index 22aecccd..6c171da7 100644 --- a/lib/pry/helpers/text.rb +++ b/lib/pry/helpers/text.rb @@ -24,6 +24,16 @@ class Pry define_method "bright_#{color}" do |text| "\033[1;#{30+value}m#{text}\033[0m" end + + COLORS.each_pair do |bg_color, bg_value| + define_method "#{color}_on_#{bg_color}" do |text| + "\033[0;#{30 + value};#{40 + bg_value}m#{text}\033[0m" + end + + define_method "bright_#{color}_on_#{bg_color}" do |text| + "\033[1;#{30 + value};#{40 + bg_value}m#{text}\033[0m" + end + end end # Remove any color codes from _text_.