diff --git a/show/banner.go b/show/banner.go new file mode 100644 index 0000000..2203f5a --- /dev/null +++ b/show/banner.go @@ -0,0 +1,12 @@ +package show + +/* +eg: + ╭──────────────────────────────────────────────────────────────────╮ + │ │ + │ Update available! 3.21.0 → 3.27.0. │ + │ Changelog: https://github.com/gookit/gcli/releases/tag/v3.2.0 │ + │ Run "x y z" to update. │ + │ │ + ╰──────────────────────────────────────────────────────────────────╯ +*/ diff --git a/show/emoji/emoji.go b/show/emoji/emoji.go index 3189c41..7200b4a 100644 --- a/show/emoji/emoji.go +++ b/show/emoji/emoji.go @@ -1,13 +1,12 @@ package emoji import ( - "bytes" "regexp" "strconv" "strings" ) -var nameMatch = regexp.MustCompile(`(:\w+:)`) +var codeMatch = regexp.MustCompile(`(:\w+:)`) // Emoji is alias of the GetByName() func Emoji(name string) string { @@ -15,7 +14,7 @@ func Emoji(name string) string { } // GetByName returns the unicode value for the given emoji name. If the -// specified emoji does not exist, will returns the input string. +// specified emoji does not exist, will return the input string. func GetByName(name string) string { if val, ok := emojiMap[name]; ok { return val @@ -50,23 +49,27 @@ func Search(kw string, limits ...int) (ret map[string]string) { } // Render a string, parse emoji name, returns rendered string. +// // Usage: -// msg := Render("a :smile: message") -// fmt.Println(msg) +// +// msg := Render("a :smile: message") +// fmt.Println(msg) func Render(str string) string { // not contains emoji name. if strings.IndexByte(str, ':') == -1 { return str } - return nameMatch.ReplaceAllStringFunc(str, func(name string) string { + return codeMatch.ReplaceAllStringFunc(str, func(name string) string { return GetByName(name) // + " " }) } // FromUnicode unicode string to emoji string +// // Usage: -// emoji := FromUnicode("\U0001f496") +// +// emoji := FromUnicode("\U0001f496") func FromUnicode(s string) string { // emoji表情的数据表达式 re := regexp.MustCompile("\\[[\\\\u0-9a-zA-Z]+\\]") @@ -84,32 +87,36 @@ func FromUnicode(s string) string { return s } -// ToUnicode unicode string to emoji string +// ToUnicode convert emoji to unicode string // Usage: -// unicode := ToUnicode("💖") -// fmt.Print(unicode) // "1f496" -// // with prefix -// unicode := ToUnicode("💖", "\U000") // "\U0001f496" -// fmt.Print(unicode) // "💖" +// +// unicode := ToUnicode("💖") +// fmt.Print(unicode) // "1f496" +// +// // with prefix +// unicode := ToUnicode("💖", "\U000") // "\U0001f496" +// fmt.Print(unicode) // "💖" func ToUnicode(emoji string, prefix ...string) string { code := strconv.FormatInt(int64(emoji[0]), 16) if len(prefix) > 0 { return prefix[0] + code } - return code } // Decode a string, convert unicode to emoji chat +// // Usage: -// str := Decode("a msg [\u1f496]") +// +// str := Decode("a msg [\u1f496]") func Decode(s string) string { // emoji表情的数据表达式 re := regexp.MustCompile("\\[[\\\\u0-9a-zA-Z]+\\]") // 提取emoji数据表达式 reg := regexp.MustCompile("\\[\\\\u|]") src := re.FindAllString(s, -1) + for i := 0; i < len(src); i++ { e := reg.ReplaceAllString(src[i], "") p, err := strconv.ParseInt(e, 16, 32) @@ -123,17 +130,15 @@ func Decode(s string) string { // Encode a string, convert emoji chat to unicode string func Encode(s string) string { - rs := []rune(s) - buf := new(bytes.Buffer) - - for _, r := range rs { + var sb strings.Builder + for _, r := range []rune(s) { if len(string(r)) == 4 { // is unicode emoji char code := strconv.FormatInt(int64(r), 16) - buf.WriteString(`[\u` + code + `]`) + sb.WriteString(`[\u` + code + `]`) } else { - buf.WriteRune(r) + sb.WriteRune(r) } } - return buf.String() + return sb.String() } diff --git a/show/emoji/some-record.md b/show/emoji/some-record.md index dc34170..2d12410 100644 --- a/show/emoji/some-record.md +++ b/show/emoji/some-record.md @@ -15,9 +15,11 @@ wget -qO- https://unicode.org/Public/emoji/11.0/emoji-test.txt | cut -f 1 -d ' ' ## data links: -- https://www.unicode.org/Public/emoji/11.0/ +- https://unicode.org/Public/emoji/15.0/emoji-sequences.txt - https://raw.githubusercontent.com/github/gemoji/master/db/emoji.json -- https://raw.githubusercontent.com/muan/emoji/gh-pages/javascripts/emojilib/emojis.json +- https://github.com/muan/emojilib/blob/main/dist/emoji-en-US.json +- https://github.com/muan/unicode-emoji-json/blob/main/data-by-emoji.json +- https://www.unicode.org/Public/emoji/11.0/ ## sites