Skip to content

Commit 20607c0

Browse files
committed
Added asciify
1 parent b9cf5df commit 20607c0

5 files changed

Lines changed: 39 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
## To Do
1111

12-
- [ ] `anyascii`: converts to ASCII using [anyascii](https://github.com/anyascii/anyascii)
12+
- [x] `asciify`: converts to ASCII using [anyascii](https://github.com/anyascii/anyascii)
1313
- [x] `asciitable`: prints out an table of ASCII characters
1414
- [ ] `bytecount`: counts the number of occurrences of each byte
1515
- [x] `certinfo`: print info about an x509 (aka SSL/HTTPS) certificate

cmd/asciify/asciify.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
anyascii "github.com/anyascii/go"
8+
"golang.org/x/text/encoding/charmap"
9+
)
10+
11+
func main() {
12+
13+
input, err := os.ReadFile("/dev/stdin")
14+
if err != nil {
15+
fmt.Fprintln(os.Stderr, "Error reading stdin:", err)
16+
os.Exit(1)
17+
}
18+
19+
// LATER: option to use a different code page
20+
decoder := charmap.CodePage437.NewDecoder()
21+
22+
// LATER: option to skip decoding (in case input is already UTF-8)
23+
utf8, err := decoder.Bytes(input)
24+
if err != nil {
25+
fmt.Fprintln(os.Stderr, "ERROR: unable to decode input: ", err)
26+
os.Exit(1)
27+
}
28+
29+
output := anyascii.Transliterate(string(utf8))
30+
fmt.Print(output)
31+
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.24
55
require golang.org/x/crypto v0.38.0
66

77
require (
8+
github.com/anyascii/go v0.3.2 // indirect
89
github.com/fatih/color v1.15.0 // indirect
910
github.com/mattn/go-colorable v0.1.13 // indirect
1011
github.com/mattn/go-isatty v0.0.19 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/anyascii/go v0.3.2 h1:87uFISteh7vwofK02srrPKtAvG6Wx7ozRjNh8uhfa7w=
2+
github.com/anyascii/go v0.3.2/go.mod h1:HDvbMmSpqJyIe+xtSkHmAYTjc8PzvO3l1Jmgx/IFUPs=
13
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
24
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
35
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=

run.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ set -o errexit
77
set -o nounset
88
set -o pipefail
99

10-
go build -o ./dist/asciitable ./cmd/asciitable
10+
CMD="${1:-asciify}"
1111

12-
./dist/asciitable
12+
go build -o "./dist/${CMD}" "./cmd/${CMD}"
13+
14+
./dist/${CMD}

0 commit comments

Comments
 (0)