mirror of
https://github.com/Rudi9719/kbtui.git
synced 2026-03-22 12:07:23 +00:00
removed dynamic emoji building
This commit is contained in:
77
mage.go
77
mage.go
@ -3,85 +3,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/magefile/mage/mg"
|
|
||||||
"github.com/magefile/mage/sh"
|
"github.com/magefile/mage/sh"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// emoji related constants
|
|
||||||
const emojiList = "https://raw.githubusercontent.com/CodeFreezr/emojo/master/db/v5/emoji-v5.json"
|
|
||||||
const emojiFileName = "emojiList.go"
|
|
||||||
|
|
||||||
// json parsing structure
|
|
||||||
type emoji struct {
|
|
||||||
Num int `json:"No"`
|
|
||||||
Emoji string `json:"Emoji"`
|
|
||||||
Category string `json:"Category"`
|
|
||||||
SubCategory string `json:"SubCategory"`
|
|
||||||
Unicode string `json:"Unicode"`
|
|
||||||
Name string `json:"Name"`
|
|
||||||
Tags string `json:"Tags"`
|
|
||||||
Shortcode string `json:"Shortcode"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// This func downloaded and parses the emojis from online into a slice of all shortnames
|
|
||||||
// to be used as a lookup for tab completion for emojis
|
|
||||||
// this way the pull from GitHub only has to be done at build time.
|
|
||||||
func createEmojiSlice() ([]string, error) {
|
|
||||||
result, err := http.Get(emojiList)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer result.Body.Close()
|
|
||||||
|
|
||||||
emojiList, err := ioutil.ReadAll(result.Body)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var emojis []emoji
|
|
||||||
if err := json.Unmarshal(emojiList, &emojis); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var emojiSlice []string
|
|
||||||
|
|
||||||
for _, emj := range emojis {
|
|
||||||
if len(emj.Shortcode) == 0 || strings.Contains(emj.Shortcode, "_tone") {
|
|
||||||
// dont add them
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
emojiSlice = append(emojiSlice, emj.Shortcode)
|
|
||||||
}
|
|
||||||
return emojiSlice, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build kbtui with emoji lookup support
|
|
||||||
func BuildEmoji() error {
|
|
||||||
emojis, err := createEmojiSlice()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
f, err := os.Create(emojiFileName)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
fileContent := fmt.Sprintf("package main\n\nvar emojiSlice = %#v", emojis)
|
|
||||||
_, err = f.WriteString(fileContent)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
f.Sync()
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// proper error reporting and exit code
|
// proper error reporting and exit code
|
||||||
func exit(err error) {
|
func exit(err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -142,8 +68,7 @@ func BuildAllCommandsT() {
|
|||||||
|
|
||||||
// Build kbtui with beta functionality
|
// Build kbtui with beta functionality
|
||||||
func BuildBeta() {
|
func BuildBeta() {
|
||||||
mg.Deps(BuildEmoji)
|
if err := sh.Run("go", "build", "-tags", "allcommands,showreactionscmd,tabcompletion"); err != nil {
|
||||||
if err := sh.Run("go", "build", "-tags", "allcommands,showreactionscmd,emojiList,tabcompletion"); err != nil {
|
|
||||||
defer func() {
|
defer func() {
|
||||||
exit(err)
|
exit(err)
|
||||||
}()
|
}()
|
||||||
|
|||||||
Reference in New Issue
Block a user