updated to v1.14

This commit is contained in:
Dan Remollino
2023-04-03 14:23:38 -04:00
parent 941844d99a
commit 6c0bf3cbf3
4 changed files with 64 additions and 37 deletions

View File

@ -1,3 +1,8 @@
## Version 1.14
- added Lua, Perl, Python, Ruby, SASS, XML, and YAML to list of supported languages for auto-commenting
- fixed top/bottom border outputting too long if respective border character setting was greater than one character in length
- fixed top/bottom border applying left border characters on the right border when a respective padding was set in conjuction with a left or right border
## Version 1.13 ## Version 1.13
- added option to set how FIGcharacters are spaced - added option to set how FIGcharacters are spaced

View File

@ -4,7 +4,7 @@
- convert selection to FIGlet text - convert selection to FIGlet text
- 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, Lua, Perl, PHP, Python, Sass, SCSS, Typescript, Ruby, XML, and YAML
- add padding, borders, and margins - add padding, borders, and margins
- generate a custom previews of all Homebrew installed font collections - generate a custom previews of all Homebrew installed font collections

View File

@ -13,7 +13,7 @@
nova.commands.register('figlet', (workspace, figletArgs, textToConvert, postConversion) => { nova.commands.register('figlet', (workspace, figletArgs, textToConvert, postConversion) => {
const fontSubDir = nova.config.get('figlet_text.font', 'string').match(/^.*\/\s*/) const fontSubDir = nova.config.get('figlet_text.font', 'string').match(/^.*\/\s*/)
const fontDir = () => { const fontDir = () => {
if ( fontSubDir !== null) { if (fontSubDir !== null) {
return '/usr/local/Cellar/figlet/2.2.5/share/figlet/fonts/' + fontSubDir return '/usr/local/Cellar/figlet/2.2.5/share/figlet/fonts/' + fontSubDir
} }
return '/usr/local/Cellar/figlet/2.2.5/share/figlet/fonts/' return '/usr/local/Cellar/figlet/2.2.5/share/figlet/fonts/'
@ -101,14 +101,26 @@ nova.commands.register('figletTextEditor', editor => {
const getCommentChars = () => { const getCommentChars = () => {
switch (editor.document.syntax) { switch (editor.document.syntax) {
case 'css': case 'css':
case 'sass':
case 'scss': case 'scss':
return {block: {start: '/*', end: '*/'}, inline: {start: '/*', end: '*/'}} return {block: {start: '/*', end: '*/'}, inline: {start: '/*', end: '*/'}}
case 'html': case 'html':
case 'xml':
return {block: {start: '<!--', end: '-->'}, inline: {start: '<!--', end: '-->'}} return {block: {start: '<!--', end: '-->'}, inline: {start: '<!--', end: '-->'}}
case 'javascript': case 'javascript':
case 'typescript': case 'typescript':
case 'php': case 'php':
return {block: {start: '/*', end: '*/'}, inline: {start: '//', end: ''}} return {block: {start: '/*', end: '*/'}, inline: {start: '//', end: ''}}
case 'lua':
return {block: {start: '--[[', end: '--]]'}, inline: {start: '--', end: ''}}
case 'perl':
return {block: {start: '=', end: '=cut'}, inline: {start: '#', end: ''}}
case 'python':
return {block: {start: '"""', end: '"""'}, inline: {start: '#', end: ''}}
case 'ruby':
return {block: {start: '=begin', end: '=end'}, inline: {start: '#', end: ''}}
case 'yaml':
return {block: null, inline: {start: '#', end: ''}}
default: default:
return null return null
} }
@ -142,7 +154,7 @@ nova.commands.register('figletTextEditor', editor => {
let longestLine = 0 let longestLine = 0
figletTextArr.map(line => { if (line.length > longestLine) longestLine = line.length }) 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) let outputLength = longestLine + (((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 // top/bottom transformations need to be buffered and applied
// after left/right transformations which are done line by and // after left/right transformations which are done line by and
@ -176,7 +188,7 @@ nova.commands.register('figletTextEditor', editor => {
} else { } else {
for (let count = borders.top.padding; count; count--) { for (let count = borders.top.padding; count; count--) {
borderBuffer.paddingTop.push( 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) borders.left.char.repeat(borders.left.width) + ' '.repeat(longestLine + borders.left.padding + borders.right.padding) + borders.right.char.repeat(borders.right.width)
) )
} }
} }
@ -188,7 +200,7 @@ nova.commands.register('figletTextEditor', editor => {
} else { } else {
for (let count = borders.bottom.padding; count; count--) { for (let count = borders.bottom.padding; count; count--) {
borderBuffer.paddingBottom.push( 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) borders.left.char.repeat(borders.left.width) + ' '.repeat(longestLine + borders.left.padding + borders.right.padding) + borders.right.char.repeat(borders.right.width)
) )
} }
} }
@ -217,12 +229,12 @@ nova.commands.register('figletTextEditor', editor => {
break break
case 'top': case 'top':
for (let count = 0; count < borders[border].width; count++) { for (let count = 0; count < borders[border].width; count++) {
borderBuffer.widthTop.push(`${borders[border].char.repeat(longestLine + additionalWidth)}`) borderBuffer.widthTop.push(`${borders[border].char.repeat(outputLength)}`.slice(0, outputLength))
} }
break break
case 'bottom': case 'bottom':
for (let count = 0; count < borders[border].width; count++) { for (let count = 0; count < borders[border].width; count++) {
borderBuffer.widthBottom.push(`${borders[border].char.repeat(longestLine + additionalWidth)}`) borderBuffer.widthBottom.push(`${borders[border].char.repeat(outputLength)}`.slice(0, outputLength))
} }
break break
} }
@ -235,37 +247,47 @@ nova.commands.register('figletTextEditor', editor => {
if (!borderBuffer.widthBottom.empty) figletTextArr = figletTextArr.concat(borderBuffer.widthBottom) if (!borderBuffer.widthBottom.empty) figletTextArr = figletTextArr.concat(borderBuffer.widthBottom)
} }
// comment each line if the option is enabled and a let addComments = () => {
// comment structure is defined for the current syntax // comment if the option is enabled and a
if (commentsEnabled && getCommentChars() !== null) { // structure is defined for the current syntax
switch (commentType) { if (commentsEnabled && getCommentChars() !== null) {
case 'inline': switch (commentType) {
// find the longest line so we can add whitespace to shorter case 'inline':
// lines so closing comments line up if the syntax uses them // find the longest line so we can add whitespace to shorter
let longestLine = 0 // lines so closing comments line up if the syntax uses them
figletTextArr.map(line => { if (line.length > longestLine) longestLine = line.length }) let longestLine = 0
figletTextArr.map(line => { if (line.length > longestLine) longestLine = line.length })
// add the comment characters, lengthen lines with closing // add the comment characters, lengthen lines with closing
// comments, and add user configured comment padding // comments, and add user configured comment padding
figletTextArr = figletTextArr.map(line => { figletTextArr = figletTextArr.map(line => {
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 commented line if not whitespace // return the commented line if not whitespace
if (/^\s+$/.test(line)) return '\n' if (/^\s+$/.test(line)) return '\n'
return `${getCommentChars().inline.start}${commentPaddingStr.repeat(commentPadding.inline)}${line}${' '.repeat(linePadding)}${commentPaddingStr.repeat(commentPadding.inline)}${getCommentChars().inline.end}`.trimEnd() return `${getCommentChars().inline.start}${commentPaddingStr.repeat(commentPadding.inline)}${line}${' '.repeat(linePadding)}${commentPaddingStr.repeat(commentPadding.inline)}${getCommentChars().inline.end}`.trimEnd()
}) })
break break
case 'block': case 'block':
if (commentPadding.block > 0) { // if block comments are not available for syntax, use inline
figletTextArr.unshift('\n'.repeat(commentPadding.block - 1)) if (getCommentChars().block === null) {
figletTextArr.push('\n'.repeat(commentPadding.block - 1)) commentType = 'inline'
} addComments()
figletTextArr.unshift(getCommentChars().block.start) break
figletTextArr.push(getCommentChars().block.end) }
break
if (commentPadding.block > 0) {
figletTextArr.unshift('\n'.repeat(commentPadding.block - 1))
figletTextArr.push('\n'.repeat(commentPadding.block - 1))
}
figletTextArr.unshift(getCommentChars().block.start)
figletTextArr.push(getCommentChars().block.end)
break
}
} }
} }
addComments()
// add margins if the option is enabled // add margins if the option is enabled
if (marginsEnabled) { if (marginsEnabled) {

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.13", "version": "1.14",
"categories": ["commands", "formatters"], "categories": ["commands", "formatters"],
"entitlements": { "entitlements": {
@ -524,14 +524,14 @@
{ {
"key": "figlet_text.comment", "key": "figlet_text.comment",
"title": "Enable Comments", "title": "Enable Comments",
"description": "FIGlet Text will auto line comment the output. Currently supported in CSS, HTML, Javascript, PHP, Typescript, and SCSS syntaxes.", "description": "Auto comment the output. Supported in CSS, HTML, Javascript, Lua, Perl, PHP, Python, Sass, SCSS, Typescript, Ruby, XML, and YAML syntaxes.",
"type": "boolean", "type": "boolean",
"default": true "default": true
}, },
{ {
"key": "figlet_text.commentType", "key": "figlet_text.commentType",
"title": "Comment Type", "title": "Comment Type",
"description": "Comment output line by line or as a single block.", "description": "Comment output as a single block or line by line.",
"type": "enum", "type": "enum",
"values": [["block", "Block"], ["inline", "Inline"]], "values": [["block", "Block"], ["inline", "Inline"]],
"default": "inline" "default": "inline"