Skip to content

Commit 0edbab4

Browse files
committed
Printer file rendering
1 parent 5069681 commit 0edbab4

File tree

6 files changed

+118
-36
lines changed

6 files changed

+118
-36
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"Other"
1616
],
1717
"activationEvents": [
18-
"onLanguage:dds.dspf"
18+
"onLanguage:dds.dspf",
19+
"onLanguage:dds.prtf"
1920
],
2021
"main": "./src/extension.js",
2122
"contributes": {

src/dspf.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class DisplayFile {
6161

6262
case ' ':
6363
if ((x !== "" && y !== "") || inout === `H`) {
64+
// From a regular display file
6465
if (this.currentField !== null) {
6566
this.currentField.handleKeywords();
6667
this.currentFields.push(this.currentField);
@@ -71,6 +72,18 @@ class DisplayFile {
7172
x: Number(x),
7273
y: Number(y)
7374
};
75+
} else if (x !== "" && y === "") {
76+
// From a printer file with no Y position
77+
if (this.currentField !== null) {
78+
this.currentField.handleKeywords();
79+
this.currentFields.push(this.currentField);
80+
}
81+
82+
this.currentField = new FieldInfo();
83+
this.currentField.position = {
84+
x: Number(x),
85+
y: 0
86+
};
7487
}
7588

7689
if (name != "")

src/extension.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ function activate(context) {
3434
// Now provide the implementation of the command with registerCommand
3535
// The commandId parameter must match the command field in package.json
3636
context.subscriptions.push(
37-
vscode.commands.registerCommand('vscode-displayfile.render', function (sourceLines, format) {
37+
vscode.commands.registerCommand('vscode-displayfile.render', function (sourceLines, format, type) {
3838
// The code you place here will be executed every time your command is executed
3939

4040
try {
4141
const dspf = new DisplayFile();
4242
dspf.parse(sourceLines);
4343

44-
const render = new Render(dspf, Indicators.values);
44+
const render = new Render(dspf, Indicators.values, type);
4545

4646
const html = render.generate(format);
4747

@@ -80,18 +80,19 @@ function activate(context) {
8080

8181
renderTimeout = setTimeout(() => {
8282
if (Window.isActive()) {
83-
if (editor) {
83+
const activeEditor = vscode.window.activeTextEditor;
84+
if (editor && activeEditor) {
8485
const document = editor.document;
8586
const id = document.languageId;
8687

87-
if (id === `dds.dspf`) {
88+
if ([`dds.dspf`, `dds.prtf`].includes(id)) {
8889
const eol = document.eol === vscode.EndOfLine.CRLF ? `\r\n` : `\n`;
8990
const sourceLines = document.getText().split(eol);
9091

9192
const dspf = new DisplayFile();
9293
dspf.parse(sourceLines);
9394

94-
const render = new Render(dspf, Indicators.values);
95+
const render = new Render(dspf, Indicators.values, id);
9596

9697
const line = selection.start.line;
9798

@@ -115,6 +116,12 @@ function activate(context) {
115116
},
116117
lens
117118
),
119+
vscode.languages.registerCodeLensProvider(
120+
{
121+
language: `dds.prtf`,
122+
},
123+
lens
124+
),
118125
);
119126
}
120127

src/lensProvider.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports = class lensProvider {
4141
{
4242
command: `vscode-displayfile.render`,
4343
title: `Preview ${name}`,
44-
arguments: [lines, name]
44+
arguments: [lines, name, document.languageId]
4545
}
4646
));
4747
}
@@ -58,7 +58,7 @@ module.exports = class lensProvider {
5858
{
5959
command: `vscode-displayfile.render`,
6060
title: `Preview all`,
61-
arguments: [lines]
61+
arguments: [lines, undefined, document.languageId]
6262
}
6363
));
6464

src/render.js

Lines changed: 88 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const colors = {
88
GRN: `green`,
99
TRQ: `turquoise`,
1010
YLW: `yellow`,
11-
PNK: `pink`
11+
PNK: `pink`,
12+
BLK: `black`,
1213
};
1314

1415
const dateFormats = {
@@ -31,56 +32,78 @@ const timeFormats = {
3132
};
3233

3334
module.exports = class Render {
34-
constructor(display, indicators) {
35+
constructor(display, indicators, type) {
3536
/** @type {DisplayFile} */
3637
this.display = display;
3738

3839
/** @type {{[ind: number]: boolean}} */
3940
this.indicators = indicators || {};
40-
}
41-
42-
generate(format) {
43-
let size = {
44-
width: 880,
45-
height: 480
46-
};
4741

48-
const globalFormat = this.display.formats.find(currentFormat => currentFormat.name === `GLOBAL`);
49-
50-
let parts;
42+
this.printerFileLine = 0;
5143

52-
if (globalFormat) {
53-
const displaySize = globalFormat.keywords.find(keyword => keyword.name === `DSPSIZ`);
44+
/** @type {"dds.dspf"|"dds.prtf"} */
45+
this.type = type;
46+
}
5447

55-
if (displaySize) {
56-
parts = Render.parseParms(displaySize.value);
48+
generate(format) {
49+
let props = {
50+
size: {
51+
width: 880,
52+
height: 480
53+
},
54+
backgroundColor: colors.BLK,
55+
textColor: colors.GRN,
56+
}
5757

58-
if (parts.length >= 2) {
59-
const [height, width] = parts;
58+
switch (this.type) {
59+
case `dds.dspf`:
60+
const globalFormat = this.display.formats.find(currentFormat => currentFormat.name === `GLOBAL`);
6061

61-
size = {
62-
width: Number(width) * 11,
63-
height: Number(height) * 20
64-
};
62+
let parts;
63+
64+
if (globalFormat) {
65+
const displaySize = globalFormat.keywords.find(keyword => keyword.name === `DSPSIZ`);
66+
67+
if (displaySize) {
68+
parts = Render.parseParms(displaySize.value);
69+
70+
if (parts.length >= 2) {
71+
const [height, width] = parts;
72+
73+
props.size = {
74+
width: Number(width) * 11,
75+
height: Number(height) * 20
76+
};
77+
}
6578
}
6679
}
80+
break;
81+
case `dds.prtf`:
82+
props.size = {
83+
width: 132 * 11,
84+
height: 66 * 20
85+
};
86+
87+
props.backgroundColor = `#FFFFE8`;
88+
props.textColor = colors.BLK;
89+
break;
6790
}
6891

6992
let css = [
7093
`#container {`,
7194
` font-family: monospace;`,
7295
` font-size: 18px;`,
7396
` border: solid black 1px;`,
74-
` width: ${size.width}px;`,
75-
` height: ${size.height}px;`,
97+
` width: ${props.size.width}px;`,
98+
` height: ${props.size.height}px;`,
7699
` position: absolute;`,
77100
` --g: transparent calc(100% - 1px), #ebebeb 0;`,
78101
` letter-spacing: 0.15px;`,
79-
` color: ${colors.GRN};`,
102+
` color: ${props.textColor};`,
80103
` background:`,
81104
// ` linear-gradient(to right, var(--g)),`,
82105
// ` linear-gradient(to bottom, var(--g)), `,
83-
` black;`,
106+
` ${props.backgroundColor};`,
84107
` background-size:`,
85108
` 11px 100%,`,
86109
` 100% 20px;`,
@@ -361,6 +384,30 @@ module.exports = class Render {
361384
}
362385
}
363386

387+
// Printer file keywords
388+
let skipBefore = format.keywords.find(keyword => keyword.name === `SKIPB`);
389+
let skipAfter = format.keywords.find(keyword => keyword.name === `SKIPA`);
390+
let spaceBefore = format.keywords.find(keyword => keyword.name === `SPACEB`);
391+
let spaceAfter = format.keywords.find(keyword => keyword.name === `SPACEA`);
392+
393+
if (this.printerFileLine === 0) this.printerFileLine += 1;
394+
395+
if (skipBefore) {
396+
this.printerFileLine = Number(skipBefore.value);
397+
}
398+
399+
if (spaceBefore) {
400+
this.printerFileLine += Number(spaceBefore.value);
401+
}
402+
403+
if (spaceAfter) {
404+
this.printerFileLine += Number(spaceAfter.value);
405+
}
406+
407+
if (skipAfter) {
408+
this.printerFileLine += Number(skipAfter.value);
409+
}
410+
364411
const fields = format.fields.filter(field => field.displayType !== `hidden`);
365412
fields.forEach(field => {
366413
let canDisplay = true;
@@ -369,13 +416,27 @@ module.exports = class Render {
369416
if (this.indicators[cond.indicator] !== (cond.negate ? false : true)) {
370417
canDisplay = false;
371418
}
372-
})
419+
});
420+
421+
spaceBefore = field.keywords.find(keyword => keyword.name === `SPACEB`);
422+
spaceAfter = field.keywords.find(keyword => keyword.name === `SPACEA`);
423+
424+
if (spaceBefore) {
425+
this.printerFileLine += Number(spaceBefore.value);
426+
}
427+
428+
if (field.position.y === 0)
429+
field.position.y += this.printerFileLine;
373430

374431
if (canDisplay) {
375432
const content = this.getContent(field);
376433
css += content.css;
377434
body += content.body;
378435
}
436+
437+
if (spaceAfter) {
438+
this.printerFileLine += Number(spaceAfter.value);
439+
}
379440
});
380441

381442
} else {

src/window.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ let panel;
66
module.exports = class {
77
static create() {
88
if (panel) {
9-
panel.reveal
9+
panel.reveal();
1010
} else {
1111
panel = vscode.window.createWebviewPanel(
1212
`displayFile`,

0 commit comments

Comments
 (0)