zlocalz
Version:
ZLocalz - TUI Locale Guardian for Flutter ARB l10n/i18n validation and translation with AI-powered fixes
139 lines • 4.99 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.DiffView = void 0;
const blessed = __importStar(require("blessed"));
const diff_1 = require("diff");
class DiffView {
container;
scrollable;
mode = 'unified';
constructor(parent) {
this.container = blessed.box({
parent,
top: 0,
left: 0,
width: '100%',
height: '100%',
hidden: true
});
this.scrollable = blessed.scrollabletext({
parent: this.container,
top: 0,
left: 0,
width: '100%',
height: '100%',
keys: true,
vi: true,
mouse: true,
tags: true,
scrollbar: {
ch: ' ',
track: { bg: '#333333' },
style: { inverse: true }
},
style: {
fg: 'white',
bg: '#1e1e1e'
}
});
this.container.key(['m'], () => {
this.toggleMode();
});
}
setContent(sourceValue, targetValue) {
if (this.mode === 'unified') {
this.showUnifiedDiff(sourceValue, targetValue);
}
else {
this.showSideBySideDiff(sourceValue, targetValue);
}
}
showUnifiedDiff(sourceValue, targetValue) {
const patch = (0, diff_1.createTwoFilesPatch)('source', 'target', sourceValue, targetValue, '', '', { context: 3 });
const lines = patch.split('\n').slice(4);
const formatted = lines.map(line => {
if (line.startsWith('+')) {
return `{green-fg}${line}{/green-fg}`;
}
else if (line.startsWith('-')) {
return `{red-fg}${line}{/red-fg}`;
}
else if (line.startsWith('@')) {
return `{cyan-fg}${line}{/cyan-fg}`;
}
else {
return line;
}
}).join('\n');
this.scrollable.setContent(formatted);
}
showSideBySideDiff(sourceValue, targetValue) {
const sourceLines = sourceValue.split('\n');
const targetLines = targetValue.split('\n');
const maxLines = Math.max(sourceLines.length, targetLines.length);
const halfWidth = Math.floor((this.container.width || 80) / 2) - 3;
const formatted = [
`{bold}{cyan-fg}${'Source'.padEnd(halfWidth)}│ Target{/cyan-fg}{/bold}`,
`{gray-fg}${'─'.repeat(halfWidth)}┼${'─'.repeat(halfWidth)}{/gray-fg}`
];
for (let i = 0; i < maxLines; i++) {
const sourceLine = sourceLines[i] || '';
const targetLine = targetLines[i] || '';
let sourceFormatted = sourceLine.substring(0, halfWidth).padEnd(halfWidth);
let targetFormatted = targetLine.substring(0, halfWidth);
if (sourceLine !== targetLine) {
sourceFormatted = `{red-fg}${sourceFormatted}{/red-fg}`;
targetFormatted = `{green-fg}${targetFormatted}{/green-fg}`;
}
formatted.push(`${sourceFormatted}│ ${targetFormatted}`);
}
this.scrollable.setContent(formatted.join('\n'));
}
toggleMode() {
this.mode = this.mode === 'unified' ? 'side-by-side' : 'unified';
if (this.scrollable.getContent()) {
this.container.screen.render();
}
}
show() {
this.container.show();
}
hide() {
this.container.hide();
}
}
exports.DiffView = DiffView;
//# sourceMappingURL=diff-view.js.map