Calculate terminal width when drawing figlets

This commit is contained in:
The Magician 2024-06-12 18:57:12 +01:00
parent 779adfd274
commit d835ff2fcd
2 changed files with 13 additions and 12 deletions

View File

@ -4,16 +4,9 @@ import (
"database/sql" "database/sql"
tea "github.com/charmbracelet/bubbletea" tea "github.com/charmbracelet/bubbletea"
"github.com/lukesampson/figlet/figletlib"
) )
var ( var (
Program *tea.Program Program *tea.Program
Database *sql.DB Database *sql.DB
WindowWidth int
WindowHeight int
FigletFontSlant *figletlib.Font
FigletFontTerm *figletlib.Font
) )

View File

@ -3,10 +3,10 @@ package figlet
import ( import (
"os" "os"
"path/filepath" "path/filepath"
"sevenkeys/constants"
"sevenkeys/logic" "sevenkeys/logic"
"github.com/lukesampson/figlet/figletlib" "github.com/lukesampson/figlet/figletlib"
"golang.org/x/crypto/ssh/terminal"
) )
var ( var (
@ -27,10 +27,18 @@ func ReadFigletFonts() {
logic.Check(err) logic.Check(err)
} }
func getTerminalWidth() int {
width, _, err := terminal.GetSize(0)
if err != nil {
return 80
}
return width
}
func PrintMsgSlant(msg, alignment string) { func PrintMsgSlant(msg, alignment string) {
figletlib.PrintMsg(msg, figletlib.PrintMsg(msg,
FigletFontSlant, FigletFontSlant,
200, getTerminalWidth(),
FigletFontSlant.Settings(), FigletFontSlant.Settings(),
alignment) alignment)
} }
@ -38,7 +46,7 @@ func PrintMsgSlant(msg, alignment string) {
func PrintMsgTerm(msg, alignment string) { func PrintMsgTerm(msg, alignment string) {
figletlib.PrintMsg(msg, figletlib.PrintMsg(msg,
FigletFontTerm, FigletFontTerm,
200, getTerminalWidth(),
FigletFontTerm.Settings(), FigletFontTerm.Settings(),
alignment) alignment)
} }
@ -46,7 +54,7 @@ func PrintMsgTerm(msg, alignment string) {
func SprintMsgSlant(msg, alignment string) string { func SprintMsgSlant(msg, alignment string) string {
return figletlib.SprintMsg(msg, return figletlib.SprintMsg(msg,
FigletFontSlant, FigletFontSlant,
constants.WindowWidth, getTerminalWidth(),
FigletFontSlant.Settings(), FigletFontSlant.Settings(),
alignment) alignment)
} }
@ -54,7 +62,7 @@ func SprintMsgSlant(msg, alignment string) string {
func SprintMsgTerm(msg, alignment string) string { func SprintMsgTerm(msg, alignment string) string {
return figletlib.SprintMsg(msg, return figletlib.SprintMsg(msg,
FigletFontTerm, FigletFontTerm,
constants.WindowWidth, getTerminalWidth(),
FigletFontTerm.Settings(), FigletFontTerm.Settings(),
alignment) alignment)
} }