Documentation
¶
Index ¶
- Constants
- Variables
- func AppendMessageSuffix(msg, suffix string) string
- func EmojiFromAlias(alias string, customAliases map[string]string) (string, bool)
- func EmojiReplaceAliases(s string, customAliases map[string]string) string
- func ExpandDirectoryURL(tmpl, nick, username string, extra ...string) string
- func FindClosestIRCColor(hexColor string) string
- func FormatActionSuffix(kind ActionSuffixKind, useUnicode bool) string
- func FormatAndShortenSummary(text string, opts SummaryOpts) string
- func FormatFullCodeBlock(text, lexer, indent string, opts ProcessMessageOpts, yield func(string))
- func FormatLastOnline(lastActivity int64, isOnline ...bool) string
- func FormatMarkdownAndEmoji(msg string, disableMarkdown bool, disableEmoji bool, blockQuoteChar string, ...) string
- func Irc2Markdown(msg string) string
- func Markdown2irc(msg string, blockQuoteChar string, inlineCode string) string
- func ProcessMessageText(text string, opts ProcessMessageOpts, yield func(line string))
- func SanitizeDefaultMentions(text string, useUnicode bool) string
- func StringWidth(s string) int
- func WrapMessage(msg string, maxLen int, hardLineSplit ...bool) string
- type ActionSuffixKind
- type IRCColor
- type ProcessMessageOpts
- type SkinTone
- type SummaryOpts
Constants ¶
const ( AttachmentMarkerStart = "\x00<ATTM>\x00" AttachmentMarkerEnd = "\x00</ATTM>\x00" )
const BlockQuoteCharDefault = ">"
Variables ¶
var GetEmojiMap = sync.OnceValue(func() map[string]string { data := emoji.Gemoji() aliasMap := make(map[string]string, (len(data)*6)+len(defaultAliases)) register := func(name string, unicodeVal string, supportsSkinTone bool) { if name == "" { return } if _, exists := aliasMap[name]; !exists { aliasMap[name] = unicodeVal } if !supportsSkinTone { return } for _, st := range skinToneSuffixes { variantKey := name + st.suffix if _, exists := aliasMap[variantKey]; !exists { aliasMap[variantKey] = applySkinTone(unicodeVal, st.tone) } } } registerWithVariants := func(name string, unicodeVal string, supportsSkinTone bool) { register(name, unicodeVal, supportsSkinTone) if strings.ContainsRune(name, '-') { register(strings.ReplaceAll(name, "-", "_"), unicodeVal, supportsSkinTone) } if len(name) == 2 && len(unicodeVal) == 8 && unicodeVal[:3] == "\xf0\x9f\x87" && unicodeVal[4:7] == "\xf0\x9f\x87" && unicodeVal[3] >= 0xA6 && unicodeVal[3] <= 0xBF && unicodeVal[7] >= 0xA6 && unicodeVal[7] <= 0xBF { register("flag_"+name, unicodeVal, supportsSkinTone) register("flag-"+name, unicodeVal, supportsSkinTone) } else if rest, ok := strings.CutPrefix(name, "flag_"); ok { register("flag-"+rest, unicodeVal, supportsSkinTone) } if rest, ok := strings.CutPrefix(name, "flight_"); ok { register("airplane_"+rest, unicodeVal, supportsSkinTone) register("airplane-"+strings.ReplaceAll(rest, "_", "-"), unicodeVal, supportsSkinTone) if rest == "arrival" { register("airplane_arriving", unicodeVal, supportsSkinTone) register("airplane-arriving", unicodeVal, supportsSkinTone) } } else if rest, ok := strings.CutPrefix(name, "airplane_"); ok { register("flight_"+rest, unicodeVal, supportsSkinTone) register("flight-"+strings.ReplaceAll(rest, "_", "-"), unicodeVal, supportsSkinTone) if rest == "arriving" { register("flight_arrival", unicodeVal, supportsSkinTone) register("flight-arrival", unicodeVal, supportsSkinTone) } } if rest, ok := strings.CutSuffix(name, "_man"); ok { register("man_"+rest, unicodeVal, supportsSkinTone) register("man-"+strings.ReplaceAll(rest, "_", "-"), unicodeVal, supportsSkinTone) } else if rest, ok := strings.CutSuffix(name, "_woman"); ok { register("woman_"+rest, unicodeVal, supportsSkinTone) register("woman-"+strings.ReplaceAll(rest, "_", "-"), unicodeVal, supportsSkinTone) } else if rest, ok := strings.CutPrefix(name, "male_"); ok { register("man_"+rest, unicodeVal, supportsSkinTone) register("man-"+strings.ReplaceAll(rest, "_", "-"), unicodeVal, supportsSkinTone) } else if rest, ok := strings.CutPrefix(name, "female_"); ok { register("woman_"+rest, unicodeVal, supportsSkinTone) register("woman-"+strings.ReplaceAll(rest, "_", "-"), unicodeVal, supportsSkinTone) } } for _, e := range data { if e.Emoji == "" { continue } if len(e.Emoji) == 8 && e.Emoji[0] == 0xF0 && e.Emoji[1] == 0x9F && e.Emoji[2] == 0x87 && e.Emoji[4] == 0xF0 && e.Emoji[5] == 0x9F && e.Emoji[6] == 0x87 { c1 := 'a' + (e.Emoji[3] - 0xA6) c2 := 'a' + (e.Emoji[7] - 0xA6) if c1 >= 'a' && c1 <= 'z' && c2 >= 'a' && c2 <= 'z' { code := string([]byte{c1, c2}) registerWithVariants(code, e.Emoji, false) } } for _, alias := range e.Aliases { registerWithVariants(alias, e.Emoji, e.SkinTones) if e.Category == "Flags" && !strings.HasPrefix(alias, "flag") { registerWithVariants("flag_"+alias, e.Emoji, false) registerWithVariants("flag-"+alias, e.Emoji, false) } } } for _, e := range data { if e.Emoji == "" { continue } for _, tag := range e.Tags { registerWithVariants(tag, e.Emoji, e.SkinTones) } } for alias, target := range defaultAliases { targetClean := trimColons(target) if unicodeVal, exists := aliasMap[targetClean]; exists { registerWithVariants(alias, unicodeVal, true) } } return aliasMap })
GetEmojiMap initializes and returns the immutable alias-to-Unicode map once using Go 1.21+ sync.OnceValue.
Functions ¶
func AppendMessageSuffix ¶ added in v0.35.0
AppendMessageSuffix appends a formatted suffix (such as a reply context or action suffix) to msg, stripping trailing newlines and placing single-line CTCP ACTION suffixes inside \x01.
func EmojiFromAlias ¶ added in v0.31.0
EmojiFromAlias looks up an emoji by shortcode, supporting with or without surrounding colons.
func EmojiReplaceAliases ¶ added in v0.31.0
EmojiReplaceAliases scans the input and replaces :alias: tokens with Unicode emojis.
func ExpandDirectoryURL ¶ added in v0.35.0
ExpandDirectoryURL expands {nick}, {username}, {email}, {firstname}, and {lastname} placeholders in a DirectoryURL template, escaping them appropriately for the path and query components.
func FindClosestIRCColor ¶ added in v0.32.0
FindClosestIRCColor uses the precalculated palette to quickly find the nearest match.
func FormatActionSuffix ¶ added in v0.35.0
func FormatActionSuffix(kind ActionSuffixKind, useUnicode bool) string
FormatActionSuffix returns the italicized IRC suffix for a message state change.
func FormatAndShortenSummary ¶ added in v0.32.0
func FormatAndShortenSummary(text string, opts SummaryOpts) string
FormatAndShortenSummary formats markdown/emoji, collapses newlines, and shortens text.
func FormatFullCodeBlock ¶ added in v0.32.0
func FormatFullCodeBlock(text, lexer, indent string, opts ProcessMessageOpts, yield func(string))
FormatFullCodeBlock handles syntax highlighting entirely in-memory and yields lines
func FormatLastOnline ¶ added in v0.35.0
FormatLastOnline formats a Unix timestamp (seconds) as a human-readable "Last online ..." or "Last activity ..." string for WHOIS output.
func FormatMarkdownAndEmoji ¶ added in v0.32.0
func FormatMarkdownAndEmoji(msg string, disableMarkdown bool, disableEmoji bool, blockQuoteChar string, inlineCode string, customEmoji map[string]string) string
FormatMarkdownAndEmoji applies Markdown formatting and Emoji alias replacement. It utilizes a fast-path single-pass check to bypass processing entirely if no trigger characters are present, drastically reducing allocations and CPU usage.
func Irc2Markdown ¶ added in v0.33.0
Irc2Markdown converts IRC formatting back to Markdown, handling links and text styles.
func ProcessMessageText ¶ added in v0.32.0
func ProcessMessageText(text string, opts ProcessMessageOpts, yield func(line string))
ProcessMessageText abstracts the parsing loop, multi-line code handling, and formatting. It uses a zero-allocation callback (yield) to return lines.
func SanitizeDefaultMentions ¶ added in v0.34.0
SanitizeDefaultMentions defangs @channel, @all, @here, @everyone, and Matrix @room mentions to prevent unwanted highlights in IRC clients. When useUnicode is enabled, it inserts a Zero-Width Non-Joiner (ZWNJ) after the '@'. When disabled, it inserts a hyphen.
func StringWidth ¶ added in v0.34.0
StringWidth returns the visual cell width of a string in a monospace terminal, accounting for East Asian wide characters, combining marks, format characters, regional indicator pairs (flags), and emoji sequences.
func WrapMessage ¶ added in v0.31.0
WrapMessage soft-wraps msg into lines of at most maxLen bytes, breaking only at spaces/newlines. Words longer than maxLen are left unbroken and overflow their line rather than being split unless hardLineSplit is enabled.
Types ¶
type ActionSuffixKind ¶ added in v0.35.0
type ActionSuffixKind string
ActionSuffixKind identifies a message state suffix appended to IRC messages.
const ( SuffixEdited ActionSuffixKind = "edited" SuffixPinned ActionSuffixKind = "pinned" SuffixUnpinned ActionSuffixKind = "unpinned" SuffixUpdated ActionSuffixKind = "updated" SuffixDeleted ActionSuffixKind = "deleted" SuffixEncrypted ActionSuffixKind = "encrypted" )
type IRCColor ¶ added in v0.32.0
IRCColor represents a pre-parsed IRC color for fast distance calculations.
type ProcessMessageOpts ¶ added in v0.32.0
type ProcessMessageOpts struct {
DisableEmoji bool
CustomEmoji map[string]string
DisableMarkdown bool
SyntaxHighlighting string
CodeBlockPrefix string
CodeBlockSeparator string
BlockquoteChar string
InlineCodeChar string
PreserveNewLines string // "all" (default), "max-one", or "none" / "zero"
}
ProcessMessageOpts holds the configuration for text processing