updated to v1.6

This commit is contained in:
Dan Remollino
2023-03-22 17:49:27 -04:00
parent 6679d65194
commit 5277c146ee
4 changed files with 86 additions and 29 deletions

View File

@ -1,3 +1,6 @@
## Version 1.6
- added option to auto comment FIGlet converted output for CSS, HTML, Javascript, and PHP syntaxes
## Version 1.5.1
- added extension to 'formatters' category
- added Repository link

View File

@ -1,12 +1,17 @@
# Features
- convert selected text to FIGlet text
- select FIGlet font
- configure FIGlet text output options
- option to auto comment converted text (HTML, Javascript, and PHP syntaxes only)
- prepend/append new lines to converted text
# Requirements
## FIGlet
FIGlet Text requires [FIGlet](http://www.figlet.org) to be installed locally. It is recommended to install FIGlet using [Homebrew](https://brew.sh). Once Homebrew is installed, simply run `brew install figlet`.
## Monospaced Fonts
It is recommended to only use a monospaced font in Nova. Not doing so will result in garbled looking FIGlet conversions.
# How to Use FIGlet Text
FIGlet Text will add a 'Create FIGlet Text from Selection' menu item to the Editor menu. Make one or more selections in the editor and run the command.
# TODO
- option to auto comment converted 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.

View File

@ -31,8 +31,12 @@ nova.commands.register('figlet', (workspace, figletArgs, textToConvert, postConv
let figTextStr = ''
process.onDidExit(status => {
if (status === 0) {
// the converted text from FIGlet as a string
figTextStr = figTextArr.join('').trimEnd()
// trim any whitespace from the end of each line; FIGlet seems
// to add a single column of whitespace more than what is required
figTextArr = figTextArr.map(line => { return line.trimEnd() })
// convert to a string
figTextStr = figTextArr.join('\n')
postConversion(figTextStr)
}
})
@ -41,18 +45,7 @@ nova.commands.register('figlet', (workspace, figletArgs, textToConvert, postConv
})
// FIGlet convert the selected text in the editor
nova.commands.register('createFigletText', editor => {
// console.log(editor.document.syntax)
let printNewLines = numOfLines => {
let newLinesStr = ''
while (numOfLines > 0) {
newLinesStr += '\n'
numOfLines--
}
return newLinesStr
}
nova.commands.register('figletTextEditor', editor => {
let figConfig = {
font: '-f' + nova.config.get('figlet_text.font', 'string'),
outputWidth: '-w' + nova.config.get('figlet_text.outputWidth', 'number'),
@ -60,6 +53,16 @@ nova.commands.register('createFigletText', editor => {
justification: nova.config.get('figlet_text.justification', 'string'),
}
let syntax = editor.document.syntax
let comment = nova.config.get('figlet_text.comment', 'boolean')
let commentPadding = nova.config.get('figlet_text.commentPadding', 'number')
let commentPaddingStr = nova.config.get('figlet_text.commentPaddingStr', 'string')
let commentChars = {
css: {start: '/*', end: '*/'},
html: {start: '<!--', end: '-->'},
javascript: {start: '//', end: ''},
php: {start: '//', end: ''}
}
let prependNewLines = nova.config.get('figlet_text.prependNewLines', 'number')
let appendNewLines = nova.config.get('figlet_text.appendNewLines', 'number')
@ -69,15 +72,32 @@ nova.commands.register('createFigletText', editor => {
let text = editor.getTextInRange(range)
nova.commands.invoke('figlet', figConfig, text, figletText => {
// // prepend/append new lines
if (appendNewLines > 0) { figletText = figletText.concat(printNewLines(figConfig.appendNewLines)) }
if (prependNewLines > 0) { figletText = printNewLines(figConfig.prependNewLines).concat(figletText) }
// comment each line if the option is selected
if (comment && (syntax === 'css' || syntax === 'html' || syntax === 'javascript' || syntax === 'php')) {
let lines = figletText.split('\n')
// replace the selection with the converted FIGlet text
editor.edit(e => {
e.replace(range, figletText)
let longestLine = 0
lines.map(line => {
if (line.length > longestLine) longestLine = line.length
})
let linesCommented = lines.map(line => {
let linePadding = 0
if (line.length < longestLine && (commentChars[syntax].end !== '')) linePadding = longestLine - line.length
return `${commentChars[syntax].start}${commentPaddingStr.repeat(commentPadding)}${line}${' '.repeat(linePadding)}${commentPaddingStr.repeat(commentPadding)}${commentChars[syntax].end}`.trimEnd()
})
figletText = linesCommented.join('\n')
}
// prepend/append new lines
if (prependNewLines > 0) figletText = `${'\n'.repeat(prependNewLines)}${figletText}`
if (appendNewLines > 0) figletText = `${figletText}${'\n'.repeat(appendNewLines)}`
// replace the selection with the converted/transformed FIGlet text
editor.edit(e => { e.replace(range, figletText) })
// deselect and position the cursor
editor.moveRight(1)
})
}

View File

@ -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.5.1",
"version": "1.6",
"categories": ["commands", "formatters"],
"entitlements": {
@ -199,7 +199,7 @@
{
"type": "section",
"required": false,
"title": "Output",
"title": "Text",
"children": [
{
"key": "figlet_text.outputWidth",
@ -228,6 +228,35 @@
"radio": false,
"values": [["-x", "Auto"], ["-l", "Left"], ["-c", "Center"], ["-r", "Right"]],
"default": "-x"
}
]
},
{
"type": "section",
"required": false,
"title": "Transformation",
"children": [
{
"key": "figlet_text.comment",
"title": "Comment FIGlet Output",
"description": "FIGlet Text will auto line comment the output. Currently supported in CSS, HTML, Javascript, and PHP syntaxes.",
"type": "boolean",
"default": true
},
{
"key": "figlet_text.commentPadding",
"title": "Comment Padding",
"description": "The number of Comment Padding Characters to add between the converted text and comment symbols.",
"type": "number",
"default": 4
},
{
"key": "figlet_text.commentPaddingStr",
"title": "Comment Padding Character",
"description": "Text string to use as Comment Padding. Defaults to a single space.",
"type": "string",
"default": " "
},
{
"key": "figlet_text.prependNewLines",
@ -250,8 +279,8 @@
"commands": {
"editor": [
{
"title": "Create FIGlet Text from Selection",
"command": "createFigletText",
"title": "Convert Selection to FIGlet",
"command": "figletTextEditor",
"shortcut": "ctrl-opt-cmd-f",
"when": "editorHasSelection"
}