aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar alecdwm 2016-03-15 21:46:40 +0100
committerGravatar alecdwm 2016-03-15 21:52:05 +0100
commit02985f47521986ca078b8c4221d85370b34efe22 (patch)
treedee4bbfcdc17df654eb480a802a516e4085f0c54
Initial commit:
* Basic prototype of features * Query localhost:8080/gen?query=text-to-convert * pt features missing: Parsing of charmap.txt
-rw-r--r--.gitignore1
-rw-r--r--LICENSE.txt21
-rw-r--r--Makefile15
-rw-r--r--README.md28
-rw-r--r--ascii.go46
-rw-r--r--charmap.txt259
-rw-r--r--main.go45
7 files changed, 415 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..40b9d60
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+asciigen
diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 0000000..658e97d
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2016 alecdwm <owls.io>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..45090d6
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,15 @@
+phony:
+ @echo -ne "\033[0;33mAvailable commands:\033[0m\n\n\
+make test\t- test the server\n\
+make clean\t- clean up\n\
+\n"
+
+test:
+ @echo "Building asciiartfont"
+ @go build
+ @echo "Running asciiartfont"
+ @./asciiartfont
+
+clean:
+ @echo "Removing asciiartfont"
+ @rm -f ./asciiartfont
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..21b8408
--- /dev/null
+++ b/README.md
@@ -0,0 +1,28 @@
+```
+ █████╗ ███████╗ ██████╗██╗██╗ █████╗ ██████╗ ████████╗███████╗ ██████╗ ███╗ ██╗████████╗
+██╔══██╗██╔════╝██╔════╝██║██║██╔══██╗██╔══██╗╚══██╔══╝██╔════╝██╔═══██╗████╗ ██║╚══██╔══╝
+███████║███████╗██║ ██║██║███████║██████╔╝ ██║ █████╗ ██║ ██║██╔██╗ ██║ ██║
+██╔══██║╚════██║██║ ██║██║██╔══██║██╔══██╗ ██║ ██╔══╝ ██║ ██║██║╚██╗██║ ██║
+██║ ██║███████║╚██████╗██║██║██║ ██║██║ ██║ ██║ ██║ ╚██████╔╝██║ ╚████║ ██║
+╚═╝ ╚═╝╚══════╝ ╚═════╝╚═╝╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═╝
+```
+
+A small tool written in Go to convert `this` to
+```
+████████╗██╗ ██╗██╗███████╗
+╚══██╔══╝██║ ██║██║██╔════╝
+ ██║ ███████║██║███████╗
+ ██║ ██╔══██║██║╚════██║
+ ██║ ██║ ██║██║███████║
+ ╚═╝ ╚═╝ ╚═╝╚═╝╚══════╝
+```
+
+This is by far a mere hobby project, the future may/may not see the following features implemented:
+
+* Web form for querying the daemon via gui
+* Hosting on [ascii.owls.io](https://ascii.owls.io)
+* Multiple fonts without moving files around on the fs
+* Font selection on the web form
+* A cli/webgui helper for generating font maps
+* Web form theming
+* Refactoring into a Go lib package and webserver 'main' package
diff --git a/ascii.go b/ascii.go
new file mode 100644
index 0000000..844ec94
--- /dev/null
+++ b/ascii.go
@@ -0,0 +1,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
+}
diff --git a/charmap.txt b/charmap.txt
new file mode 100644
index 0000000..9dc5184
--- /dev/null
+++ b/charmap.txt
@@ -0,0 +1,259 @@
+
+
+
+ █████╗
+██╔══██╗
+███████║
+██╔══██║
+██║ ██║
+╚═╝ ╚═╝
+
+
+
+
+██████╗
+██╔══██╗
+██████╔╝
+██╔══██╗
+██████╔╝
+╚═════╝
+
+
+
+
+ ██████╗
+██╔════╝
+██║
+██║
+╚██████╗
+ ╚═════╝
+
+
+
+
+██████╗
+██╔══██╗
+██║ ██║
+██║ ██║
+██████╔╝
+╚═════╝
+
+
+
+
+███████╗
+██╔════╝
+█████╗
+██╔══╝
+███████╗
+╚══════╝
+
+
+
+
+███████╗
+██╔════╝
+█████╗
+██╔══╝
+██║
+╚═╝
+
+
+
+
+ ██████╗
+██╔════╝
+██║ ███╗
+██║ ██║
+╚██████╔╝
+ ╚═════╝
+
+
+
+
+██╗ ██╗
+██║ ██║
+███████║
+██╔══██║
+██║ ██║
+╚═╝ ╚═╝
+
+
+
+
+██╗
+██║
+██║
+██║
+██║
+╚═╝
+
+
+
+
+ ██╗
+ ██║
+ ██║
+██ ██║
+╚█████╔╝
+ ╚════╝
+
+
+
+
+██╗ ██╗
+██║ ██╔╝
+█████╔╝
+██╔═██╗
+██║ ██╗
+╚═╝ ╚═╝
+
+
+
+
+██╗
+██║
+██║
+██║
+███████╗
+╚══════╝
+
+
+
+
+███╗ ███╗
+████╗ ████║
+██╔████╔██║
+██║╚██╔╝██║
+██║ ╚═╝ ██║
+╚═╝ ╚═╝
+
+
+
+
+███╗ ██╗
+████╗ ██║
+██╔██╗ ██║
+██║╚██╗██║
+██║ ╚████║
+╚═╝ ╚═══╝
+
+
+
+
+ ██████╗
+██╔═══██╗
+██║ ██║
+██║ ██║
+╚██████╔╝
+ ╚═════╝
+
+
+
+
+██████╗
+██╔══██╗
+██████╔╝
+██╔═══╝
+██║
+╚═╝
+
+
+
+
+ ██████╗
+██╔═══██╗
+██║ ██║
+██║▄▄ ██║
+╚██████╔╝
+ ╚══▀▀═╝
+
+
+
+
+██████╗
+██╔══██╗
+██████╔╝
+██╔══██╗
+██║ ██║
+╚═╝ ╚═╝
+
+
+
+
+███████╗
+██╔════╝
+███████╗
+╚════██║
+███████║
+╚══════╝
+
+
+
+
+████████╗
+╚══██╔══╝
+ ██║
+ ██║
+ ██║
+ ╚═╝
+
+
+
+
+██╗ ██╗
+██║ ██║
+██║ ██║
+██║ ██║
+╚██████╔╝
+ ╚═════╝
+
+
+
+
+██╗ ██╗
+██║ ██║
+██║ ██║
+╚██╗ ██╔╝
+ ╚████╔╝
+ ╚═══╝
+
+
+
+
+██╗ ██╗
+██║ ██║
+██║ █╗ ██║
+██║███╗██║
+╚███╔███╔╝
+ ╚══╝╚══╝
+
+
+
+
+██╗ ██╗
+╚██╗██╔╝
+ ╚███╔╝
+ ██╔██╗
+██╔╝ ██╗
+╚═╝ ╚═╝
+
+
+
+
+██╗ ██╗
+╚██╗ ██╔╝
+ ╚████╔╝
+ ╚██╔╝
+ ██║
+ ╚═╝
+
+
+
+
+███████╗
+╚══███╔╝
+ ███╔╝
+ ███╔╝
+███████╗
+╚══════╝
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..e7aabc2
--- /dev/null
+++ b/main.go
@@ -0,0 +1,45 @@
+package main
+
+import (
+ "net/http"
+ "unicode/utf8"
+
+ "github.com/inconshreveable/log15"
+)
+
+func main() {
+ http.HandleFunc("/gen", gen)
+
+ err := http.ListenAndServe(":8080", nil)
+ if err != nil {
+ log15.Error("serving http requests", "error", err)
+ }
+}
+
+func gen(w http.ResponseWriter, r *http.Request) {
+ log15.Info("serving request")
+
+ err := r.ParseForm()
+ if err != nil {
+ log15.Error("parsing form in request", "error", err)
+ }
+
+ val := r.FormValue("query")
+
+ if !utf8.ValidString(val) {
+ log15.Error("non utf-8 encoded string", "key", "query", "val", val)
+ w.Write([]byte("non utf-8 encoded string"))
+ return
+ }
+
+ var asciiString string
+
+ runeArray := []rune(val)
+
+ for i := 0; i < utf8.RuneCountInString(val); i++ {
+ asciiString += ASCIICharacter(runeArray[i])
+ }
+
+ log15.Info("writing result", "result", asciiString)
+ w.Write([]byte(asciiString))
+}