Module: Fatty::Env
Instance Method Summary collapse
- #arch ⇒ Object
-
#curses_info ⇒ Object
----------------------- ncurses capabilities -----------------------.
- #detect ⇒ Object
- #detect_terminal_program ⇒ Object
-
#os ⇒ Object
----------------------- OS / platform -----------------------.
- #screen? ⇒ Boolean
- #ssh? ⇒ Boolean
-
#term_program ⇒ Object
----------------------- Terminal identity -----------------------.
- #tmux? ⇒ Boolean
Instance Method Details
#arch ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/fatty/env.rb', line 36 def arch case RUBY_PLATFORM when /x86_64/ then :x86_64 when /arm64|aarch64/ then :arm64 else :unknown end end |
#curses_info ⇒ Object
ncurses capabilities
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/fatty/env.rb', line 89 def curses_info return {} unless defined?(::Curses) { key_min: ::Curses::KEY_MIN, key_max: ::Curses::KEY_MAX, } rescue StandardError {} end |
#detect ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/fatty/env.rb', line 7 def detect { os: os, arch: arch, ruby_platform: RUBY_PLATFORM, term: ENV["TERM"], terminal: detect_terminal_program, terminal_version: ENV["KONSOLE_VERSION"] || ENV["TERM_PROGRAM_VERSION"], tmux: tmux?, screen: screen?, ssh: ssh?, curses: curses_info, } end |
#detect_terminal_program ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/fatty/env.rb', line 53 def detect_terminal_program return "tmux" if ENV.key?("TMUX") return "screen" if ENV.key?("STY") return "konsole" if ENV.key?("KONSOLE_VERSION") return "kitty" if ENV.key?("KITTY_WINDOW_ID") return "wezterm" if ENV["TERM_PROGRAM"]&.downcase == "wezterm" return "iterm" if ENV["TERM_PROGRAM"] == "iTerm.app" return "ghostty" if ENV["TERM_PROGRAM"]&.downcase == "ghostty" return "alacritty" if ENV.key?("ALACRITTY_LOG") return "terminator" if ENV.key?("TERMINATOR_UUID") if ENV.key?("TERM_PROGRAM") ENV["TERM_PROGRAM"]&.downcase elsif ENV.key?("TERM") ENV["TERM"]&.downcase else 'unknown' end end |
#os ⇒ Object
OS / platform
26 27 28 29 30 31 32 33 34 |
# File 'lib/fatty/env.rb', line 26 def os case RUBY_PLATFORM when /linux/ then :linux when /darwin/ then :darwin when /bsd/ then :bsd when /mswin|mingw|cygwin/ then :windows else :unknown end end |
#screen? ⇒ Boolean
77 78 79 |
# File 'lib/fatty/env.rb', line 77 def screen? ENV.key?("STY") end |
#ssh? ⇒ Boolean
81 82 83 |
# File 'lib/fatty/env.rb', line 81 def ssh? ENV.key?("SSH_TTY") || ENV.key?("SSH_CONNECTION") end |
#term_program ⇒ Object
Terminal identity
48 49 50 51 |
# File 'lib/fatty/env.rb', line 48 def term_program ENV["TERM_PROGRAM"]&.downcase || ENV["COLORTERM"]&.downcase end |
#tmux? ⇒ Boolean
73 74 75 |
# File 'lib/fatty/env.rb', line 73 def tmux? ENV.key?("TMUX") end |