lib/cli/ui/os.rb in cli-ui-1.5.1 vs lib/cli/ui/os.rb in cli-ui-2.0.0

- old
+ new

@@ -1,67 +1,63 @@ +# typed: true + require 'rbconfig' module CLI module UI - module OS - # Determines which OS is currently running the UI, to make it easier to - # adapt its behaviour to the features of the OS. - def self.current - @current_os ||= case RbConfig::CONFIG['host_os'] - when /darwin/ - Mac - when /linux/ - Linux - else - if RUBY_PLATFORM !~ /cygwin/ && ENV['OS'] == 'Windows_NT' - Windows - else - raise "Could not determine OS from host_os #{RbConfig::CONFIG["host_os"]}" - end - end + class OS + extend T::Sig + + sig { params(emoji: T::Boolean, color_prompt: T::Boolean, arrow_keys: T::Boolean, shift_cursor: T::Boolean).void } + def initialize(emoji: true, color_prompt: true, arrow_keys: true, shift_cursor: false) + @emoji = emoji + @color_prompt = color_prompt + @arrow_keys = arrow_keys + @shift_cursor = shift_cursor end - class Mac - class << self - def supports_emoji? - true - end + sig { returns(T::Boolean) } + def use_emoji? + @emoji + end - def supports_color_prompt? - true - end + sig { returns(T::Boolean) } + def use_color_prompt? + @color_prompt + end - def supports_arrow_keys? - true - end - - def shift_cursor_on_line_reset? - false - end - end + sig { returns(T::Boolean) } + def suggest_arrow_keys? + @arrow_keys end - class Linux < Mac + sig { returns(T::Boolean) } + def shift_cursor_back_on_horizontal_absolute? + @shift_cursor end - class Windows - class << self - def supports_emoji? - false - end + class << self + extend T::Sig - def supports_color_prompt? - false + sig { returns(OS) } + def current + @current_os ||= case RbConfig::CONFIG['host_os'] + when /darwin/ + MAC + when /linux/ + LINUX + else + if RUBY_PLATFORM !~ /cygwin/ && ENV['OS'] == 'Windows_NT' + WINDOWS + else + raise "Could not determine OS from host_os #{RbConfig::CONFIG["host_os"]}" + end end - - def supports_arrow_keys? - false - end - - def shift_cursor_on_line_reset? - true - end end end + + MAC = OS.new + LINUX = OS.new + WINDOWS = OS.new(emoji: false, color_prompt: false, arrow_keys: false, shift_cursor: true) end end end