TheMathemagicians/sevenkeys/figlet/figlet.go

69 lines
1.2 KiB
Go

package figlet
import (
"os"
"path/filepath"
"sevenkeys/logic"
"github.com/lukesampson/figlet/figletlib"
"golang.org/x/crypto/ssh/terminal"
)
var (
FigletFontSlant *figletlib.Font
FigletFontTerm *figletlib.Font
)
func ReadFigletFonts() {
cwd, err := os.Getwd()
logic.Check(err)
fontsdir := filepath.Join(cwd, "fonts")
FigletFontSlant, err = figletlib.GetFontByName(fontsdir, "slant")
logic.Check(err)
FigletFontTerm, err = figletlib.GetFontByName(fontsdir, "term")
logic.Check(err)
}
func getTerminalWidth() int {
width, _, err := terminal.GetSize(0)
if err != nil {
return 80
}
return width
}
func PrintMsgSlant(msg, alignment string) {
figletlib.PrintMsg(msg,
FigletFontSlant,
getTerminalWidth(),
FigletFontSlant.Settings(),
alignment)
}
func PrintMsgTerm(msg, alignment string) {
figletlib.PrintMsg(msg,
FigletFontTerm,
getTerminalWidth(),
FigletFontTerm.Settings(),
alignment)
}
func SprintMsgSlant(msg, alignment string) string {
return figletlib.SprintMsg(msg,
FigletFontSlant,
getTerminalWidth(),
FigletFontSlant.Settings(),
alignment)
}
func SprintMsgTerm(msg, alignment string) string {
return figletlib.SprintMsg(msg,
FigletFontTerm,
getTerminalWidth(),
FigletFontTerm.Settings(),
alignment)
}