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"
tea "github.com/charmbracelet/bubbletea"
"github.com/lukesampson/figlet/figletlib"
)
var (
Program *tea.Program
Database *sql.DB
WindowWidth int
WindowHeight int
FigletFontSlant *figletlib.Font
FigletFontTerm *figletlib.Font
)

View File

@ -3,10 +3,10 @@ package figlet
import (
"os"
"path/filepath"
"sevenkeys/constants"
"sevenkeys/logic"
"github.com/lukesampson/figlet/figletlib"
"golang.org/x/crypto/ssh/terminal"
)
var (
@ -27,10 +27,18 @@ func ReadFigletFonts() {
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,
200,
getTerminalWidth(),
FigletFontSlant.Settings(),
alignment)
}
@ -38,7 +46,7 @@ func PrintMsgSlant(msg, alignment string) {
func PrintMsgTerm(msg, alignment string) {
figletlib.PrintMsg(msg,
FigletFontTerm,
200,
getTerminalWidth(),
FigletFontTerm.Settings(),
alignment)
}
@ -46,7 +54,7 @@ func PrintMsgTerm(msg, alignment string) {
func SprintMsgSlant(msg, alignment string) string {
return figletlib.SprintMsg(msg,
FigletFontSlant,
constants.WindowWidth,
getTerminalWidth(),
FigletFontSlant.Settings(),
alignment)
}
@ -54,7 +62,7 @@ func SprintMsgSlant(msg, alignment string) string {
func SprintMsgTerm(msg, alignment string) string {
return figletlib.SprintMsg(msg,
FigletFontTerm,
constants.WindowWidth,
getTerminalWidth(),
FigletFontTerm.Settings(),
alignment)
}