summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbinoam P. Marques Jr <abinoam@gmail.com>2017-10-18 23:00:16 -0300
committerAbinoam P. Marques Jr <abinoam@gmail.com>2017-10-19 00:00:34 -0300
commit5340bdc21ee54549d39a1d63736cea916049da78 (patch)
treeea73b0a3374c9a697fd8cc2a0451b865a3c07f1e
parentd53851be0d545453e58439c8faca98f4fbdebf40 (diff)
downloadhighline-5340bdc21ee54549d39a1d63736cea916049da78.tar.gz
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.
-rwxr-xr-xlib/highline.rb19
1 files changed, 17 insertions, 2 deletions
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