-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvisuals.p6
executable file
·94 lines (82 loc) · 2.5 KB
/
visuals.p6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env perl6
# Copyright © 2018-2019
# Aleks-Daniel Jakimenko-Aleksejev <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
use RoboRG::Middleware;
use Cro::HTTP::Router::WebSocket;
use Cro::HTTP::Router;
use Cro::HTTP::Server;
use Cro::WebSocket::Handler;
use Cro::WebSocket::Message;
unit sub MAIN(IO() $names-file);
my $name-channel = Supplier.new;
my $app = route {
get -> 'visuals' {
web-socket -> $incoming {
note ‘Connected!’;
supply {
whenever $incoming -> $message {
}
whenever $name-channel -> $name {
emit $name;
}
}
}
}
}
my $http-server = Cro::HTTP::Server.new(port => 8765, application => $app);
$http-server.start;
END .stop with $http-server;
my $index = 0;
my $name = ‘’;
sub set-index($id) {
$index = $id;
my @names = $names-file.slurp.lines;
$index max= 0;
$index min= @names - 1;
$name = @names[$index];
my $next = @names[$index+1] || ‘’;
note “$index (next: $next)”;
}
my $stdin = Channel.new;
start for lines() { $stdin.send: $_ }
my $ignore = 0;
react {
whenever service-subscribe(‘visuals-controller2’, ‘output’) {
#next if $ignore++ %% 2;
my @words = .body-text.words;
given @words[0] {
when ‘title-advance’ {
set-index($index += +@words[1]);
}
when ‘title-show’ {
note $name;
$name-channel.emit: $name;
}
when ‘title-cancel’ {
$name-channel.emit: ‘CANCEL’;
}
when ‘cam’ {
$ = run <xdotool key>, ‘F2’ ~ @words[1];
True
}
}
}
whenever $stdin {
my $id = +$_;
next unless $id;
set-index $id;
}
}