From 6c0bf3cbf34d0182f43c85b0659f98da9916a2d0 Mon Sep 17 00:00:00 2001 From: Dan Remollino Date: Mon, 3 Apr 2023 14:23:38 -0400 Subject: [PATCH] updated to v1.14 --- FIGlet Text.novaextension/CHANGELOG.md | 5 ++ FIGlet Text.novaextension/README.md | 2 +- FIGlet Text.novaextension/Scripts/main.js | 88 ++++++++++++++--------- FIGlet Text.novaextension/extension.json | 6 +- 4 files changed, 64 insertions(+), 37 deletions(-) diff --git a/FIGlet Text.novaextension/CHANGELOG.md b/FIGlet Text.novaextension/CHANGELOG.md index 574bc1c..986e7c7 100644 --- a/FIGlet Text.novaextension/CHANGELOG.md +++ b/FIGlet Text.novaextension/CHANGELOG.md @@ -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 - added option to set how FIGcharacters are spaced diff --git a/FIGlet Text.novaextension/README.md b/FIGlet Text.novaextension/README.md index 7d1dbb6..add7817 100644 --- a/FIGlet Text.novaextension/README.md +++ b/FIGlet Text.novaextension/README.md @@ -4,7 +4,7 @@ - convert selection to FIGlet text - select FIGlet font - 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 - generate a custom previews of all Homebrew installed font collections diff --git a/FIGlet Text.novaextension/Scripts/main.js b/FIGlet Text.novaextension/Scripts/main.js index e89c5c2..a7bcd3f 100644 --- a/FIGlet Text.novaextension/Scripts/main.js +++ b/FIGlet Text.novaextension/Scripts/main.js @@ -13,7 +13,7 @@ nova.commands.register('figlet', (workspace, figletArgs, textToConvert, postConversion) => { const fontSubDir = nova.config.get('figlet_text.font', 'string').match(/^.*\/\s*/) 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/' @@ -101,14 +101,26 @@ nova.commands.register('figletTextEditor', editor => { const getCommentChars = () => { switch (editor.document.syntax) { case 'css': + case 'sass': case 'scss': return {block: {start: '/*', end: '*/'}, inline: {start: '/*', end: '*/'}} case 'html': + case 'xml': return {block: {start: ''}, inline: {start: ''}} case 'javascript': case 'typescript': case 'php': 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: return null } @@ -142,7 +154,7 @@ nova.commands.register('figletTextEditor', editor => { 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) + 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 // after left/right transformations which are done line by and @@ -176,7 +188,7 @@ nova.commands.register('figletTextEditor', editor => { } 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) + 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 { 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) + 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 case 'top': 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 case 'bottom': 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 } @@ -235,37 +247,47 @@ nova.commands.register('figletTextEditor', editor => { if (!borderBuffer.widthBottom.empty) figletTextArr = figletTextArr.concat(borderBuffer.widthBottom) } - // comment each line if the option is enabled and a - // comment structure is defined for the current syntax - if (commentsEnabled && getCommentChars() !== null) { - switch (commentType) { - case 'inline': - // find the longest line so we can add whitespace to shorter - // lines so closing comments line up if the syntax uses them - let longestLine = 0 - figletTextArr.map(line => { if (line.length > longestLine) longestLine = line.length }) + let addComments = () => { + // comment if the option is enabled and a + // structure is defined for the current syntax + if (commentsEnabled && getCommentChars() !== null) { + switch (commentType) { + case 'inline': + // find the longest line so we can add whitespace to shorter + // lines so closing comments line up if the syntax uses them + let longestLine = 0 + figletTextArr.map(line => { if (line.length > longestLine) longestLine = line.length }) - // add the comment characters, lengthen lines with closing - // comments, and add user configured comment padding - figletTextArr = figletTextArr.map(line => { - let linePadding = 0 - if (line.length < longestLine && (getCommentChars().end !== '')) linePadding = longestLine - line.length + // add the comment characters, lengthen lines with closing + // comments, and add user configured comment padding + figletTextArr = figletTextArr.map(line => { + let linePadding = 0 + if (line.length < longestLine && (getCommentChars().end !== '')) linePadding = longestLine - line.length - // return the commented line if not whitespace - 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() - }) - break - case 'block': - 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 + // return the commented line if not whitespace + 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() + }) + break + case 'block': + // if block comments are not available for syntax, use inline + if (getCommentChars().block === null) { + commentType = 'inline' + addComments() + 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 if (marginsEnabled) { diff --git a/FIGlet Text.novaextension/extension.json b/FIGlet Text.novaextension/extension.json index 6f31973..92f766e 100644 --- a/FIGlet Text.novaextension/extension.json +++ b/FIGlet Text.novaextension/extension.json @@ -3,7 +3,7 @@ "name": "FIGlet Text", "organization": "Dan Remollino", "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"], "entitlements": { @@ -524,14 +524,14 @@ { "key": "figlet_text.comment", "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", "default": true }, { "key": "figlet_text.commentType", "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", "values": [["block", "Block"], ["inline", "Inline"]], "default": "inline"