Skip to content

Commit b873726

Browse files
committed
Windows interactive Perl scripts
1 parent ffe3f6b commit b873726

File tree

10 files changed

+259
-124
lines changed

10 files changed

+259
-124
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ in the documentation of this project are to be interpreted as described in [RFC
8484

8585
* PEB can be started from any folder without installation procedure.
8686
* [Perl script output is seamlessly inserted in a nice HTML user interface.](./doc/SETTINGS.md#perl-scripts-api)
87-
* [Linux and Mac Perl scripts with STDIN event loops can be repeatedly fed with data.](./doc/SETTINGS.md#interactive-perl-scripts)
87+
* [Event-driven interactive Perl scripts can be repeatedly fed with data.](./doc/SETTINGS.md#interactive-perl-scripts)
8888
* [Any version of Perl 5 can be used.](./doc/REQUIREMENTS.md#runtime-requirements)
8989
* [Single file or multiple files, new filename, existing or new directory can be selected by user.](./doc/SETTINGS.md#selecting-files-and-folders)
9090
* [Unified logging of Perl and JavaScript errors in the JavaScript console](./doc/LOGGING.md)
@@ -106,7 +106,6 @@ in the documentation of this project are to be interpreted as described in [RFC
106106
* Only single-page applications are supported with no pop-up windows and no Perl scripting inside frames.
107107
* No files can be downloaded.
108108
* Printing is not supported.
109-
* Windows builds of PEB do not support [interactive Perl Scripts](./doc/SETTINGS.md#interactive-perl-scripts).
110109

111110
## History
112111

doc/SETTINGS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,9 @@ The [interactive.pl](https://github.com/ddmitov/perl-executing-browser/blob/mast
222222

223223
## Long-Running Windows Perl Scripts
224224

225-
Windows builds of PEB do not support [interactive Perl Scripts](./doc/SETTINGS.md#interactive-perl-scripts), but long-running Windows Perl scripts are supported provided that they also have ``$|=1;`` among their first lines to disable the built-in buffering of the Perl interpreter.
225+
Long-running Windows Perl scripts are supported provided that they also have ``$|=1;`` among their first lines to disable the built-in buffering of the Perl interpreter.
226226

227-
Long-running Windows Perl scripts can not receive the ``SIGTERM`` signal and if they are still running when PEB is closed, they can only be killed with no mechanism for a graceful shutdown.
227+
Windows Perl scripts can not receive the ``SIGTERM`` signal and if they are still running when PEB is closed, they can only be killed with no mechanism for a graceful shutdown.
228228

229229
## Selecting Files and Folders
230230

resources/app/index-windows.html

Lines changed: 105 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -7,54 +7,92 @@
77
<meta charset="utf-8">
88

99
<script>
10-
// PEB page settings:
11-
var pebSettings = {}; // 'pebSettings' object name is hard-coded.
12-
pebSettings.autoStartScripts = ['clock_one', 'clock_two'];
13-
pebSettings.cutLabel = '- Cut -';
14-
pebSettings.copyLabel = '- Copy -';
15-
pebSettings.pasteLabel = '- Paste -';
16-
pebSettings.selectAllLabel = '- Select All -';
17-
pebSettings.okLabel = 'OK';
18-
pebSettings.cancelLabel = 'CANCEL';
19-
pebSettings.yesLabel = 'YES';
20-
pebSettings.noLabel = 'NO';
21-
pebSettings.closeConfirmation =
22-
'Text was entered in a form and it is going to be lost!\n' +
23-
'Are you sure you want to close the application?';
24-
25-
// Settings objects for the Perl scripts:
26-
var perl_input = {};
27-
perl_input.scriptRelativePath = 'perl-scripts/input.pl';
28-
perl_input.inputData = function() {
29-
var data = document.getElementById('perl-input-box').value;
30-
$('#perl-input').trigger('reset');
31-
return data;
10+
// PEB page settings:
11+
var pebSettings = {}; // 'pebSettings' object name is hard-coded.
12+
pebSettings.autoStartScripts = ['interactive_one', 'interactive_two'];
13+
pebSettings.cutLabel = '- Cut -';
14+
pebSettings.copyLabel = '- Copy -';
15+
pebSettings.pasteLabel = '- Paste -';
16+
pebSettings.selectAllLabel = '- Select All -';
17+
pebSettings.okLabel = 'OK';
18+
pebSettings.cancelLabel = 'CANCEL';
19+
pebSettings.yesLabel = 'YES';
20+
pebSettings.noLabel = 'NO';
21+
pebSettings.closeConfirmation =
22+
'Text was entered in a form and it is going to be lost!\n' +
23+
'Are you sure you want to close the application?';
24+
25+
// Settings objects for Perl scripts
26+
// Interactive script:
27+
var messenger_one = {};
28+
messenger_one.scriptRelativePath = 'perl-scripts/messenger.pl';
29+
messenger_one.inputData = function() {
30+
var message = {};
31+
if(("tempfile" in messenger_one)) {
32+
message.tempfile = messenger_one.tempfile;
33+
}
34+
message.user_input = document.getElementById("interactive-one-input").value;
35+
$('#form-one').trigger('reset');
36+
return JSON.stringify(message);
3237
}
33-
perl_input.stdoutFunction = function (stdout) {
34-
var target = document.getElementById('user-data-perl-output');
35-
target.innerText = 'Last user input: ' + stdout;
38+
39+
var messenger_two = {};
40+
messenger_two.scriptRelativePath = 'perl-scripts/messenger.pl';
41+
messenger_two.inputData = function() {
42+
var message = {};
43+
if(("tempfile" in messenger_two)) {
44+
message.tempfile = messenger_two.tempfile;
45+
}
46+
message.user_input = document.getElementById("interactive-two-input").value;
47+
$('#form-two').trigger('reset');
48+
return JSON.stringify(message);
3649
}
3750

38-
var clock_one = {};
39-
clock_one.scriptRelativePath = 'perl-scripts/clock.pl';
40-
clock_one.inputData = function() {
41-
return "unix-epoch";
51+
var interactive_one = {};
52+
interactive_one.scriptRelativePath = 'perl-scripts/interactive-windows.pl';
53+
interactive_one.inputData = function() {
54+
var input = {};
55+
input.mode = "unix-epoch";
56+
return JSON.stringify(input);
4257
}
43-
clock_one.stdoutFunction = function (stdout) {
44-
var target = document.getElementById('clock-one-output');
45-
target.innerHTML = stdout;
58+
interactive_one.stdoutFunction = function (stdout) {
59+
var target = document.getElementById('instance-one-output');
60+
var output = JSON.parse(stdout);
61+
var html;
62+
messenger_one.tempfile = output.tempfile;
63+
if(("user_input" in output)) {
64+
if (output.user_input != undefined) {
65+
html = output.time + '<br>' + output.user_input;
66+
} else {
67+
html = output.time;
68+
}
69+
target.innerHTML = html;
70+
};
4671
}
4772

48-
var clock_two = {};
49-
clock_two.scriptRelativePath = 'perl-scripts/clock.pl';
50-
clock_two.inputData = function() {
51-
return "local-time";
73+
var interactive_two = {};
74+
interactive_two.scriptRelativePath = 'perl-scripts/interactive-windows.pl';
75+
interactive_two.inputData = function() {
76+
var input = {};
77+
input.mode = "local-time";
78+
return JSON.stringify(input);
5279
}
53-
clock_two.stdoutFunction = function (stdout) {
54-
var target = document.getElementById('clock-two-output');
55-
target.innerHTML = stdout;
80+
interactive_two.stdoutFunction = function (stdout) {
81+
var target = document.getElementById('instance-two-output');
82+
var output = JSON.parse(stdout);
83+
var html;
84+
messenger_two.tempfile = output.tempfile;
85+
if(("user_input" in output)) {
86+
if (output.user_input != undefined) {
87+
html = output.time + '<br>' + output.user_input;
88+
} else {
89+
html = output.time;
90+
}
91+
target.innerHTML = html;
92+
};
5693
}
5794

95+
// Other PEB tests:
5896
var open_file = {};
5997
open_file.scriptRelativePath = 'perl-scripts/open-files.pl';
6098
open_file.stdoutFunction = function (stdout) {
@@ -189,8 +227,9 @@
189227
font-size: 20px;
190228
}
191229

192-
.output {
230+
.interactive-output {
193231
font-size: 20px;
232+
margin-bottom: 20px;
194233
}
195234
</style>
196235
</head>
@@ -246,8 +285,6 @@
246285
</ul>
247286
</li>
248287

249-
<li><a href="javascript:location.reload();">Reload</a></li>
250-
251288
<li><a href="https://www.google.com/">Google</a></li>
252289

253290
<li class="dropdown">
@@ -277,40 +314,52 @@ <h2>Perl Executing Browser</h2>
277314
</div>
278315
</div>
279316

280-
<div class="row">
281-
&nbsp;
282-
</div>
317+
<h3>Interactive Script Demo</h3>
283318

284319
<div class="row">
285320
<div class="col-xs-12 form-group">
286-
<form action="perl_input.script" id="perl-input">
321+
<form action="messenger_one.script" id="form-one">
287322
<div class="input-group">
288-
<input type="text" id="perl-input-box" class="form-control"
289-
placeholder="Press Enter to send data to Perl script">
323+
<input type="text" id="interactive-one-input" name="input" class="form-control"
324+
placeholder="Press Enter to send data to the first interactive script instance">
290325

291326
<span class="input-group-addon btn btn-primary"
292-
onclick="javascript:$('#perl-input').trigger('reset');">
327+
onclick="javascript:$('#form-one').trigger('reset');">
293328
Reset
294329
</span>
295330

296331
<span class="input-group-addon btn btn-primary"
297-
onclick="javascript:$('#perl-input').trigger('submit');">
332+
onclick="javascript:$('#form-one').trigger('submit');">
298333
Send
299334
</span>
300335
</div>
301336
</form>
302337
</div>
303338

304-
<div id="user-data-perl-output" class="output">Last user input: none</div>
339+
<div id="instance-one-output" class="interactive-output">&nbsp;</div>
305340
</div>
306341

307342
<div class="row">
308-
&nbsp;
309-
</div>
343+
<div class="col-xs-12 form-group">
344+
<form action="messenger_two.script" id="form-two">
345+
<div class="input-group">
346+
<input type="text" id="interactive-two-input" name="input" class="form-control"
347+
placeholder="Press Enter to send data to the second interactive script instance">
310348

311-
<div class="row">
312-
<div id="clock-one-output" class="output">&nbsp;</div>
313-
<div id="clock-two-output" class="output">&nbsp;</div>
349+
<span class="input-group-addon btn btn-primary"
350+
onclick="javascript:$('#form-two').trigger('reset');">
351+
Reset
352+
</span>
353+
354+
<span class="input-group-addon btn btn-primary"
355+
onclick="javascript:$('#form-two').trigger('submit');">
356+
Send
357+
</span>
358+
</div>
359+
</form>
360+
</div>
361+
362+
<div id="instance-two-output" class="interactive-output">&nbsp;</div>
314363
</div>
315364
</div>
316365
</body>

resources/app/index.html

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,23 @@
2222
'Text was entered in a form and it is going to be lost!\n' +
2323
'Are you sure you want to close the application?';
2424

25-
// Settings objects for Perl scripts:
25+
// Settings objects for Perl scripts
26+
// Interactive script:
2627
var interactive_one = {};
2728
interactive_one.scriptRelativePath = 'perl-scripts/interactive.pl';
2829
interactive_one.inputData = function() {
2930
var input = {}
3031
input.mode = "unix-epoch";
31-
input.user = document.getElementById("interactive-one-input").value;
32+
input.user_input = document.getElementById("interactive-one-input").value;
3233
$('#form-one').trigger('reset');
3334
return JSON.stringify(input);
3435
}
3536
interactive_one.stdoutFunction = function (stdout) {
3637
var target = document.getElementById('instance-one-output');
3738
var output = JSON.parse(stdout);
3839
var html;
39-
if(("user" in output)) {
40-
html = output.time + '<br>' + output.user;
40+
if(("user_input" in output)) {
41+
html = output.time + '<br>' + output.user_input;
4142
} else {
4243
html = output.time;
4344
};
@@ -49,22 +50,23 @@
4950
interactive_two.inputData = function() {
5051
var input = {}
5152
input.mode = "local-time";
52-
input.user = document.getElementById("interactive-two-input").value;
53+
input.user_input = document.getElementById("interactive-two-input").value;
5354
$('#form-one').trigger('reset');
5455
return JSON.stringify(input);
5556
}
5657
interactive_two.stdoutFunction = function (stdout) {
5758
var target = document.getElementById('instance-two-output');
5859
var output = JSON.parse(stdout);
5960
var html;
60-
if(("user" in output)) {
61-
html = output.time + '<br>' + output.user;
61+
if(("user_input" in output)) {
62+
html = output.time + '<br>' + output.user_input;
6263
} else {
6364
html = output.time;
6465
};
6566
target.innerHTML = html;
6667
}
6768

69+
// Other PEB tests:
6870
var open_file = {};
6971
open_file.scriptRelativePath = 'perl-scripts/open-files.pl';
7072
open_file.stdoutFunction = function (stdout) {

resources/app/perl-scripts/clock.pl

Lines changed: 0 additions & 40 deletions
This file was deleted.

resources/app/perl-scripts/input.pl

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)