Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Determine color usage dynamically #296

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/kafo/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Configuration
ScenarioOption::ANSWER_FILE => './config/answers.yaml',
ScenarioOption::INSTALLER_DIR => '.',
ScenarioOption::MODULE_DIRS => ['./modules'],
ScenarioOption::COLORS => Kafo::ColorScheme.colors_possible?,
ScenarioOption::COLORS => nil,
ScenarioOption::COLOR_OF_BACKGROUND => :dark,
ScenarioOption::HOOK_DIRS => [],
ScenarioOption::CHECK_DIRS => nil,
Expand Down Expand Up @@ -107,6 +107,10 @@ def app
end
end

def use_colors?
app.fetch(ScenarioOption::COLORS) { Kafo::ColorScheme.colors_possible? }
end

def get_custom(key)
custom_storage[key.to_sym]
end
Expand Down
14 changes: 8 additions & 6 deletions lib/kafo/kafo_configure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@ def help(*args)

def use_colors?
if config
colors = config.app[:colors]
config.use_colors?
elsif ARGV.include?('--no-colors')
false
elsif ARGV.include?('--colors')
true
else
colors = ARGV.include?('--no-colors') ? false : nil
colors = ARGV.include?('--colors') ? true : nil if colors.nil?
Kafo::ColorScheme.colors_possible?
end
colors
end

def preset_color_scheme
Expand Down Expand Up @@ -190,7 +192,7 @@ def execute
parse_cli_arguments

if !config.app[:verbose]
@progress_bar = config.app[:colors] ? ProgressBars::Colored.new : ProgressBars::BlackWhite.new
@progress_bar = config.use_colors? ? ProgressBars::Colored.new : ProgressBars::BlackWhite.new
end

unless skip_checks_i_know_better?
Expand Down Expand Up @@ -347,7 +349,7 @@ def terminal_log_levels_message

def set_app_options
app_option ['--[no-]colors'], :flag, 'Use color output on STDOUT',
:default => config.app[:colors], :advanced => true
:default => config.use_colors?, :advanced => true
app_option ['--color-of-background'], 'COLOR', 'Your terminal background is :bright or :dark',
:default => config.app[:color_of_background], :advanced => true
app_option ['--dont-save-answers'], :flag, "Skip saving answers to '#{self.class.config.answer_file}'?",
Expand Down