aboutsummaryrefslogtreecommitdiffstats
path: root/ascii.go
blob: 844ec9440caa659464b53310358a00ef618f3d37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main

import (
	"io/ioutil"

	"github.com/inconshreveable/log15"
	"github.com/kardianos/osext"
)

// ASCIICharacterMap maps from runes to ascii characters represented as strings
type ASCIICharacterMap map[rune]string

var chars ASCIICharacterMap

// ASCIICharacter returns an 'ascii-art' representation of the given rune
func ASCIICharacter(character rune) string {
	if asciiChar, ok := chars[character]; ok {
		return asciiChar
	}
	return ""
}

func init() {
	dir, err := osext.ExecutableFolder()
	if err != nil {
		log15.Error("getting executable directory", "error", err)
	}

	charmapRaw, err := ioutil.ReadFile(dir + "/charmap.txt")
	if err != nil {
		log15.Error("reading charmap file",
			"file", dir+"/charmap.txt", "error", err)
	}

	charmap := string(charmapRaw[:])

	chars = loadCharMap(charmap)
}

func loadCharMap(charmap string) ASCIICharacterMap {
	newCharMap := make(map[rune]string)

	newCharMap['r'] = "R"

	return newCharMap
}