From 1cc4855e167e4c5d3668a3888051503fc4d81025 Mon Sep 17 00:00:00 2001 From: Rick van der Staaij Date: Fri, 15 Nov 2024 21:09:21 +0100 Subject: [PATCH 1/2] Focus syntax highlighting on tasks --- .../Highlighter/highlighter.module.css | 4 + .../Highlighter/lineRenderers.tsx | 79 ++++++++++++++++--- .../GeneredTaskfile/taskfile-base.sh | 3 +- 3 files changed, 75 insertions(+), 11 deletions(-) diff --git a/src/components/Generator/GeneredTaskfile/Highlighter/highlighter.module.css b/src/components/Generator/GeneredTaskfile/Highlighter/highlighter.module.css index 1dcda92..70798b4 100644 --- a/src/components/Generator/GeneredTaskfile/Highlighter/highlighter.module.css +++ b/src/components/Generator/GeneredTaskfile/Highlighter/highlighter.module.css @@ -33,3 +33,7 @@ .text-blue-light { color: #93c5fd; } + +.text-green { + color: #2c9835; +} diff --git a/src/components/Generator/GeneredTaskfile/Highlighter/lineRenderers.tsx b/src/components/Generator/GeneredTaskfile/Highlighter/lineRenderers.tsx index f6d94ec..9b89aff 100644 --- a/src/components/Generator/GeneredTaskfile/Highlighter/lineRenderers.tsx +++ b/src/components/Generator/GeneredTaskfile/Highlighter/lineRenderers.tsx @@ -4,11 +4,16 @@ import styles from './highlighter.module.css'; enum RendererType { EmptyLines, + TaskDefinitions, FunctionDefinitions, + Sections, Comments, Variables, + TaskCalls, Conditionals, EchoStatements, + Titles, + FunctionEnds, } type LineRenderer = { @@ -21,23 +26,47 @@ export const lineRenderers: Record = { test: (line) => line.trim() === '', render: (_, i) =>
 
, }, - [RendererType.FunctionDefinitions]: { - test: (line) => /^function\s+[a-zA-Z_:]+/.test(line), + [RendererType.TaskDefinitions]: { + test: (line) => /^function\stask:+[a-zA-Z-_:]+/.test(line), render: (line, i) => { - const [, name, rest] = line.match(/^function\s+([a-zA-Z_:]+)(.*)/) || []; + const [, name, rest] = line.match(/^function\stask:+([a-zA-Z-_:]+)\s{\s##(.*)/) || []; return (
- function + function + task: {name} + {' { ##'} {rest}
); }, }, + [RendererType.FunctionDefinitions]: { + test: (line) => /^function\s+[a-zA-Z-_:]+/.test(line), + render: (line, i) => { + const [, name, rest] = line.match(/^function\s+([a-zA-Z-_:]+)(.*)/) || []; + return ( +
+ function + {name} + {rest} +
+ ); + }, + }, + [RendererType.Sections]: { + test: (line) => line.startsWith('## '), + render: (line, i) => ( +
+ ## + {line.substring(3)} +
+ ), + }, [RendererType.Comments]: { test: (line) => line.trim().startsWith('#'), render: (line, i) => ( -
+
{line}
), @@ -48,7 +77,7 @@ export const lineRenderers: Record = { const [varName, ...rest] = line.split('='); return (
- {varName} + {varName} = {rest.join('=')}
@@ -56,7 +85,7 @@ export const lineRenderers: Record = { }, }, [RendererType.Conditionals]: { - test: (line) => /^\s*if\s+|^\s*then\s+|^\s*else\s+|^\s*fi\s*/.test(line), + test: (line) => /^if+|^then+|^else+|^fi/.test(line.trim()), render: (line, i) => (
{line} @@ -69,11 +98,43 @@ export const lineRenderers: Record = { const parts = line.split('echo'); return (
- {parts[0]} - echo + {parts[0]}echo + {parts[1]} +
+ ); + }, + }, + [RendererType.Titles]: { + test: (line) => line.trim().startsWith('title'), + render: (line, i) => { + const parts = line.split('title'); + return ( +
+ {parts[0]}title {parts[1]}
); }, }, + [RendererType.TaskCalls]: { + test: (line) => /^\stask:+[a-zA-Z-_:]+/.test(line), + render: (line, i) => { + const [, space, task] = line.match(/(\s)task:+([a-zA-Z-_:]+)/) || []; + + return ( +
+ {space}task: + {task} +
+ ); + }, + }, + [RendererType.FunctionEnds]: { + test: (line) => line.trim().startsWith('}'), + render: (line, i) => ( +
+ {line} +
+ ), + }, }; diff --git a/src/components/Generator/GeneredTaskfile/taskfile-base.sh b/src/components/Generator/GeneredTaskfile/taskfile-base.sh index 450acef..50ed326 100644 --- a/src/components/Generator/GeneredTaskfile/taskfile-base.sh +++ b/src/components/Generator/GeneredTaskfile/taskfile-base.sh @@ -63,8 +63,7 @@ function task:help { ## Show all available tasks function task:shorthand { ## Create CLI shorthand task instead of ./Taskfile title "Creating task shorthand" - if [ -f /usr/local/bin/task ] - then + if [ -f /usr/local/bin/task ]; then echo "/usr/local/bin/task already exists." else echo -e "You are about to create /usr/local/bin/task that requires root permission..." From 3dc36d6d8ebf2f5a0025c1e467085866ca57b512 Mon Sep 17 00:00:00 2001 From: Rick van der Staaij Date: Fri, 15 Nov 2024 21:41:07 +0100 Subject: [PATCH 2/2] Make variables more clear --- .../GeneredTaskfile/Highlighter/highlighter.module.css | 2 +- .../GeneredTaskfile/Highlighter/lineRenderers.tsx | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/components/Generator/GeneredTaskfile/Highlighter/highlighter.module.css b/src/components/Generator/GeneredTaskfile/Highlighter/highlighter.module.css index 70798b4..2c883d4 100644 --- a/src/components/Generator/GeneredTaskfile/Highlighter/highlighter.module.css +++ b/src/components/Generator/GeneredTaskfile/Highlighter/highlighter.module.css @@ -35,5 +35,5 @@ } .text-green { - color: #2c9835; + color: #1d8525; } diff --git a/src/components/Generator/GeneredTaskfile/Highlighter/lineRenderers.tsx b/src/components/Generator/GeneredTaskfile/Highlighter/lineRenderers.tsx index 9b89aff..d6f4cae 100644 --- a/src/components/Generator/GeneredTaskfile/Highlighter/lineRenderers.tsx +++ b/src/components/Generator/GeneredTaskfile/Highlighter/lineRenderers.tsx @@ -35,7 +35,8 @@ export const lineRenderers: Record = { function task: {name} - {' { ##'} + {' {'} + {' ##'} {rest}
); @@ -77,9 +78,9 @@ export const lineRenderers: Record = { const [varName, ...rest] = line.split('='); return (
- {varName} - = - {rest.join('=')} + {varName} + = + {rest.join('=')}
); },