module RabbotMetaColorsReport
Constants
- IRC_TAG
- MAX_GROUP_BODY_LINES
- MAX_PAIRS_BODY_LINES
- STYLE_TITLE
- SWATCHES_PER_LINE
Public Instance Methods
Source
# File lib/rabbot_meta_colors_report.rb, line 43 def format_code(code) hex = IrcExtendedColors.rgb(code) group = IrcExtendedColors.group(code) swatch = IrcExtendedColors.swatch(code) IrcReply.card( tag: IRC_TAG, title: "Colour #{code}", body_lines: [ "#{swatch} #{code} · ##{hex} · #{IrcExtendedColors.group_label(group)}", "Control code: \\003#{code.to_s.rjust(2, '0')}" ], footer_parts: ["extended colour", "ircdocs.horse"], heading_style: STYLE_TITLE ) end
Source
# File lib/rabbot_meta_colors_report.rb, line 112 def format_group(name) codes = IrcExtendedColors.codes_for_group(name) label = IrcExtendedColors.group_label(name) body = codes.each_slice(SWATCHES_PER_LINE).take(MAX_GROUP_BODY_LINES).map do |slice| slice.map { |code| "#{IrcExtendedColors.swatch(code)}#{code}" }.join(" ") end IrcReply.card( tag: IRC_TAG, title: "Group — #{label}", body_lines: body, footer_parts: ["#{codes.first}–#{codes.last}", "#{codes.length} colours"], heading_style: STYLE_TITLE ) end
Source
# File lib/rabbot_meta_colors_report.rb, line 23 def format_help group_lines = IrcExtendedColors::GROUPS.map do |name, codes| "— #{name} — #{codes.first}–#{codes.last} (#{codes.length} fixed colours)" end IrcReply.card( tag: IRC_TAG, title: "Extended mIRC colours", body_lines: [ "Fixed RGB palette 16–98 (same for all IRC users). Theme colours 0–15 vary by client.", *group_lines, "Named pairs: !rabbot colors pairs · !rabbot colors title", "Themes: !rabbot colors themes · !rabbot colors neon · !rabbot colors spectrum", "Usage: !rabbot colors · !rabbot colors 52 · !rabbot colors 59,88 · !rabbot colors vivid" ], footer_parts: ["mIRC extended palette", "16–98"], heading_style: STYLE_TITLE ) end
Source
# File lib/rabbot_meta_colors_report.rb, line 86 def format_named_pair(name, fg, bg) format_pair(fg, bg, name: name) end
Source
# File lib/rabbot_meta_colors_report.rb, line 60 def format_pair(fg, bg, name: nil) swatch = IrcExtendedColors.swatch(fg, bg: bg) fg_hex = IrcExtendedColors.extended?(fg) ? "##{IrcExtendedColors.rgb(fg)}" : "theme" bg_hex = IrcExtendedColors.extended?(bg) ? "##{IrcExtendedColors.rgb(bg)}" : "theme" title = if name "Pair — #{name} (#{fg},#{bg})" else "Colour pair #{fg},#{bg}" end body = [ "#{swatch} Sample text", "fg #{fg} #{fg_hex} · bg #{bg} #{bg_hex}", "Contrast: #{pair_contrast_hint(fg, bg)}" ] role = name ? IrcExtendedColors.pair_role(name) : nil body.insert(1, "Role: #{role}") if role IrcReply.card( tag: IRC_TAG, title: title, body_lines: body, footer_parts: ["fg,bg preview", "IrcFormat.color"], heading_style: STYLE_TITLE ) end
Source
# File lib/rabbot_meta_colors_report.rb, line 90 def format_pairs_list rows = IrcExtendedColors.pair_names.map do |name| fg, bg = IrcExtendedColors.resolve_pair(name) swatch = IrcExtendedColors.swatch(fg, bg: bg) extended = IrcExtendedColors.pair_extended?(name) ? "fixed" : "theme" { label: name.to_s, value: "#{swatch}#{fg},#{bg} (#{extended})" } end body = TextAlign.format_colon_rows(rows).take(MAX_PAIRS_BODY_LINES) total = IrcExtendedColors.pair_names.length IrcReply.card( tag: IRC_TAG, title: "Named colour pairs", body_lines: body, footer_parts: ["#{total} pairs", "!rabbot colors title"], heading_style: STYLE_TITLE ) end
Source
# File lib/rabbot_meta_colors_report.rb, line 128 def pair_contrast_hint(fg, bg) fg = fg.to_i bg = bg.to_i return "invisible (same fg and bg)" if fg == bg return "readable (vivid fg on dark bg)" if (52..63).cover?(fg) && (88..92).cover?(bg) return "readable (dark fg on light bg)" if (88..89).cover?(fg) && (96..98).cover?(bg) "check on your client" end