Module: Fatty::Env

Extended by:
Env
Included in:
Env
Defined in:
lib/fatty/env.rb

Instance Method Summary collapse

Instance Method Details

#archObject



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_infoObject


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

#detectObject



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_programObject



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

#osObject


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

Returns:

  • (Boolean)


77
78
79
# File 'lib/fatty/env.rb', line 77

def screen?
  ENV.key?("STY")
end

#ssh?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/fatty/env.rb', line 81

def ssh?
  ENV.key?("SSH_TTY") || ENV.key?("SSH_CONNECTION")
end

#term_programObject


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

Returns:

  • (Boolean)


73
74
75
# File 'lib/fatty/env.rb', line 73

def tmux?
  ENV.key?("TMUX")
end