🦋 Welcome to the MAIN() IRC channel of the Raku Programming Language (raku.org). Log available at irclogs.raku.org/raku/live.html . If you're a beginner, you can also check out the #raku-beginner channel!
Set by lizmat on 6 September 2022.
Xliff \o 06:19
tellable6 2022-10-26T07:34:58Z #raku-dev <lizmat> Xliff: about 3.5x as fast
2022-10-26T07:38:28Z #raku-dev <lizmat> Xliff Actually, more than 7.4x as fast, if you want strings, as .comb.rotor() will give you lists that would need to get joined: .comb.rotor(3 => -2)>>.join
Xliff How can I get function key input in raku?
.tell lizmat Wow! Nice work. Thanks for the info.
tellable6 Xliff, I'll pass your message to lizmat
Xliff How can I get function key input in raku? 06:43
I've tried Term::ReadKey and it's not working as I expected.
Xliff How can I get function key input in raku? 08:05
Inline::Perl5 still doesn't work.
So the one working solution I've found isn't applicable, ATM
Anton Antonov <@742445366489645080> On what platform / OS is not working as expected? 08:22
Xliff Linux / Terminal, so I don't have access to GUI toolkits 08:30
lizmat weekly: dev.to/lizmat/dont-fear-the-grepper-4-nki 09:50
notable6 lizmat, Noted! (weekly)
tellable6 2022-10-27T06:19:42Z #raku <Xliff> lizmat Wow! Nice work. Thanks for the info.
Xliff lizmat: I'm trying to detect function keys like F1, F2, etc... do you know of a good mechanism in Raku for that? 10:02
lizmat nope :-(
Xliff :( 10:02
Term::ReadKey gives you the sequences, but that's hard to switch into F1/F2 and such because you have to build the sequences manually. 10:03
Inline::Perl5 is still br0kered. 10:04
m: use CPAN:from<Perl5>
camelia ===SORRY!=== Error while compiling <tmp>
Please install Inline::Perl5 for Perl 5 support.
at <tmp>:1
Xliff Ah.
lizmat Xliff: looks like you will need to make a supply converter 10:05
Xliff How would that work? 10:10
lizmat github.com/rakudo/rakudo/blob/mast...s.pm6#L498 gives a nice example of that 10:12
Xliff Not really. That's a lot of code with no examples. :) 10:13
lizmat method produce 10:14
taking a Supply, and producing another Supply
Xliff And how does that apply to keystroke sequences? 10:15
lizmat Term::Readkey produces a Supply, right ?
Xliff Yes.... it can.
lizmat key-pressed 10:16
the problem is that function keys are emitted as more than one value by that supply, right ?
Xliff Yes. 10:18
I've only ever used supplies as event handlers.
I've never used them for things like lists, so this is new to me.
So can you get a Supply to take successive values and then check if that list is (1, 2, 3, 4)? 10:19
lizmat the Supply produce method is an example of a taking a supply, and collecting info from a given supply, and emitting values on a new supply
yup, just collect them, and pass them on when it matches your idea of a sensible sequence 10:20
Xliff Is there an example of this?
lizmat the link I just posted ?
Xliff That's the source for produce. Not an example. 10:21
And the docs have this: docs.raku.org/type/Supply#method_produce 10:22
Which is just a sum, not a sequence tracker.
lizmat gist.github.com/lizmat/737f60089a9...bbfed4f17d 10:26
I mean, it's very simplified
Xliff Thinking. I just tried something like this, myself. 10:30
Xliff This still doesn't work -- 10:38
raku -e 'use Mojo::DOM:from<Perl5>; #===SORRY!=== Error while compiling -e. Too many positionals passed; expected 1 argument but got 2 10:39
Xliff It would be nice if Supply.tail(3) would automatically give me the last 3 values emitted. 10:44
lizmat it doesn't? 11:02
it should? 11:03
ah, you mean "the last 3 values emitted before the current value" 11:04
Xliff: but that wouldn't help you, would it? because it would pass on invalid values also? 11:05
lizmat afk& 11:25
SmokeMachine m: Supply.from-list(4, 3, 2, 1, 2, 3, 4).rotor(3 => -2).grep({ $_ ~~ [1, 2, 3] }).act: &say # Xliff would something like this help? 11:38
camelia [1 2 3]
Xliff SmokeMachine: Thanks for trying, but no. 12:35
SmokeMachine then I think I gon't get what the problem is... :(
Xliff The valies come one at a time, therefore .rotor and .tail don't wokr.
So it's more like... 12:36
SmokeMachine but it works with that coming aone at a time...
Xliff m: my $s = Supplier::Preserving.new; $s.emit($_) for 4, 3, 2, 1, 2, 3, 4; my $sup = $s.Supply; $s.rotor(3 => -2).grep({ $_ ~~ [1, 2, 3] ]).act: .say 12:39
camelia ===SORRY!=== Error while compiling <tmp>
Missing block
at <tmp>:1
------> s.rotor(3 => -2).grep({ $_ ~~ [1, 2, 3] ⏏]).act: .say
expecting any of:
statement end
statement modifier
statement modif…
Xliff m: my $s = Supplier::Preserving.new; $s.emit($_) for 4, 3, 2, 1, 2, 3, 4; my $sup = $s.Supply; $s.rotor(3 => -2).grep({ $_ ~~ [1, 2, 3] }).act: .say
camelia (Any)
No such method 'act' for invocant of type 'Seq'
in block <unit> at <tmp> line 1
SmokeMachine m: supply { whenever Supply.interval: 0.001 { emit ^5 .roll } }.rotor(3 => -2).grep({ $_ ~~ [1, 2, 3] }).act: &say; sleep 1
camelia [1 2 3]
[1 2 3]
[1 2 3]
[1 2 3]
[1 2 3]
[1 2 3]
Xliff m: supply { whenever Supply.interval: 0.001 { emit (^5).roll } }.rotor(3 => -2).grep({ $_ ~~ [1, 2, 3] }).act: &say; sleep 1 12:40
camelia [1 2 3]
[1 2 3]
Xliff That might work.
SmokeMachine the rotor I'm using is not the List's one, but the Supply's one
Xliff That's what I was hoping to use. 12:41
Let me try that last one and see what I get. 12:42
Xliff SmokeMachine: OK, after attempts I have managed to get this: "use Term::ReadKey; react { whenever key-pressed( :!echo ).rotor(4) { .map( *.ord ).say }; }; 13:21
However, if the return sequence isn't 3 characters, I have to wait until a 4th character comes before I can act on the input. 13:22
The problem is I need to be able to act on sequences of an arbitrary number of values 13:24
F1-F4 have 3 characters per sequence. 13:25
F-F10 have 5 characters.
s/F-F10/F5-F10/ 13:26
How can the supply pattern handle that in a non-blocking way?
Xliff How can I detect if $*OUT is redirected to a file? 14:23
Oh! .t is available. Excellent! 14:25
japhb Oh dear lord, don't do this by hand! 14:27
Xliff: See Terminal::ANSIParser if you absolutely need the key sequence yourself. 14:28
See Terminal::LineEditor (and its guts) if you want to learn more about how to use a parsed ANSI sequence 14:29
See also Terminal::Widgets (and its guts) for an even more advanced user of same
japhb In particular Terminal::LineEditor::RawTerminalInput and Terminal::Widgets::Terminal may be of use. 14:32
Do we still have a knowledge bot in channel? 14:33
Xliff japhb: Oh. Thank. You. Jeebus!
I just wanna get the keystrokes.
japhb I feel like I need to create a bot that detects Term::ReadKey and goes "YOU PROBABLY DON'T WANT THAT, PLEASE LOOK OVER HERE." ;-)
Xliff YES, PLS!
:-)
I thought I looked at Terminal::Widgets. But it was late at night. I want to put an interface on this app I am writing for $dayJob. 14:34
japhb Terminal::Widgets only has a very small actual widget set. Most of my available hours were spent on getting the guts right. 14:35
So that's completely understandable.
I mean, it's usable for some things, with some work on your part, but certainly not "out of the box ready" 14:36
Xliff japhb: I am most happy to PR the parts I need that aren't there.
I just need something to take keystrokes and give me: F1, or F2, etc
japhb Look at Terminal::LineEditor::RawTerminalInput, that should give you an idea how I wrapped up usage of Terminal::ANSIParser. 14:37
BTW, I gave a talk on all this at the last Raku conf.
conf.raku.org/talk/178 (It's not technical, but the second half does show you what each of the Terminal::Modules do. The first half talks about *why* I've been going through all this pain.) 14:39
Xliff So far, not seeing any function key symbols.
Ooh! Watching, now.
japhb github.com/japhb/Terminal-LineEdit...akumod#L21 14:40
The next couple hundred lines have structures and declarations for decoding the result of Terminal::ANSIParser; starting around github.com/japhb/Terminal-LineEdit...kumod#L356 are the input and output pumps for the ANSI parser. 14:42
(And the length of all that is why I suggest just using the module. ;-) 14:43
Xliff japhb: So how is ::RawTerminalInput used? 15:06
japhb: This doesn't seem to be sufficient. All of your examples focus on line, not key based input handling... 15:20
japhb Xliff: Starting here: github.com/japhb/Terminal-LineEdit...kumod#L652 you can see how all of that is used to make a single-line line editor input. github.com/japhb/Terminal-Widgets/...al.rakumod shows using the building blocks to form an event pump for terminal events.
Xliff: Have you watched the whole video? :-) 15:21
Xliff --> "use Terminal::LineEditor; use Terminal::LineEditor::RawTerminalInput; my $cli = Terminal::LineEditor::CLIInput.new; $cli.start-decoder; react { whenever $cli.decoded { say $_ } }
Not yet. I am doing like... 3 things at once. I'm in the middle of the workday, here.
japhb AH!
Xliff I got as far as your Basic games books and cracked up laughing. Got strange looks, here.
=D
I think I had those. 15:22
japhb Terminal::LineEditor::CLIInput *uses* the real-time key handling to create a line editor. But that's just the cap on that particular stack. ;-)
:-D
Love it!
Xliff OK. I might have to wait until lunch. 15:24
.... oh wait....
It is lunch!
japhb :-) 15:25
Xliff japh: Do you still have those OpenGL demos? 17:18
Xliff japhb: github.com/Xliff/p6-COGL 17:20
I can pull >60fps from this one: github.com/Xliff/p6-COGL/blob/mast...03-crate.t
Nemokosch What is this? 17:23
Xliff Raku bindings for the COGL library.
It's based on my p6-GLib work, so it's a bear to install. 17:24
Nemokosch wowie 17:29
Xliff COGL is basically a wrapper around Open GL 17:35
Installation instructions updated in case anyone wants to check it out.
Xliff japhb: Is the mad scientist demo anywhere? 18:05
Xliff japhb: MMORPG roguelike FTW? 18:07
Xliff Oh! MUGS! 18:11
Nemokosch wonders which one is the real Kaiepi 18:22
Xliff Nemokosch... it's the one with two eyes! 18:23
japhb: my &parse-codepoint := make-ansi-parser( emit-item => { @parsed.push: $_ }); parse-codepoint($_) for $input-buffer.list; # missing the definition for $input-buffer! 18:24
Nemokosch what is the state of MUGS, by the way? 18:31
Xliff <punchy>Advocating an Array.lop as the front analog for .chop -- who's with me?</punchy> 19:09
m: "Hello".chop(2).say 19:10
camelia Hel
Xliff m: "Hello".lop(2).say
camelia No such method 'lop' for invocant of type 'Str'. Did you mean 'log'?
in block <unit> at <tmp> line 1
Xliff :( -- This needs correcting!! # :-)
Xliff got into the catnip again.... don't mind him 19:11
japhb: use Terminal::Print::DecodedInput; my $in = decoded-input-supply; react { whenever $in { .say } }; 19:18
Ahhhhhhh.....
gfldex .tell Xliff a simple implementation for your problem: gist.github.com/abebd2c82c79858a43...b1bf564412 20:06
tellable6 gfldex, I'll pass your message to Xliff
japhb Xliff: It's an older code, but it checks out. :-) 21:30
Xliff: Several of the demos from that talk are not *externally* available, mostly because people get weird expectations around released code, and those don't hit the bar for me. 21:33
Still working on the rpg-ui demo in my "spare time". The "intuitive character creation" demo will eventually be merged into that. 21:34
MUGS development has been paused a bit while I throw energy at those demos, and try to turn them into decent code via Terminal::Widgets improvements. 21:35
My life as a yak shaver, I guess. :-)
Xliff Hahahaha! 22:16
tellable6 2022-10-27T20:06:26Z #raku <gfldex> Xliff a simple implementation for your problem: gist.github.com/abebd2c82c79858a43...b1bf564412
Xliff gfldex: Ooh! Thanks 22:21
japhb: What am I missing from the newer code. I would prefer to use the latest and greatest, but I see a lot of similarities between the two... and it works. 22:22
Xliff How can I get a method's callable object? 22:25
m: class A { method a { }; method b { &self.a.^name.say }; }; A.b
camelia Nil
Xliff m: class A { method a { }; method b { &self.a.^name.say }; }; A.b() 22:26
camelia Nil
Xliff m: class A { method a { }; method b { &self.a.name.say }; }; A.b()
camelia Nil
Xliff ??
Voldenet m: class A { method a { say "a called"; }; method b { self.^lookup("a") }; }; A.b.(A) 23:30
camelia a called
Voldenet consider the following 23:31
docs.raku.org/type/Metamodel::MethodContainer