Skip to content

Commit 075de31

Browse files
committed
feat: support for conditions in getLinesForField
1 parent 3e99ce2 commit 075de31

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

src/tests/dspf.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,20 @@ describe('DisplayFile tests', () => {
7878
{
7979
name: "COLOR",
8080
value: "BLU",
81-
conditions: []
81+
conditional: new Conditional()
8282
},
8383
{
8484
name: "DSPATR",
8585
value: "PR",
86-
conditions: []
86+
conditional: new Conditional(` 31`)
8787
}
8888
);
8989

9090
lines = DisplayFile.getLinesForField(field);
9191
expect(lines.length).toBe(3);
9292
expect(lines[0]).toBe(` A 4 10'Some text'`);
9393
expect(lines[1]).toBe(` A COLOR(BLU)`);
94-
expect(lines[2]).toBe(` A DSPATR(PR)`);
94+
expect(lines[2]).toBe(` A 31 DSPATR(PR)`);
9595

9696
});
9797

src/ui/dspf.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,7 @@ export class DisplayFile {
346346
}
347347

348348
for (const keyword of field.keywords) {
349-
// TODO: support conditions
350-
newLines.push(
351-
` A ${keyword.name}${keyword.value ? `(${keyword.value})` : ``}`,
352-
);
349+
newLines.push(...keyword.conditional.getLinesWithCondition(` A ${keyword.name}${keyword.value ? `(${keyword.value})` : ``}`));
353350
}
354351

355352
return newLines;
@@ -614,8 +611,29 @@ export class Conditional {
614611
return this.conditions;
615612
}
616613

617-
getLines(line: string): string[] {
618-
return [];
614+
getLinesWithCondition(line: string): string[] {
615+
if (this.conditions.length == 1 && this.conditions[0].indicators.length == 0) {
616+
return [line];
617+
}
618+
let lines: string[] = [];
619+
this.conditions.forEach((condition, cIdx) => {
620+
let i = 0;
621+
let line = ``;
622+
condition.indicators.forEach(ind => {
623+
if (i >= 3) {
624+
lines.push(line.padEnd(16));
625+
i = 0;
626+
}
627+
if (i == 0) {
628+
line = ` A${cIdx > 0 ? "O" : " "}`;
629+
}
630+
i++;
631+
line += `${ind.negate ? `N` : ` `}${String(ind.indicator).padStart(2, '0')}`;
632+
});
633+
lines.push(line.padEnd(16));
634+
});
635+
lines[lines.length - 1] = lines[lines.length - 1].substring(0, 16) + line.substring(16);
636+
return lines;
619637
}
620638

621639
}

0 commit comments

Comments
 (0)