From 5340bdc21ee54549d39a1d63736cea916049da78 Mon Sep 17 00:00:00 2001 From: "Abinoam P. Marques Jr" Date: Wed, 18 Oct 2017 23:00:16 -0300 Subject: Copy use_color from HighLine.default_instance This is gonna help people migrating code from 1.7.x to 2.0.x. At 1.7.x if you set HighLine.use_color to anything, the effect would be global. At 2.0.x this setting is saved per instance and were being default to true. With this commit, newly instantiated HighLine instances will copy use_color setting from the HighLine defaul_instance wich mimicks the behaviour at 1.7.x. The main difference is, as soon as an instance come to life, HighLine.use_color (class method) will have no effect on the instance use_color setting. --- lib/highline.rb | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/highline.rb b/lib/highline.rb index b51a1a0..33ab7eb 100755 --- a/lib/highline.rb +++ b/lib/highline.rb @@ -115,9 +115,9 @@ class HighLine @header = nil @prompt = nil @key = nil - @use_color = true - @track_eof = true # The setting used to disable EOF tracking. + @use_color = default_use_color + @track_eof = true # The setting used to disable EOF tracking. @terminal = HighLine::Terminal.get_terminal(input, output) end @@ -619,6 +619,21 @@ class HighLine def actual_length(text) Wrapper.actual_length text end + + # Check to see if there's already a HighLine.default_instance or if + # this is the first time the method is called (eg: at + # HighLine.default_instance initialization). + # If there's already one, copy use_color settings. + # This is here most to help migrate code from HighLine 1.7.x to 2.0.x + # + # @return [Boolean] + def default_use_color + if HighLine.default_instance + HighLine.default_instance.use_color + else + true + end + end end HighLine.default_instance = HighLine.new -- cgit v1.2.1