module IrcExtendedColors
Constants
- BUILTIN_THEME_IDS
- EXTENDED_MAX
- EXTENDED_MIN
- GROUPS
- GROUP_ALIASES
- NAMED_PAIRS
-
Named fg/bg pairs for themes and !rabbot colors lookup (classic 0–15 and fixed extended 16–98).
- RGB
- SPECTRUM_MAX
- SPECTRUM_MIN
- SWATCH_CHAR
Public Instance Methods
Source
# File lib/irc_extended_colors.rb, line 107 def codes_for_group(name) symbol = resolve_group(name) return [] unless symbol GROUPS[symbol].dup end
Source
# File lib/irc_extended_colors.rb, line 79 def extended?(code) (EXTENDED_MIN..EXTENDED_MAX).cover?(code.to_i) end
Source
# File lib/irc_extended_colors.rb, line 87 def group(code) value = code.to_i GROUPS.each do |name, codes| return name if codes.include?(value) end nil end
Source
# File lib/irc_extended_colors.rb, line 95 def group_label(name) name.to_s.tr("_", " ") end
Source
# File lib/irc_extended_colors.rb, line 132 def pair_extended?(name) fg, bg = resolve_pair(name) return false unless fg && bg extended?(fg) && extended?(bg) end
Source
# File lib/irc_extended_colors.rb, line 114 def pair_names NAMED_PAIRS.keys.sort end
Source
# File lib/irc_extended_colors.rb, line 126 def pair_role(name) key = name.to_s.strip.downcase.to_sym entry = NAMED_PAIRS[key] entry ? entry[:role] : nil end
Source
# File lib/irc_extended_colors.rb, line 150 def parse_query(text) query = text.to_s.strip return [:help] if query.empty? if query.include?(",") spec = IrcFormat.parse_colour_spec(query) return [:error, spec[:error]] if spec[:error] return [:pair, spec[:fg], spec[:bg]] end if query.match?(/\A\d+\z/) code = query.to_i return [:code, code] if extended?(code) unless IrcFormat.valid_color?(code) return [:error, "Invalid colour — use fg or fg,bg (0-98)."] end return [:error, "Colour #{code} is theme-dependent (0–15). Extended fixed colours are 16–98."] end return [:pairs] if query.casecmp?("pairs") return [:themes] if query.casecmp?("themes") return [:spectrum] if query.casecmp?("spectrum") || query.match?(/\A49(?:-|\.{2})98\z/) if (match = query.match(/\Atheme\s+(\S+)\z/i)) theme_id = resolve_theme_id(match[1]) return [:theme, theme_id] if theme_id return [:error, "Unknown theme #{match[1].inspect}. Try: !rabbot colors themes"] end if (pair = resolve_pair(query)) fg, bg = pair return [:named_pair, query.to_s.strip.downcase.to_sym, fg, bg] end if (theme_id = resolve_theme_id(query)) return [:theme, theme_id] end group = resolve_group(query) return [:group, group] if group names = pair_names.map(&:to_s).join(", ") [:error, "Unknown pair, theme, or group #{query.inspect}. Try: pairs, themes, spectrum, #{names}, or #{GROUPS.keys.join(', ')}."] end
Source
# File lib/irc_extended_colors.rb, line 99 def resolve_group(name) key = name.to_s.strip.downcase return nil if key.empty? symbol = GROUP_ALIASES[key] || key.to_sym GROUPS.key?(symbol) ? symbol : nil end
Source
# File lib/irc_extended_colors.rb, line 118 def resolve_pair(name) key = name.to_s.strip.downcase.to_sym entry = NAMED_PAIRS[key] return nil unless entry [entry[:fg], entry[:bg]] end
Source
# File lib/irc_extended_colors.rb, line 143 def resolve_theme_id(name) id = name.to_s.strip.downcase return nil if id.empty? BUILTIN_THEME_IDS.include?(id) ? id.to_sym : nil end
Source
# File lib/irc_extended_colors.rb, line 139 def spectrum_codes (SPECTRUM_MIN..SPECTRUM_MAX).to_a end
Source
# File lib/irc_extended_colors.rb, line 197 def style(code, bg: nil) IrcFormat.color(code, bg) end
Source
# File lib/irc_extended_colors.rb, line 205 def swatch(code, bg: nil) style_code = bg ? style(code, bg: bg) : style(code) "#{style_code}#{SWATCH_CHAR}#{IrcFormat::RESET}" end