feat: consider max width for rendering figlet
This commit is contained in:
parent
458cdef53c
commit
60ba1cdc86
2 changed files with 6 additions and 3 deletions
|
@ -19,7 +19,9 @@ const footer = ref([])
|
||||||
const figlet = useFiglet()
|
const figlet = useFiglet()
|
||||||
|
|
||||||
function getHeaderArt(header: string, font: string) {
|
function getHeaderArt(header: string, font: string) {
|
||||||
return figlet.render(header, font)
|
// Why is that so simple to approximate? Pretty sure, there is a mistake somewhere...
|
||||||
|
const maxWidth = Math.round(textArea.value?.getBoundingClientRect().width / 10) - 2
|
||||||
|
return figlet.render(header, font, maxWidth)
|
||||||
}
|
}
|
||||||
|
|
||||||
function parsedContent(src: string) {
|
function parsedContent(src: string) {
|
||||||
|
@ -42,7 +44,7 @@ function getCurrentPage(title: string) {
|
||||||
console.error('☠️ current page not found in the list. This should never happen.')
|
console.error('☠️ current page not found in the list. This should never happen.')
|
||||||
return {
|
return {
|
||||||
title: 'not_found',
|
title: 'not_found',
|
||||||
headerArt: getTitleArt('not_found'),
|
headerArt: getHeaderArt('404', 'chunky'),
|
||||||
content: 'The page could not be found.',
|
content: 'The page could not be found.',
|
||||||
uris: [],
|
uris: [],
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,8 @@ function getFont(name: string) {
|
||||||
export default function useFiglet() {
|
export default function useFiglet() {
|
||||||
const flm = new FontLayoutManager()
|
const flm = new FontLayoutManager()
|
||||||
|
|
||||||
function render(text: string, fontName: string) {
|
function render(text: string, fontName: string, maxWidth: number) {
|
||||||
|
flm.width.set(maxWidth)
|
||||||
const figFont = getFont(fontName)
|
const figFont = getFont(fontName)
|
||||||
const output = flm.renderText(text, figFont)
|
const output = flm.renderText(text, figFont)
|
||||||
return output
|
return output
|
||||||
|
|
Loading…
Add table
Reference in a new issue