updated to v.1.10

This commit is contained in:
Dan Remollino
2023-03-27 15:46:04 -04:00
parent 1add96bccc
commit eecbd369d6
4 changed files with 228 additions and 20 deletions

View File

@ -1,3 +1,8 @@
## Version 1.10
- added Borders option to add custom borders
- added Padding option to adjust spacing between outputted text and borders
- changed New Lines option to Margins
## Version 1.9 ## Version 1.9
- changed `Preview All Installed FIGlet Fonts` to `Generate FIGlet Font Collection Preview` - changed `Preview All Installed FIGlet Fonts` to `Generate FIGlet Font Collection Preview`
- added font collection selection for `Generate FIGlet Font Collection Preview` - added font collection selection for `Generate FIGlet Font Collection Preview`

View File

@ -5,8 +5,8 @@
- select FIGlet font - select FIGlet font
- configure FIGlet text output options - configure FIGlet text output options
- auto comment converted text; supported syntaxes: CSS, HTML, Javascript, PHP, Typescript, and SCSS - auto comment converted text; supported syntaxes: CSS, HTML, Javascript, PHP, Typescript, and SCSS
- prepend/append new lines to converted text - add padding, borders, and margins
- generate a custom preview of all installed FIGlet fonts - generate a custom previews of all Homebrew installed font collections
# Requirements # Requirements
@ -15,6 +15,3 @@ FIGlet Text requires [FIGlet](http://www.figlet.org) to be installed locally. Th
# How to Use FIGlet Text # How to Use FIGlet Text
FIGlet Text will add a 'Convert Selection to FIGlet' menu item to the Editor menu. Make one or more selections in the editor and run the command. FIGlet Text will add a 'Convert Selection to FIGlet' menu item to the Editor menu. Make one or more selections in the editor and run the command.
# Planned Features
- borders

View File

@ -66,7 +66,31 @@ nova.commands.register('figletTextEditor', editor => {
justification: nova.config.get('figlet_text.justification', 'string'), justification: nova.config.get('figlet_text.justification', 'string'),
} }
let comment = nova.config.get('figlet_text.comment', 'boolean') let bordersEnabled = nova.config.get('figlet_text.borders', 'boolean')
let borders = {
top: {
width: nova.config.get('figlet_text.borderTopWidth', 'number'),
padding: nova.config.get('figlet_text.borderTopPadding', 'number'),
char: nova.config.get('figlet_text.borderTopChar', 'string'),
},
right: {
width: nova.config.get('figlet_text.borderRightWidth', 'number'),
padding: nova.config.get('figlet_text.borderRightPadding', 'number'),
char: nova.config.get('figlet_text.borderRightChar', 'string'),
},
bottom: {
width: nova.config.get('figlet_text.borderBottomWidth', 'number'),
padding: nova.config.get('figlet_text.borderBottomPadding', 'number'),
char: nova.config.get('figlet_text.borderBottomChar', 'string'),
},
left: {
width: nova.config.get('figlet_text.borderLeftWidth', 'number'),
padding: nova.config.get('figlet_text.borderLeftPadding', 'number'),
char: nova.config.get('figlet_text.borderLeftChar', 'string'),
}
}
let commentsEnabled = nova.config.get('figlet_text.comment', 'boolean')
let commentPadding = nova.config.get('figlet_text.commentPadding', 'number') let commentPadding = nova.config.get('figlet_text.commentPadding', 'number')
let commentPaddingStr = nova.config.get('figlet_text.commentPaddingStr', 'string') let commentPaddingStr = nova.config.get('figlet_text.commentPaddingStr', 'string')
const getCommentChars = () => { const getCommentChars = () => {
@ -108,9 +132,93 @@ nova.commands.register('figletTextEditor', editor => {
// easier to modify line by line; order of transformations matter // easier to modify line by line; order of transformations matter
let figletTextArr = figletText.split('\n') let figletTextArr = figletText.split('\n')
// add borders if the option is enabled
if (bordersEnabled) {
let longestLine = 0
figletTextArr.map(line => { if (line.length > longestLine) longestLine = line.length })
let additionalWidth = ((borders.left.width * borders.left.char.length) + borders.left.padding) + ((borders.right.width * borders.right.char.length) + borders.right.padding)
// top/bottom transformations need to be buffered and applied
// after left/right transformations which are done line by and
// are affected by top/bottom transformations if done in place
let borderBuffer = { paddingTop: [], paddingBottom: [], widthTop: [], widthBottom: [] }
for (const border in borders) {
if (borders[border].padding > 0) {
switch (border) {
case 'left':
figletTextArr = figletTextArr.map(line => {
if (!/^\s+$/.test(line)) return `${' '.repeat(borders[border].padding)}${line}`
})
break
case 'right':
figletTextArr = figletTextArr.map(line => {
if (!/^\s+$/.test(line)) return `${line}${' '.repeat(borders[border].padding)}`
})
break
case 'top':
if (borders.left.width === 0 && borders.right.width === 0) {
// subtract one; will Array.prototype.join('\n') before final editor output
borderBuffer.paddingTop.push([`${'\n'.repeat(borders[border].padding - 1)}`])
} else {
for (let count = borders.top.padding; count; count--) {
borderBuffer.paddingTop.push(
borders.left.char.repeat(borders.left.width) + ' '.repeat(longestLine + borders.left.padding + borders.right.padding) + borders.left.char.repeat(borders.right.width)
)
}
}
break
case 'bottom':
if (borders.left.width === 0 && borders.right.width === 0) {
// subtract one; will Array.prototype.join('\n') before final editor output
borderBuffer.paddingBottom.push([`${'\n'.repeat(borders[border].padding - 1)}`])
} else {
for (let count = borders.bottom.padding; count; count--) {
borderBuffer.paddingBottom.push(
borders.left.char.repeat(borders.left.width) + ' '.repeat(longestLine + borders.left.padding + borders.right.padding) + borders.left.char.repeat(borders.right.width)
)
}
}
break
}
}
if (borders[border].width > 0) {
switch (border) {
case 'left':
figletTextArr = figletTextArr.map(line => {
if (!/^\s+$/.test(line)) { return `${borders[border].char.repeat(borders[border].width)}${line}` }
})
break
case 'right':
figletTextArr = figletTextArr.map(line => {
if (!/^\s+$/.test(line)) { return `${line}${borders[border].char.repeat(borders[border].width)}` }
})
break
case 'top':
for (let count = 0; count < borders[border].width; count++) {
borderBuffer.widthTop.push(`${borders[border].char.repeat(longestLine + additionalWidth)}`)
}
break
case 'bottom':
for (let count = 0; count < borders[border].width; count++) {
borderBuffer.widthBottom.push(`${borders[border].char.repeat(longestLine + additionalWidth)}`)
}
break
}
}
}
if (!borderBuffer.paddingTop.empty) figletTextArr = borderBuffer.paddingTop.concat(figletTextArr)
if (!borderBuffer.paddingBottom.empty) figletTextArr = figletTextArr.concat(borderBuffer.paddingBottom)
if (!borderBuffer.widthTop.empty) figletTextArr = borderBuffer.widthTop.concat(figletTextArr)
if (!borderBuffer.widthBottom.empty) figletTextArr = figletTextArr.concat(borderBuffer.widthBottom)
}
// comment each line if the option is selected and a // comment each line if the option is selected and a
// comment structure is defined for the current syntax // comment structure is defined for the current syntax
if (comment && getCommentChars() !== null) { if (commentsEnabled && getCommentChars() !== null) {
// find the longest line so we can add whitespace to shorter // find the longest line so we can add whitespace to shorter
// lines so closing comments line up if the syntax uses them // lines so closing comments line up if the syntax uses them
let longestLine = 0 let longestLine = 0
@ -122,20 +230,21 @@ nova.commands.register('figletTextEditor', editor => {
let linePadding = 0 let linePadding = 0
if (line.length < longestLine && (getCommentChars().end !== '')) linePadding = longestLine - line.length if (line.length < longestLine && (getCommentChars().end !== '')) linePadding = longestLine - line.length
// return the fully commented and formatted array of strings // return the commented line if not whitespace
if (/^\s+$/.test(line)) return '\n'
return `${getCommentChars().start}${commentPaddingStr.repeat(commentPadding)}${line}${' '.repeat(linePadding)}${commentPaddingStr.repeat(commentPadding)}${getCommentChars().end}`.trimEnd() return `${getCommentChars().start}${commentPaddingStr.repeat(commentPadding)}${line}${' '.repeat(linePadding)}${commentPaddingStr.repeat(commentPadding)}${getCommentChars().end}`.trimEnd()
}) })
} }
// prepend/append new lines // prepend/append new lines
if (prependNewLines > 0) figletTextArr = Array.of(`${'\n'.repeat(prependNewLines)}`).concat(figletTextArr) if (prependNewLines > 0) figletTextArr = [`${'\n'.repeat(prependNewLines)}`].concat(figletTextArr)
if (appendNewLines > 0) figletTextArr = figletTextArr.concat(Array.of(`${'\n'.repeat(appendNewLines)}`)) if (appendNewLines > 0) figletTextArr = figletTextArr.concat([`${'\n'.repeat(appendNewLines)}`])
// indent subsequent lines after the first if // indent subsequent lines after the first if
// the line with the selection was indented // the line with the selection was indented
if (!indentRange.empty) { if (!indentRange.empty) {
figletTextArr = figletTextArr.map((line, index) => { figletTextArr = figletTextArr.map((line, index) => {
if (index === 0) { return `${line}` } if (index === 0) return `${line}`
return `${indentText}${line}` return `${indentText}${line}`
}) })
} }

View File

@ -3,7 +3,7 @@
"name": "FIGlet Text", "name": "FIGlet Text",
"organization": "Dan Remollino", "organization": "Dan Remollino",
"description": "Convert selected text to FIGlet. Great for adding readable text to the Minimap, creating l33t text headers, and organizing files.", "description": "Convert selected text to FIGlet. Great for adding readable text to the Minimap, creating l33t text headers, and organizing files.",
"version": "1.9", "version": "1.10",
"categories": ["commands", "formatters"], "categories": ["commands", "formatters"],
"entitlements": { "entitlements": {
@ -18,7 +18,6 @@
"config": [ "config": [
{ {
"type": "section", "type": "section",
"required": false,
"title": "Font", "title": "Font",
"children": [ "children": [
{ {
@ -476,8 +475,7 @@
}, },
{ {
"type": "section", "type": "section",
"required": false, "title": "Text Output",
"title": "Text",
"children": [ "children": [
{ {
"key": "figlet_text.outputWidth", "key": "figlet_text.outputWidth",
@ -511,12 +509,11 @@
}, },
{ {
"type": "section", "type": "section",
"required": false, "title": "Comments",
"title": "Transformation",
"children": [ "children": [
{ {
"key": "figlet_text.comment", "key": "figlet_text.comment",
"title": "Comment FIGlet Output", "title": "Enable Comments",
"description": "FIGlet Text will auto line comment the output. Currently supported in CSS, HTML, Javascript, PHP, Typescript, and SCSS syntaxes.", "description": "FIGlet Text will auto line comment the output. Currently supported in CSS, HTML, Javascript, PHP, Typescript, and SCSS syntaxes.",
"type": "boolean", "type": "boolean",
"default": true "default": true
@ -534,17 +531,117 @@
"description": "Text string to use as Comment Padding. Defaults to a single space.", "description": "Text string to use as Comment Padding. Defaults to a single space.",
"type": "string", "type": "string",
"default": " " "default": " "
}
]
}, },
{
"type": "section",
"title": "Borders",
"description": "Border width and style.",
"children": [
{
"key": "figlet_text.borders",
"title": "Enable Borders",
"description": "Toggle border output without needing to change individual border settings. This option also toggles Padding output.",
"type": "bool",
"default": false
},
{
"key": "figlet_text.borderTopWidth",
"title": "Top Border Width",
"type": "number",
"default": 2
},
{
"key": "figlet_text.borderTopChar",
"title": "Top Border Character",
"type": "string",
"default": "#"
},
{
"key": "figlet_text.borderRightWidth",
"title": "Right Border Width",
"type": "number",
"default": 3
},
{
"key": "figlet_text.borderRightChar",
"title": "Right Border Character",
"type": "string",
"default": "#"
},
{
"key": "figlet_text.borderBottomWidth",
"title": "Bottom Border Width",
"type": "number",
"default": 2
},
{
"key": "figlet_text.borderBottomChar",
"title": "Bottom Border Character",
"type": "string",
"default": "#"
},
{
"key": "figlet_text.borderLeftWidth",
"title": "Left Border Width",
"type": "number",
"default": 3
},
{
"key": "figlet_text.borderLeftChar",
"title": "Left Border Character",
"type": "string",
"default": "#"
}
]
},
{
"type": "section",
"title": "Padding",
"description": "Spacing between FIGlet text and border. The 'Enable Borders' option must be checked under the Borders section for these options to have any effect.",
"children": [
{
"key": "figlet_text.borderTopPadding",
"title": "Top Padding",
"type": "number",
"default": 2
},
{
"key": "figlet_text.borderRightPadding",
"title": "Right Padding",
"type": "number",
"default": 5
},
{
"key": "figlet_text.borderBottomPadding",
"title": "Bottom Padding",
"type": "number",
"default": 2
},
{
"key": "figlet_text.borderLeftPadding",
"title": "Left Padding",
"type": "number",
"default": 5
}
]
},
{
"type": "section",
"title": "Margins",
"description": "Spacing between FIGlet text and your content.",
"children": [
{ {
"key": "figlet_text.prependNewLines", "key": "figlet_text.prependNewLines",
"title": "Prepend New Lines", "title": "Top Margin",
"description": "Amount of new lines to prepend to the converted text.", "description": "Amount of new lines to prepend to the converted text.",
"type": "number", "type": "number",
"default": 0 "default": 0
}, },
{ {
"key": "figlet_text.appendNewLines", "key": "figlet_text.appendNewLines",
"title": "Append New Lines", "title": "Bottom Margin",
"description": "Amount of new lines to append to the converted text.", "description": "Amount of new lines to append to the converted text.",
"type": "number", "type": "number",
"default": 0 "default": 0