fix(plugins): deteccion dinamica de lenguaje y sintaxis en editor de scripts (v1.24.1)
testing/ogGui-multibranch/pipeline/head There was a failure building this commit Details
oggui-debian-package/pipeline/head This commit looks good Details
oggui-debian-package/pipeline/tag This commit looks good Details

main 1.24.1
Juan Manuel Bardallo 2026-10-30 08:19:41 +01:00
parent b2237d7630
commit dbea3d2cd6
5 changed files with 68 additions and 16 deletions

View File

@ -1,5 +1,14 @@
# Changelog
## [1.24.1] - 2026-10-30
### Fixed
- **Detección Dinámica de Lenguaje y Resaltado en Editor de Scripts de Plugins (`PluginSettingsComponent`, `PluginService`)**:
- Corregido el badge de cabecera del editor de código en `plugin-settings` que mostraba estáticamente `POWERSHELL` incluso en scripts de Bash/Linux (`#!/bin/bash`).
- Incorporada la propiedad declarativa `language?: string` en `SchemaField` (`PluginService`), permitiendo a los plugins especificar directamente su sintaxis (ej. `bash`, `powershell`, `sh`).
- Detección automática inteligente como respaldo según el atributo `field.language`, el nombre de la clave (`linux`, `bash`, `ps1`, etc.) o el shebang del script (`#!/bin/bash`, `#!/bin/sh`).
- Adaptación contextual del motor de coloreado de sintaxis para comandos (`echo`, `mount`, `losetup`, `update-initramfs`, etc.), palabras clave (`if`, `fi`, `then`, `do`, `done`, etc.) y banderas de Linux (`--bind`, `-o`, etc.).
## [1.24.0] - 2026-10-28
### Added

View File

@ -1,6 +1,6 @@
{
"name": "og-webconsole",
"version": "1.24.0",
"version": "1.24.1",
"scripts": {
"ng": "ng",
"start": "ng serve",

View File

@ -136,7 +136,7 @@
<span class="terminal-dot red"></span>
<span class="terminal-dot yellow"></span>
<span class="terminal-dot green"></span>
<span class="code-lang-badge">PowerShell</span>
<span class="code-lang-badge">{{ getScriptLanguage(field) }}</span>
</div>
<div class="code-header-actions">
@if (field.action) {
@ -159,7 +159,7 @@
@if (!isEditingScript(field.key)) {
<div class="code-preview-scroll">
<div class="code-lines-table">
@for (line of getScriptLines(configData[field.key]); track $index) {
@for (line of getScriptLines(configData[field.key], field); track $index) {
<div class="code-line-row">
<span class="line-number">{{ $index + 1 }}</span>
<span class="line-code" [innerHTML]="line"></span>

View File

@ -208,10 +208,35 @@ export class PluginSettingsComponent implements OnInit, OnChanges, OnDestroy {
});
}
getScriptLines(script: string): SafeHtml[] {
getScriptLanguage(field: SchemaField): string {
if (field.language) {
const lang = field.language.toLowerCase().trim();
if (['bash', 'sh', 'shell'].includes(lang)) return 'BASH';
if (['powershell', 'ps1', 'ps'].includes(lang)) return 'POWERSHELL';
return field.language.toUpperCase();
}
const key = (field.key || '').toLowerCase();
if (key.includes('linux') || key.includes('bash') || key.includes('sh')) {
return 'BASH';
}
if (key.includes('win') || key.includes('powershell') || key.includes('ps1')) {
return 'POWERSHELL';
}
const scriptContent = (this.configData[field.key] || '').trim();
if (scriptContent.startsWith('#!/bin/') || scriptContent.startsWith('#!/usr/bin/')) {
return 'BASH';
}
return 'POWERSHELL';
}
getScriptLines(script: string, field?: SchemaField): SafeHtml[] {
if (!script) return [];
const lang = field ? this.getScriptLanguage(field) : 'POWERSHELL';
const lines = script.split('\n');
return lines.map(line => this.highlightLine(line));
return lines.map(line => this.highlightLine(line, lang));
}
private escapeHtml(str: string): string {
@ -221,7 +246,7 @@ export class PluginSettingsComponent implements OnInit, OnChanges, OnDestroy {
.replace(/>/g, '&gt;');
}
private highlightLine(rawLine: string): SafeHtml {
private highlightLine(rawLine: string, lang: string = 'POWERSHELL'): SafeHtml {
const trimmed = rawLine.trim();
if (trimmed.length === 0) {
@ -243,20 +268,37 @@ export class PluginSettingsComponent implements OnInit, OnChanges, OnDestroy {
return `___STR_${strings.length - 1}___`;
});
// 2. Parámetros / flags (/r, /t, -c, etc.)
escaped = escaped.replace(/(\s)([\/-][a-zA-Z0-9?]+)/g, '$1<span class="syntax-flag">$2</span>');
if (lang === 'BASH') {
// 2. Parámetros / flags Linux (--bind, -o, -u, etc.)
escaped = escaped.replace(/(\s)(--?[a-zA-Z0-9?_-]+)/g, '$1<span class="syntax-flag">$2</span>');
// 3. Comandos ejecutables
escaped = escaped.replace(/\b(uwfmgr\.exe|shutdown|powershell\.exe|cmd\.exe)\b/gi, '<span class="syntax-cmd">$1</span>');
// 3. Comandos ejecutables Linux
escaped = escaped.replace(/\b(echo|exit|reboot|shutdown|mount|umount|losetup|update-initramfs|modprobe|rm|mkdir|touch|cp|mv|cat|grep|sed|awk|systemctl|sleep|read)\b/gi, '<span class="syntax-cmd">$1</span>');
// 4. Subcomandos y palabras clave
escaped = escaped.replace(/\b(overlay|filter|volume|file|enable|disable|protect|set-type|set-size|add-exclusion)\b/gi, '<span class="syntax-keyword">$1</span>');
// 4. Palabras clave y control de flujo Bash
escaped = escaped.replace(/\b(if|then|else|elif|fi|case|esac|for|while|until|do|done|in|function|set|unset|export|source)\b/gi, '<span class="syntax-keyword">$1</span>');
// 5. Valores y tipos
escaped = escaped.replace(/\b(RAM|DISK|true|false)\b/gi, '<span class="syntax-val">$1</span>');
// 5. Valores y booleanos
escaped = escaped.replace(/\b(RAM|DISK|true|false)\b/gi, '<span class="syntax-val">$1</span>');
// 6. Números
escaped = escaped.replace(/\b(\d+)\b/g, '<span class="syntax-num">$1</span>');
// 6. Números
escaped = escaped.replace(/\b(\d+)\b/g, '<span class="syntax-num">$1</span>');
} else {
// 2. Parámetros / flags Windows (/r, /t, -c, etc.)
escaped = escaped.replace(/(\s)([\/-][a-zA-Z0-9?]+)/g, '$1<span class="syntax-flag">$2</span>');
// 3. Comandos ejecutables Windows
escaped = escaped.replace(/\b(uwfmgr\.exe|shutdown|powershell\.exe|cmd\.exe)\b/gi, '<span class="syntax-cmd">$1</span>');
// 4. Subcomandos y palabras clave
escaped = escaped.replace(/\b(overlay|filter|volume|file|enable|disable|protect|set-type|set-size|add-exclusion)\b/gi, '<span class="syntax-keyword">$1</span>');
// 5. Valores y tipos
escaped = escaped.replace(/\b(RAM|DISK|true|false)\b/gi, '<span class="syntax-val">$1</span>');
// 6. Números
escaped = escaped.replace(/\b(\d+)\b/g, '<span class="syntax-num">$1</span>');
}
// Restaurar cadenas
escaped = escaped.replace(/___STR_(\d+)___/g, (_, index) => {

View File

@ -69,6 +69,7 @@ export interface SchemaField {
description?: string;
descriptionKey?: string;
type: 'text' | 'number' | 'select' | 'checkbox' | 'textarea';
language?: string;
options?: string[];
default: any;
action?: FieldAction;