Skip to content

Instantly share code, notes, and snippets.

@mymmrac
Last active September 12, 2022 19:07
Show Gist options
  • Save mymmrac/a1eee6497ce6180b4ca3c941b27024ff to your computer and use it in GitHub Desktop.
Save mymmrac/a1eee6497ce6180b4ca3c941b27024ff to your computer and use it in GitHub Desktop.
Go code to peek N random Nerd Font icons
package main
import (
"fmt"
"math/rand"
"strconv"
"strings"
"time"
)
// Glyph Sets and Code Points
// https://github.com/ryanoasis/nerd-fonts/wiki/Glyph-Sets-and-Code-Points
var ranges = []string{
// Seti-UI + Custom
"e5fa-e631",
// Devicons
"e700-e7c5",
// Font Awesome
"f000-f2e0",
// Font Awesome Extension
"e200-e2a9",
// Material Design Icons
"f500-fd46",
// Weather
"e300-e3eb",
// Octicons
"f400-f4a9", "2665", "26A1",
// [Powerline Symbols]
"e0a0-e0a2", "e0b0-e0b3",
// Powerline Extra Symbols
"e0a3", "e0b4-e0c8", "e0ca", "e0cc-e0d4",
// IEC Power Symbols
"23fb-23fe", "2b58",
// Font Logos (Formerly Font Linux)
"f300-f32d",
// Pomicons
"e000-e00a",
// Codicons
"ea60-ebeb",
}
const glyphsToPeek = 64
const glyphsInRow = 8
func main() {
var chars []int64
for _, r := range ranges {
rs := strings.Split(r, "-")
if len(rs) == 1 {
rs = append(rs, rs[0])
}
start, err := strconv.ParseInt(rs[0], 16, 64)
if err != nil {
panic(err)
}
end, err := strconv.ParseInt(rs[1], 16, 64)
if err != nil {
panic(err)
}
for i := start; i <= end; i++ {
chars = append(chars, i)
}
}
fmt.Println("Glyphs:", len(chars))
rand.Seed(time.Now().Unix())
for i := 0; i < glyphsToPeek; i++ {
ind := rand.Intn(len(chars))
fmt.Print(toChar(chars[ind]) + " ")
chars = append(chars[:ind], chars[ind+1:]...)
if i > 0 && (i+1)%glyphsInRow == 0 {
fmt.Println()
}
}
}
func toChar(i int64) string {
char, err := strconv.Unquote(fmt.Sprintf("'\\u%X'", i))
if err != nil {
panic(err)
}
return char
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment