aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2022-04-27 19:34:38 +0900
committernsfisis <nsfisis@gmail.com>2022-04-27 19:34:38 +0900
commit0c1be8adcc4773ceb6927b4f38d62539077f8cc8 (patch)
treed46da59f87659e95fd5fa443deb33ab367f0e643
parent83754f16833766420cdca1f8527177dbc4b6ace1 (diff)
downloadterm-banner-0c1be8adcc4773ceb6927b4f38d62539077f8cc8.tar.gz
term-banner-0c1be8adcc4773ceb6927b4f38d62539077f8cc8.tar.zst
term-banner-0c1be8adcc4773ceb6927b4f38d62539077f8cc8.zip
support gothic font
-rw-r--r--README.md6
-rw-r--r--assets/misaki_gothic_2nd.pngbin0 -> 54790 bytes
-rw-r--r--main.go27
3 files changed, 25 insertions, 8 deletions
diff --git a/README.md b/README.md
index 8b2a990..047b8c7 100644
--- a/README.md
+++ b/README.md
@@ -24,6 +24,12 @@ Multiple arguments are displayed in multiple lines.
$ ./term-banner foo bar baz
```
+Switch font by `-f`:
+
+```
+$ ./term-banner -f gothic 'あいうえお'
+```
+
# Requirements
diff --git a/assets/misaki_gothic_2nd.png b/assets/misaki_gothic_2nd.png
new file mode 100644
index 0000000..2c80332
--- /dev/null
+++ b/assets/misaki_gothic_2nd.png
Binary files differ
diff --git a/main.go b/main.go
index 1a14810..5101d60 100644
--- a/main.go
+++ b/main.go
@@ -2,9 +2,9 @@ package main
import (
"embed"
+ "flag"
"image/png"
"log"
- "os"
"github.com/gdamore/tcell/v2"
"golang.org/x/text/encoding"
@@ -204,7 +204,7 @@ func calcSquareSizeAndOffset(r *Renderer, banner Banner) (int, int, []int, int)
squareW := scrW / gridWidthMax
squareH := scrH / gridHeight
if squareW > squareH*8 {
- squareW = squareH*8
+ squareW = squareH * 8
}
if squareH > squareW {
squareH = squareW
@@ -348,14 +348,25 @@ func prepareFont(fileHW, fileFW string) (*Font, error) {
}
func main() {
- if len(os.Args) <= 1 {
+ var fontType = flag.String("f", "mincho", "Font (mincho or gothic)")
+ flag.Parse()
+ var fontFileHW string
+ var fontFileFW string
+ if *fontType == "mincho" {
+ fontFileHW = "assets/misaki_gothic_2nd_4x8.png"
+ fontFileFW = "assets/misaki_mincho.png"
+ } else if *fontType == "gothic" {
+ fontFileHW = "assets/misaki_gothic_2nd_4x8.png"
+ fontFileFW = "assets/misaki_gothic_2nd.png"
+ } else {
+ log.Fatalf("Unknown font: %s", *fontType)
+ }
+
+ if flag.NArg() == 0 {
return
}
- font, err := prepareFont(
- "assets/misaki_gothic_2nd_4x8.png",
- "assets/misaki_mincho.png",
- )
+ font, err := prepareFont(fontFileHW, fontFileFW)
if err != nil {
log.Fatalf("%+v", err)
}
@@ -369,7 +380,7 @@ func main() {
}
defer r.Fini()
- banner, err := NewBanner(os.Args[1:])
+ banner, err := NewBanner(flag.Args())
if err != nil {
log.Fatalf("%+v", err)
}