Tickit-Console-0.12000755001750001750 014541672643 13020 5ustar00leoleo000000000000Tickit-Console-0.12/.editorconfig000444001750001750 5314541672643 15570 0ustar00leoleo000000000000root = true [*.{pm,pl,t}] indent_size = 3 Tickit-Console-0.12/Build.PL000444001750001750 132314541672643 14450 0ustar00leoleo000000000000use v5; use strict; use warnings; use Module::Build; my $build = Module::Build->new( module_name => 'Tickit::Console', requires => { 'perl' => '5.026', # signatures in Object::Pad 'Object::Pad' => '0.800', 'String::Tagged' => '0.10', 'Tickit' => 0, 'Tickit::Window' => '0.45', # rendering order 'Tickit::Widget::Entry' => 0, 'Tickit::Widget::Scroller' => '0.04', 'Tickit::Widget::Tabbed' => '0.024', # BUILDARGS }, configure_requires => { 'Module::Build' => '0.4004', # test_requires }, test_requires => { 'Test2::V0' => '0.000148', }, license => 'perl', create_license => 1, create_readme => 1, ); $build->create_build_script; Tickit-Console-0.12/Changes000444001750001750 532314541672643 14453 0ustar00leoleo000000000000Revision history for Tickit-Console 0.12 2023-12-23 [CHANGES] * Updated for Teest::ExpectAndCheck::Future v0.04 * Updates for Object::Pad v0.800: + add explicit `use warnings` * Use Object::Pad::MOP rather than `no strict 'refs'` hackery * Fixes to Pod style * Ensure every Perl file contains a `use VERSION` declaration 0.11 2023-03-04 [CHANGES] * Updates for Object::Pad 0.74: + Use :weak params + Use :isa instead of extends + Use ADJUST :params blocks + Use field NAME = EXPR 0.10 2021-07-06 [CHANGES] * Updates for Object::Pad 0.43: + Use :param and ADJUST blocks to remove/reduce BUILD blocks + Use a BUILDARGS to reshape the constructor args into a normal kvlist 0.09 2020-06-22 [CHANGES] * Added a way to override `localtime` for timestamp generation [BUGFIXES] * Ensure that unit testing of timestamps happens in UTC to avoid timezone-related failures 0.08 2020-06-15 [CHANGES] * Use Object::Pad 0.27 and signatures from perl 5.26 [BUGFIXES] * Remember to actually 'use Tickit::Widget::Tabbed' to get the ::Tab util class out of it 0.07 2014/09/08 19:30:44 [CHANGES] * Added ->prepend_line, allowing pre-history text to be inserted at the top of a scroller * Split out Tickit::Console::Tab into its own file * Allow applications to specify a custom tab class * Support management of timestamps and datestamps in scroller history * Renamed ->add_line to ->append_line 0.06 2014/08/16 21:00:11 [CHANGES] * Allow ->add_tab with a make_widget CODEref to create a tab with a custom internal layout * Proxy for ->remove_tab and ->move_tab * Pass active tab into 'on_line' callbacks on them, rather than the main console object * Added ->bind_key at the console and tab level 0.05 2014/05/14 16:51:29 [BUGFIXES] * Fix t/01basic.t for the fact that a window clear operation now happens first 0.04 2013/11/09 16:49:48 [CHANGES] * Added a simple netcat-like client example [BUGFIXES] * Fix unit test termlog expectations for recent Tickit changes 0.03 CHANGES: * Updated unit tests for visual style of Tickit::Widget:Tabbed 0.005 * Make sure to declare dependency on Tickit::Widget::Entry 0.02 CHANGES: * Use new bottom-gravity behaviour of Tickit::Widget::Scroller 0.04 0.01 First version, released on an unsuspecting world. Tickit-Console-0.12/LICENSE000444001750001750 4375514541672643 14220 0ustar00leoleo000000000000This software is copyright (c) 2023 by Paul Evans . This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2023 by Paul Evans . This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2023 by Paul Evans . This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End Tickit-Console-0.12/MANIFEST000444001750001750 43314541672643 14266 0ustar00leoleo000000000000.editorconfig Build.PL Changes examples/demo.pl examples/netcat.pl lib/Tickit/Console.pm lib/Tickit/Console/Tab.pm LICENSE MANIFEST This list of files META.json META.yml README t/00use.t t/01basic.t t/02tabs.t t/03input.t t/04make_widget.t t/05bind_key.t t/06timestamp.t t/99pod.t Tickit-Console-0.12/META.json000444001750001750 264214541672643 14602 0ustar00leoleo000000000000{ "abstract" : "build full-screen console-style applications", "author" : [ "Paul Evans " ], "dynamic_config" : 1, "generated_by" : "Module::Build version 0.4234", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Tickit-Console", "prereqs" : { "configure" : { "requires" : { "Module::Build" : "0.4004" } }, "runtime" : { "requires" : { "Object::Pad" : "0.800", "String::Tagged" : "0.10", "Tickit" : "0", "Tickit::Widget::Entry" : "0", "Tickit::Widget::Scroller" : "0.04", "Tickit::Widget::Tabbed" : "0.024", "Tickit::Window" : "0.45", "perl" : "5.026" } }, "test" : { "requires" : { "Test2::V0" : "0.000148" } } }, "provides" : { "Tickit::Console" : { "file" : "lib/Tickit/Console.pm", "version" : "0.12" }, "Tickit::Console::Tab" : { "file" : "lib/Tickit/Console/Tab.pm", "version" : "0.12" } }, "release_status" : "stable", "resources" : { "license" : [ "http://dev.perl.org/licenses/" ] }, "version" : "0.12", "x_serialization_backend" : "JSON::PP version 4.07" } Tickit-Console-0.12/META.yml000444001750001750 163414541672643 14432 0ustar00leoleo000000000000--- abstract: 'build full-screen console-style applications' author: - 'Paul Evans ' build_requires: Test2::V0: '0.000148' configure_requires: Module::Build: '0.4004' dynamic_config: 1 generated_by: 'Module::Build version 0.4234, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Tickit-Console provides: Tickit::Console: file: lib/Tickit/Console.pm version: '0.12' Tickit::Console::Tab: file: lib/Tickit/Console/Tab.pm version: '0.12' requires: Object::Pad: '0.800' String::Tagged: '0.10' Tickit: '0' Tickit::Widget::Entry: '0' Tickit::Widget::Scroller: '0.04' Tickit::Widget::Tabbed: '0.024' Tickit::Window: '0.45' perl: '5.026' resources: license: http://dev.perl.org/licenses/ version: '0.12' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Tickit-Console-0.12/README000444001750001750 634514541672643 14045 0ustar00leoleo000000000000NAME Tickit::Console - build full-screen console-style applications SYNOPSIS my $console = Tickit::Console->new; Tickit->new( root => $console )->run; DESCRIPTION A Tickit::Console instance is a subclass of Tickit::Widget::VBox intended to help building a full-screen console-style application which presents the user with one or more scrollable text areas, selectable as tabs on a ribbon, with a text entry area at the bottom of the screen for entering commands or other data. As a Tickit::Widget subclass it can be added anywhere within a widget tree, though normally it would be used as the root widget for a Tickit instance. CONSTRUCTOR new $console = Tickit::Console->new( %args ); Returns a new instance of a Tickit::Console. Takes the following named arguments: on_line => CODE Callback to invoke when a line of text is entered in the entry widget. $on_line->( $active_tab, $text ); tab_class => STRING Optional. If set, gives a class name (which should be a subclass of Tickit::Console::Tab) to construct newly-added tabs with. This setting allows an application to provide new methods in tabs to change behaviours. timestamp_format, datestamp_format Optional. If supplied, these will be stored as default values to pass to the tab constructor in the add_tab method. METHODS add_tab $tab = $console->add_tab( %args ); Adds a new tab to the console, and returns a Tickit::Console::Tab object representing it. Takes the following named arguments: name => STRING Name for the tab. on_line => CODE Optional. Provides a different callback to invoke when a line of text is entered while this tab is active. Invoked the same way as above. make_widget => CODE Optional. Gives a piece of code used to construct the actual Tickit::Widget used as this tab's child in the ribbon. A Tickit::Widget::Scroller to hold the tab's content will be passed in to this code, which should construct some sort of widget tree with that inside it, and return it. This can be used to apply a decorative frame, place the scroller in a split box or other layout along with other widgets, or various other effects. $tab_widget = $make_widget->( $scroller ); Any other named arguments are passed to the tab's constructor. active_tab_index $index = $console->active_tab_index; active_tab $tab = $console->active_tab; remove_tab $console->remove_tab( $tab_or_index ); move_tab $console->move_tab( $tab_or_index, $delta ); activate_tab $console->activate_tab( $tab_or_index ); next_tab $console->next_tab; prev_tab $console->prev_tab; These methods are all passed through to the underlying Tickit::Widget::Tabbed object. bind_key $console->bind_key( $key, $code ); Installs a callback to invoke if the given key is pressed, overwriting any previous callback for the same key. The code block is invoked as $code->( $console, $key ); If $code is missing or undef, any existing callback is removed. AUTHOR Paul Evans Tickit-Console-0.12/examples000755001750001750 014541672643 14636 5ustar00leoleo000000000000Tickit-Console-0.12/examples/demo.pl000555001750001750 470014541672643 16260 0ustar00leoleo000000000000#!/usr/bin/perl use v5.26; use warnings; use Tickit::Async; use Tickit::Console; use Tickit::Widgets 0.30 qw( Frame=0.32 ); use IO::Async::Loop; use IO::Async::Timer::Periodic; use String::Tagged; my $loop = IO::Async::Loop->new(); my $globaltab; my $warntab; my $counter = 1; sub add_a_line { my $text = String::Tagged->new( ": Line $counter " ); $counter++; for ( 0 .. rand( 30 ) + 3 ) { $text->append_tagged( chr( rand( 26 ) + 0x40 ) x ( rand( 10 ) + 5 ), fg => int( rand( 7 ) + 1 ), b => rand > 0.8, u => rand > 0.8, i => rand > 0.8, ); $text->append( " " ); } $globaltab->add_line( $text, indent => 8 ); } my $timercount = 0; my $timer = IO::Async::Timer::Periodic->new( interval => 1, on_tick => \&add_a_line, ); $loop->add( $timer ); my $console = Tickit::Console->new( on_line => sub { my ( $self, $line ) = @_; if( $line eq "quit" ) { $loop->stop; } elsif( $line eq "start" ) { $timercount = 0; $timer->start; } elsif( $line eq "stop" ) { $timer->stop; } else { $globaltab->add_line( ": $line", indent => 9 ); } }, on_key => sub { my ( $self, $type, $str, $key ) = @_; # Encode nicely $str =~ s/\//\\\\/g; $str =~ s/\n/\\n/g; $str =~ s/\r/\\r/g; $str =~ s/\e/\\e/g; $str =~ s{([^\x20-\x7e])}{sprintf "\\x%02x", ord $1}eg; $globaltab->add_line( ": $type => $str", indent => 7 ); }, ); $globaltab = $console->add_tab( name => "GLOBAL" ); $warntab = $console->add_tab( name => "WARN" ); $SIG{__WARN__} = sub { return unless defined $warntab; $warntab->add_line( "WARN: $_[0]", 6 ); }; my $framedtab = $console->add_tab( name => "FRAME", make_widget => sub { my ( $scroller ) = @_; return Tickit::Widget::Frame->new( style => { linetype => "single" }, title => "The scroller", )->set_child( $scroller ); }, ); # Lines of content for the frame $framedtab->add_line( $_ ) for qw( Content for the frame ); my $tickit = Tickit::Async->new; $loop->add( $tickit ); $tickit->set_root_widget( $console ); # Create some inital content so the tab has something interesting to scroll around add_a_line for 1 .. 50; eval { $tickit->run }; undef $console; die "$@" if $@; Tickit-Console-0.12/examples/netcat.pl000555001750001750 527314541672643 16620 0ustar00leoleo000000000000#!/usr/bin/perl use v5.26; use warnings; use Tickit::Async; use Tickit::Console; use String::Tagged; use IO::Async::Loop; my $loop = IO::Async::Loop->new; my $host = shift @ARGV or die "Need a HOST"; my $service = shift @ARGV or die "Need a SERVICE"; my $stream; $loop->connect( host => $host, service => $service, socktype => 'stream', on_stream => sub { ( $stream ) = @_; }, on_connect_error => sub { die "Cannot connect - $_[-1]\n" }, on_resolve_error => sub { die "Cannot resolve - $_[-1]\n" }, ); $loop->loop_once until $stream; my $tab; $stream->configure( on_read => sub { my ( $self, $buffref, $eof ) = @_; while( $$buffref =~ s/^(.*?)\r?\n// ) { my $line = $1; # Render CTRL characters as reverse-video capitals ( my $linetext = $line ) =~ s{([\x00-\x1f])}{chr 64 + ord $1}eg; my $str = String::Tagged->new( "<- $linetext" ); $str->apply_tag( 0, 2, fg => 'green' ); $str->apply_tag( 3 + $-[0], 1, rv => 1 ) while $line =~ m{[\x00-\x1f]}g; $tab->add_line( $str ); } if( $eof ) { # TODO: partial my $str = String::Tagged->new( "EOF" ); $str->apply_tag( 0, 3, fg => 'green' ); $tab->add_line( $str ); } return 0; }, ); $loop->add( $stream ); my $console = Tickit::Console->new( on_line => sub { my ( $self, $line ) = @_; if( $line =~ s{^/([a-z]+)}{}i ) { my $cmd = lc $1; given( $cmd ) { when( "lf" ) { my $str = String::Tagged->new( "-> LF" ); $str->apply_tag( 0, 5, fg => 'red' ); $tab->add_line( $str ); $stream->write( "\r\n" ); } when( "quit" ) { $loop->stop; } } } else { my $str = String::Tagged->new( "-> $line" ); $str->apply_tag( 0, 2, fg => 'red' ); $tab->add_line( $str ); $stream->write( "$line\r\n" ); } }, ); $tab = $console->add_tab( name => "netcat", timestamp_format => "[%H:%M:%S] ", ); $loop->resolver->getnameinfo( addr => $stream->read_handle->peername, on_resolved => sub { my ( $rev_host, $rev_service ) = @_; my $str = String::Tagged->new( "Connected to $rev_host:$rev_service" ); $str->apply_tag( -1, -1, fg => 'blue' ); $tab->add_line( $str ); }, on_error => sub { my $str = String::Tagged->new( "Connected to $host:$service [reverse unknown]" ); $str->apply_tag( -1, -1, fg => 'blue' ); $tab->add_line( $str ); }, ); my $tickit = Tickit::Async->new; $loop->add( $tickit ); $tickit->set_root_widget( $console ); $tickit->run; Tickit-Console-0.12/lib000755001750001750 014541672643 13566 5ustar00leoleo000000000000Tickit-Console-0.12/lib/Tickit000755001750001750 014541672643 15015 5ustar00leoleo000000000000Tickit-Console-0.12/lib/Tickit/Console.pm000444001750001750 1420414541672643 17133 0ustar00leoleo000000000000# You may distribute under the terms of either the GNU General Public License # or the Artistic License (the same terms as Perl itself) # # (C) Paul Evans, 2011-2023 -- leonerd@leonerd.org.uk use v5.26; # signatures use warnings; use Object::Pad 0.800 ':experimental(adjust_params)'; package Tickit::Console 0.12; class Tickit::Console :isa(Tickit::Widget::VBox); use Tickit::Widget::Entry; use Tickit::Widget::Scroller 0.04; use Tickit::Widget::Tabbed 0.003; use Tickit::Console::Tab; use Scalar::Util qw( weaken ); =head1 NAME C - build full-screen console-style applications =head1 SYNOPSIS my $console = Tickit::Console->new; Tickit->new( root => $console )->run; =head1 DESCRIPTION A C instance is a subclass of L intended to help building a full-screen console-style application which presents the user with one or more scrollable text areas, selectable as tabs on a ribbon, with a text entry area at the bottom of the screen for entering commands or other data. As a L subclass it can be added anywhere within a widget tree, though normally it would be used as the root widget for a L instance. =cut =head1 CONSTRUCTOR =cut =head2 new $console = Tickit::Console->new( %args ); Returns a new instance of a C. Takes the following named arguments: =over 8 =item on_line => CODE Callback to invoke when a line of text is entered in the entry widget. $on_line->( $active_tab, $text ); =item tab_class => STRING Optional. If set, gives a class name (which should be a subclass of L) to construct newly-added tabs with. This setting allows an application to provide new methods in tabs to change behaviours. =item timestamp_format, datestamp_format Optional. If supplied, these will be stored as default values to pass to the tab constructor in the C method. =back =cut field %_default_tab_opts; field $_tabbed; field $_entry; ADJUST :params ( :$on_line = undef, :$timestamp_format = undef, :$datestamp_format = undef, :$tab_class = "Tickit::Console::Tab", ) { $_default_tab_opts{timestamp_format} = $timestamp_format; $_default_tab_opts{datestamp_format} = $datestamp_format; $self->add( $_tabbed = Tickit::Widget::Tabbed->new( tab_position => "bottom", tab_class => $tab_class, ), expand => 1, ); $self->add( $_entry = Tickit::Widget::Entry->new ); weaken( my $weakself = $self ); $_entry->set_on_enter( sub ( $entry, @ ) { return unless $weakself; my $line = $entry->text; $entry->set_text( "" ); my $tab = $weakself->active_tab; $tab->_on_line( $line ) or $on_line->( $tab, $line ); } ); } =head1 METHODS =cut =head2 add_tab $tab = $console->add_tab( %args ); Adds a new tab to the console, and returns a L object representing it. Takes the following named arguments: =over 8 =item name => STRING Name for the tab. =item on_line => CODE Optional. Provides a different callback to invoke when a line of text is entered while this tab is active. Invoked the same way as above. =item make_widget => CODE Optional. Gives a piece of code used to construct the actual L used as this tab's child in the ribbon. A C to hold the tab's content will be passed in to this code, which should construct some sort of widget tree with that inside it, and return it. This can be used to apply a decorative frame, place the scroller in a split box or other layout along with other widgets, or various other effects. $tab_widget = $make_widget->( $scroller ); =back Any other named arguments are passed to the tab's constructor. =cut method add_tab ( %args ) { my $make_widget = delete $args{make_widget}; my $scroller = Tickit::Widget::Scroller->new( gravity => "bottom" ); my $widget = $make_widget ? $make_widget->( $scroller ) : $scroller; my $tab = $_tabbed->add_tab( $widget, label => delete $args{name}, console => $self, scroller => $scroller, %_default_tab_opts, %args, ); return $tab; } =head2 active_tab_index $index = $console->active_tab_index; =head2 active_tab $tab = $console->active_tab; =head2 remove_tab $console->remove_tab( $tab_or_index ); =head2 move_tab $console->move_tab( $tab_or_index, $delta ); =head2 activate_tab $console->activate_tab( $tab_or_index ); =head2 next_tab $console->next_tab; =head2 prev_tab $console->prev_tab; These methods are all passed through to the underlying L object. =cut BEGIN { use Object::Pad 0.800 ':experimental(mop)'; my $meta = Object::Pad::MOP::Class->for_caller; foreach my $method (qw( active_tab_index active_tab remove_tab move_tab activate_tab next_tab prev_tab )) { $meta->add_method( $method => method { $_tabbed->$method( @_ ); } ); } } =head2 bind_key $console->bind_key( $key, $code ); Installs a callback to invoke if the given key is pressed, overwriting any previous callback for the same key. The code block is invoked as $code->( $console, $key ); If C<$code> is missing or C, any existing callback is removed. =cut field %_keybindings; method bind_key ( $key, $code ) { $_keybindings{$key}[0] = $code; $self->_update_key_binding( $key ); } method _update_key_binding ( $key ) { my $bindings = $_keybindings{$key}; if( $bindings->[0] or $bindings->[1] ) { $_entry->bind_keys( $key => sub ( $entry, $key ) { $entry->parent->_on_key( $key ); }); } else { $_entry->bind_key( $key => undef ); } } method _inc_key_binding ( $key ) { $_keybindings{$key}[1]++; $self->_update_key_binding( $key ); } method _dec_key_binding ( $key ) { $_keybindings{$key}[1]--; $self->_update_key_binding( $key ); } method _on_key ( $key ) { if( my $tab = $self->active_tab ) { return 1 if $tab->_on_key( $key ); } my $code = $_keybindings{$key}[0] or return 0; return $code->( $self, $key ); } =head1 AUTHOR Paul Evans =cut 0x55AA; Tickit-Console-0.12/lib/Tickit/Console000755001750001750 014541672643 16417 5ustar00leoleo000000000000Tickit-Console-0.12/lib/Tickit/Console/Tab.pm000444001750001750 1545014541672643 17645 0ustar00leoleo000000000000# You may distribute under the terms of either the GNU General Public License # or the Artistic License (the same terms as Perl itself) # # (C) Paul Evans, 2014-2023 -- leonerd@leonerd.org.uk use v5.26; # signatures use warnings; use Object::Pad 0.800 ':experimental(init_expr)'; use Tickit::Widget::Tabbed 0.024; package Tickit::Console::Tab 0.12; class Tickit::Console::Tab :isa(Tickit::Widget::Tabbed::Tab) :strict(params); use Tickit::Widget::Scroller::Item::Text; use Tickit::Widget::Scroller::Item::RichText; use String::Tagged 0.10; use POSIX (); use Scalar::Util qw( blessed weaken ); =head1 NAME C - represent a single tab on a C =head1 DESCRIPTION Objects in this class represent a single switchable tab within a L. They are not constructed directly, but instead are returned by the C method of the underlying C object. =cut =head1 PARAMETERS The following extra parameters may be passed to the constructor, or via the C method on the C object: =over 8 =item timestamp_format => STRING or String::Tagged If defined, every line is prefixed with a timestamp built by applying the C function to this string. If a L instance is applied it will preserve all the formatting from it. =item datestamp_format => STRING or String::Tagged If defined, every time a line is added to the buffer, if it starts a new day since the previous message (because the format yields a different string), this message is added as well to the scroller. =item localtime => CODE If defined, provides an alternative function to C for converting an epoch value into a timestamp. For example, this may be set to sub { gmtime $_[0] } to generate timestamps in UTC instead of using the local timezone. =back =cut field $_scroller :param; field $_console :param :weak; field $_on_line :param = undef; field $_timestamp_format :param; field $_datestamp_format :param; field $_localtime :param = sub ( $time ) { localtime $time }; =head1 METHODS =cut =head2 name =head2 set_name $name = $tab->name; $tab->set_name( $name ); Returns or sets the tab name text =cut method name () { return $self->label; } method set_name ( $name ) { $self->set_label( $name ); } =head2 append_line $tab->append_line( $string, %opts ); Appends a line of text to the tab. C<$string> may either be a plain perl string, or an instance of L containing formatting tags, as specified by L. Options will be passed to the L used to contain the string. Also recognises the following options: =over 8 =item time => NUM Overrides the epoch C value used to generate a timestamp for this line =item timestamp_format => STRING or String::Tagged Overrides the stored format for generating a timestamp string. =item datestamp_format => STRING or String::Tagged Overrides the stored format for generating a datestamp string. =back =cut sub strftime ( $format, @t ) { if( blessed $format and $format->isa( "String::Tagged" ) ) { my $fplain = $format->str; my $ret = String::Tagged->new; # Iterate format specifiers and other literal text foreach my $m ( $format->matches( qr/%[_0#^-]?[OE]?.|[^%]+/ ) ) { if( $m =~ m/^%/ ) { # Format specifier $ret->append_tagged( POSIX::strftime( $m, @t ), %{ $m->get_tags_at( 0 ) } ); } else { # Literal $ret->append( $m ); } } return $ret; } else { return POSIX::strftime( $format, @t ); } } sub _make_item ( $string, %opts ) { if( blessed $string and $string->isa( "String::Tagged" ) ) { return Tickit::Widget::Scroller::Item::RichText->new( $string, %opts ); } else { return Tickit::Widget::Scroller::Item::Text->new( $string, %opts ); } } field $_dusk_datestamp; field $_dawn_datestamp; method _make_item_with_timestamp ( $string, %opts ) { if( my $timestamp_format = delete $opts{timestamp_format} // $_timestamp_format ) { my $time = delete $opts{time} // time(); my $timestamp = strftime( $timestamp_format, $_localtime->( $time ) ); $string = $timestamp . $string; } return _make_item( $string, %opts ); } method append_line ( $string, %opts ) { if( my $datestamp_format = delete $opts{datestamp_format} // $_datestamp_format ) { my $time = $opts{time} //= time(); my $plain = POSIX::strftime( $datestamp_format, my @t = $_localtime->( $time ) ); if( ( $_dusk_datestamp // "" ) ne $plain ) { my $datestamp = strftime( $datestamp_format, @t ); $_scroller->push( _make_item( $datestamp ) ); $_dusk_datestamp = $plain; $_dawn_datestamp //= $plain; } } $_scroller->push( $self->_make_item_with_timestamp( $string, %opts ) ); } *add_line = \&append_line; =head2 prepend_line $tab->prepend_line( $string, %opts ); As C, but prepends it at the beginning of the scroller. =cut method prepend_line ( $string, %opts ) { my $datestamp_item; if( my $datestamp_format = delete $opts{datestamp_format} // $_datestamp_format ) { my $time = $opts{time} //= time(); my $plain = POSIX::strftime( $datestamp_format, my @t = $_localtime->( $time ) ); $_scroller->shift if ( $_dawn_datestamp // "" ) eq $plain; my $datestamp = strftime( $datestamp_format, @t ); $datestamp_item = _make_item( $datestamp ); $_dawn_datestamp = $plain; $_dusk_datestamp //= $plain; } $_scroller->unshift( $self->_make_item_with_timestamp( $string, %opts ) ); $_scroller->unshift( $datestamp_item ) if $datestamp_item; } =head2 bind_key $tab->bind_key( $key, $code ); Installs a callback to invoke if the given key is pressed while this tab has focus, overwriting any previous callback for the same key. The code block is invoked as $result = $code->( $tab, $key ); If C<$code> is missing or C, any existing callback is removed. This callback will be invoked before one defined on the console object itself, if present. If it returns a false value, then the one on the console will be invoked instead. =cut field %_keybindings; method bind_key ( $key, $code ) { if( not $_keybindings{$key} and $code ) { $_console->_inc_key_binding( $key ); } elsif( $_keybindings{$key} and not $code ) { $_console->_dec_key_binding( $key ); } $_keybindings{$key} = $code; } method _on_line ( $line ) { $_on_line or return 0; $_on_line->( $self, $line ); return 1; } method _on_key ( $key ) { return 1 if $_keybindings{$key} and $_keybindings{$key}->( $self, $key ); return 0; } =head1 AUTHOR Paul Evans =cut 0x55AA; Tickit-Console-0.12/t000755001750001750 014541672643 13263 5ustar00leoleo000000000000Tickit-Console-0.12/t/00use.t000444001750001750 17214541672643 14521 0ustar00leoleo000000000000#!/usr/bin/perl use v5.26; use warnings; use Test2::V0; require Tickit::Console; pass "Modules loaded"; done_testing; Tickit-Console-0.12/t/01basic.t000444001750001750 624714541672643 15040 0ustar00leoleo000000000000#!/usr/bin/perl use v5.26; use warnings; use Test2::V0 0.000148; use Tickit::Test; use String::Tagged; use Tickit::Console; my $win = mk_window; my $console = Tickit::Console->new; ok( defined $console, 'defined $console' ); is_oneref( $console, '$console has refcount 1 initially' ); $console->set_window( $win ); flush_tickit; is_termlog( [ ( map { GOTO($_,0), SETBG(undef), ERASECH(80) } 0 .. 22 ), GOTO(23,0), SETBG(4), ERASECH(80), GOTO(24,0), SETBG(undef), ERASECH(80), GOTO(24,0) ], 'Termlog initially' ); is_display( [ BLANKLINES(23), BLANKLINE(bg=>4), BLANKLINE() ], 'Display initially' ); is_cursorpos( 24, 0, 'Cursor position initially' ); my $tab = $console->add_tab( name => "Tabname" ); flush_tickit; is_display( [ BLANKLINES(23), [TEXT("[",fg=>7,bg=>4),TEXT("Tabname",fg=>14,bg=>4),TEXT("]",fg=>7,bg=>4),TEXT("",bg=>4)], BLANKLINE() ], 'Display after ->add_tab' ); is_cursorpos( 24, 0, 'Cursor position after ->add_tab' ); $tab->append_line( "A line of content" ); flush_tickit; is_display( [ [TEXT("A line of content")], BLANKLINES(22), [TEXT("[",fg=>7,bg=>4),TEXT("Tabname",fg=>14,bg=>4),TEXT("]",fg=>7,bg=>4),TEXT("",bg=>4)], BLANKLINE() ], 'Display after tab->append_line' ); is_cursorpos( 24, 0, 'Cursor position after tab->append_line' ); my $text = String::Tagged->new( "Content with formatting in it" ); $text->apply_tag( 0, 7, b => 1 ); $text->apply_tag( 13, 10, u => 1 ); $tab->append_line( $text ); flush_tickit; is_display( [ [TEXT("A line of content")], [TEXT("Content",b=>1),TEXT(" with "),TEXT("formatting",u=>1),TEXT(" in it")], BLANKLINES(21), [TEXT("[",fg=>7,bg=>4),TEXT("Tabname",fg=>14,bg=>4),TEXT("]",fg=>7,bg=>4),TEXT("",bg=>4)], BLANKLINE() ], 'Display after tab->append_line tagged' ); $tab->append_line( "XXXX " x 20, indent => 4 ); flush_tickit; is_display( [ [TEXT("A line of content")], [TEXT("Content",b=>1),TEXT(" with "),TEXT("formatting",u=>1),TEXT(" in it")], [TEXT("XXXX " x 16)], [TEXT(" "),TEXT("XXXX " x 4),TEXT("")], BLANKLINES(19), [TEXT("[",fg=>7,bg=>4),TEXT("Tabname",fg=>14,bg=>4),TEXT("]",fg=>7,bg=>4),TEXT("",bg=>4)], BLANKLINE() ], 'Display after tab->append_line with indent' ); $tab->prepend_line( "This line first" ); flush_tickit; is_display( [ [TEXT("This line first")], [TEXT("A line of content")], [TEXT("Content",b=>1),TEXT(" with "),TEXT("formatting",u=>1),TEXT(" in it")], [TEXT("XXXX " x 16)], [TEXT(" "),TEXT("XXXX " x 4),TEXT("")], BLANKLINES(18), [TEXT("[",fg=>7,bg=>4),TEXT("Tabname",fg=>14,bg=>4),TEXT("]",fg=>7,bg=>4),TEXT("",bg=>4)], BLANKLINE() ], 'Display after tab->prepend_line' ); is_oneref( $console, '$console has refcount 1 at EOF' ); done_testing; Tickit-Console-0.12/t/02tabs.t000444001750001750 304714541672643 14704 0ustar00leoleo000000000000#!/usr/bin/perl use v5.26; use warnings; use Test2::V0; use Tickit::Test; use Tickit::Console; my $win = mk_window; my $console = Tickit::Console->new; $console->set_window( $win ); my @tabs = map { $console->add_tab( name => $_ ) } qw( Tab0 Tab1 Tab2 ); flush_tickit; is_display( [ BLANKLINES(23), [TEXT("[",fg=>7,bg=>4),TEXT("Tab0",fg=>14,bg=>4),TEXT("]Tab1 Tab2 ",fg=>7,bg=>4),TEXT("",bg=>4)], BLANKLINE() ], 'Display after ->add_tab' ); is_cursorpos( 24, 0, 'Cursor position after ->add_tab' ); is( $console->active_tab_index, 0, '$console->active_tab_index' ); ref_is( $console->active_tab, $tabs[0], '$console->active_tab' ); is( $tabs[0]->index, 0, '$tab[0]->index' ); is( $tabs[0]->name, "Tab0", '$tab[0]->name' ); $tabs[0]->set_name( "Newname" ); is( $tabs[0]->name, "Newname", '$tab[0]->name after ->set_name' ); flush_tickit; is_display( [ BLANKLINES(23), [TEXT("[",fg=>7,bg=>4),TEXT("Newname",fg=>14,bg=>4),TEXT("]Tab1 Tab2 ",fg=>7,bg=>4),TEXT("",bg=>4)], BLANKLINE() ], 'Display after $tab->set_name' ); $console->activate_tab( 1 ); is( $console->active_tab_index, 1, '$console->active_tab_index after ->activate_tab' ); ref_is( $console->active_tab, $tabs[1], '$console->active_tab after ->activate_tab' ); flush_tickit; is_display( [ BLANKLINES(23), [TEXT(" Newname[",fg=>7,bg=>4),TEXT("Tab1",fg=>14,bg=>4),TEXT("]Tab2 ",fg=>7,bg=>4),TEXT("",bg=>4)], BLANKLINE() ], 'Display after ->activate_tab' ); done_testing; Tickit-Console-0.12/t/03input.t000444001750001750 400614541672643 15107 0ustar00leoleo000000000000#!/usr/bin/perl use v5.26; use warnings; use Test2::V0; use Tickit::Test; use Tickit::Console; my $win = mk_window; my $on_line_invocant; my @lines; my $console = Tickit::Console->new( on_line => sub { $on_line_invocant = $_[0]; push @lines, $_[1]; }, ); $console->set_window( $win ); my $tab = $console->add_tab( name => "Tab" ); flush_tickit; is_display( [ BLANKLINES(23), [TEXT("[",fg=>7,bg=>4),TEXT("Tab",fg=>14,bg=>4),TEXT("]",fg=>7,bg=>4),TEXT("",bg=>4)], BLANKLINE() ], 'Display initially' ); is_cursorpos( 24, 0, 'Cursor position initially' ); presskey( text => $_ ) for split //, "Hello"; flush_tickit; is_display( [ BLANKLINES(23), [TEXT("[",fg=>7,bg=>4),TEXT("Tab",fg=>14,bg=>4),TEXT("]",fg=>7,bg=>4),TEXT("",bg=>4)], [TEXT("Hello"),TEXT("")] ], 'Display after "Hello"' ); is_cursorpos( 24, 5, 'Cursor after "Hello"' ); is( scalar @lines, 0, 'No @lines yet before Enter' ); presskey( key => "Enter" ); flush_tickit; is_display( [ BLANKLINES(23), [TEXT("[",fg=>7,bg=>4),TEXT("Tab",fg=>14,bg=>4),TEXT("]",fg=>7,bg=>4),TEXT("",bg=>4)], BLANKLINE() ], 'Display after Enter' ); is_cursorpos( 24, 0, 'Cursor after Enter' ); ref_is( $on_line_invocant, $tab, 'on_line invocant is $tab' ); is( \@lines, [ "Hello" ], '@lines after Enter' ); my @special_lines; my $special_tab = $console->add_tab( name => "Tab2", on_line => sub { push @special_lines, $_[1] }, ); undef @lines; $console->activate_tab( $special_tab ); flush_tickit; is_display( [ BLANKLINES(23), [TEXT(" Tab[",fg=>7,bg=>4),TEXT("Tab2",fg=>14,bg=>4),TEXT("]",fg=>7,bg=>4),TEXT("",bg=>4)], BLANKLINE() ], 'Display after ->add_tab special' ); presskey( text => $_ ) for split //, "Another"; presskey( key => "Enter" ); is( \@lines, [], '@lines empty after entry on special tab' ); is( \@special_lines, [ "Another" ], '@special_lines after entry on special tab' ); done_testing; Tickit-Console-0.12/t/04make_widget.t000444001750001750 275614541672643 16243 0ustar00leoleo000000000000#!/usr/bin/perl use v5.26; use warnings; use Test2::V0; use Tickit::Test; use Tickit::Console; use Tickit::Widget::Static; use Tickit::Widget::HBox; my $win = mk_window; my $console = Tickit::Console->new; $console->set_window( $win ); # A particularly silly layout my $tab = $console->add_tab( name => "Silly", make_widget => sub { my ( $scroller ) = @_; my $hbox = Tickit::Widget::HBox->new( spacing => 2, ); $hbox->add( Tickit::Widget::Static->new( text => "Left" ) ); $hbox->add( $scroller, expand => 1 ); $hbox->add( Tickit::Widget::Static->new( text => "Right" ) ); return $hbox; }, ); flush_tickit; is_display( [ [TEXT("Left"), BLANK(71), TEXT("Right")], BLANKLINES(22), [TEXT("[",fg=>7,bg=>4), TEXT("Silly",fg=>14,bg=>4), TEXT("]",fg=>7,bg=>4), BLANK(73,bg=>4)], BLANKLINE() ], 'Display initially with make_widget' ); $tab->append_line( "One" ); $tab->append_line( "Two" ); $tab->append_line( "Three" ); flush_tickit; is_display( [ [TEXT("Left"), BLANK(2), TEXT("One"), BLANK(66), TEXT("Right")], [BLANK(6), TEXT("Two"), BLANK(71) ], [BLANK(6), TEXT("Three"), BLANK(69) ], BLANKLINES(20), [TEXT("[",fg=>7,bg=>4), TEXT("Silly",fg=>14,bg=>4), TEXT("]",fg=>7,bg=>4), BLANK(73,bg=>4)], BLANKLINE() ], 'Display after ->append_line on tab with custom widget' ); done_testing; Tickit-Console-0.12/t/05bind_key.t000444001750001750 252514541672643 15542 0ustar00leoleo000000000000#!/usr/bin/perl use v5.26; use warnings; use Test2::V0; use Tickit::Test; use Tickit::Console; my $win = mk_window; my $console = Tickit::Console->new; $console->set_window( $win ); my @global_keys; $console->bind_key( 'A-x' => sub { push @global_keys, [ @_ ]; }); presskey( key => "A-x" ); flush_tickit; is( \@global_keys, [ [ exact_ref($console), 'A-x' ] ], 'Console-level key binding receives key' ); undef @global_keys; my $tab = $console->add_tab( name => "Tab" ); presskey( key => "A-x" ); flush_tickit; is( \@global_keys, [ [ exact_ref($console), 'A-x' ] ], 'Console-level key binding receives key with tab focused' ); undef @global_keys; { my @tab_keys; $tab->bind_key( 'A-x' => sub { push @tab_keys, [ @_ ]; }); presskey( key => "A-x" ); flush_tickit; is( \@tab_keys, [ [ exact_ref($tab), 'A-x' ] ], 'Tab-level key binding receives key' ); is( scalar @global_keys, 0, 'Console-level key binding does not receive key with tab focused' ); undef @tab_keys; $tab->bind_key( 'A-x' => undef ); presskey( key => "A-x" ); flush_tickit; is( scalar @tab_keys, 0, 'Removed tab-level key binding no longer receives key' ); is( \@global_keys, [ [ exact_ref($console), "A-x" ] ], 'Console-level keybinding receives key again' ); } done_testing; Tickit-Console-0.12/t/06timestamp.t000444001750001750 715714541672643 15770 0ustar00leoleo000000000000#!/usr/bin/perl use v5.26; use warnings; use Test2::V0; use Tickit::Test; use String::Tagged; use Tickit::Console; my $win = mk_window; my $console = Tickit::Console->new; $console->set_window( $win ); # Just timestamp, plain { my $tab = $console->add_tab( name => "Tabname", timestamp_format => "[%H:%M:%S] ", localtime => sub { gmtime $_[0] }, ); $tab->append_line( "First line", time => 123456789, # 1973/11/29 21:33:09 ); flush_tickit; is_display( [ [TEXT("[21:33:09] First line")], BLANKLINES(22), [TEXT("[",fg=>7,bg=>4),TEXT("Tabname",fg=>14,bg=>4),TEXT("]",fg=>7,bg=>4),TEXT("",bg=>4)], BLANKLINE() ], 'Display after tab->append_line with timestamp' ); $console->remove_tab( $tab ); } # Just timestamp, String::Tagged { my $tab = $console->add_tab( name => "Tabname", timestamp_format => String::Tagged->new( "[%H:%M] " ) ->apply_tag( 1, 2, fg => "red" ) ->apply_tag( 4, 2, fg => "blue" ), localtime => sub { gmtime $_[0] }, ); $tab->append_line( "First line", time => 123456789, # 1973/11/29 21:33:09 ); flush_tickit; is_display( [ [TEXT("["), TEXT("21",fg=>1), TEXT(":"), TEXT("33",fg=>4), TEXT("] First line")], BLANKLINES(22), [TEXT("[",fg=>7,bg=>4),TEXT("Tabname",fg=>14,bg=>4),TEXT("]",fg=>7,bg=>4),TEXT("",bg=>4)], BLANKLINE() ], 'Display after tab->append_line with formatted timestamp' ); $console->remove_tab( $tab ); } # Time + Datestamp, appending { my $tab = $console->add_tab( name => "Tabname", timestamp_format => "[%H:%M] ", datestamp_format => "- day is now %Y/%m/%d -", localtime => sub { gmtime $_[0] }, ); $tab->append_line( "First line", time => 123456789, # 1973/11/29 21:33:09 ); $tab->append_line( "Second line", time => 123456792, # 1973/11/29 21:33:12 ); $tab->append_line( "Third line", time => 123498765, # 1973/11/30 09:12:45 ); flush_tickit; is_display( [ [TEXT("- day is now 1973/11/29 -")], [TEXT("[21:33] First line")], [TEXT("[21:33] Second line")], [TEXT("- day is now 1973/11/30 -")], [TEXT("[09:12] Third line")], BLANKLINES(18), [TEXT("[",fg=>7,bg=>4),TEXT("Tabname",fg=>14,bg=>4),TEXT("]",fg=>7,bg=>4),TEXT("",bg=>4)], BLANKLINE() ], 'Display after tab->append_line with datestamp' ); $console->remove_tab( $tab ); } # Time + Datestamp, prepending { my $tab = $console->add_tab( name => "Tabname", timestamp_format => "[%H:%M] ", datestamp_format => "- day is now %Y/%m/%d -", localtime => sub { gmtime $_[0] }, ); $tab->prepend_line( "First line", time => 123456789, # 1973/11/29 21:33:09 ); $tab->prepend_line( "Second line", time => 123456787, # 1973/11/29 21:33:07 ); $tab->prepend_line( "Third line", time => 123345678, # 1973/11/28 14:41:18 ); flush_tickit; is_display( [ [TEXT("- day is now 1973/11/28 -")], [TEXT("[14:41] Third line")], [TEXT("- day is now 1973/11/29 -")], [TEXT("[21:33] Second line")], [TEXT("[21:33] First line")], BLANKLINES(18), [TEXT("[",fg=>7,bg=>4),TEXT("Tabname",fg=>14,bg=>4),TEXT("]",fg=>7,bg=>4),TEXT("",bg=>4)], BLANKLINE() ], 'Display after tab->append_line with datestamp' ); $console->remove_tab( $tab ); } done_testing; Tickit-Console-0.12/t/99pod.t000444001750001750 25514541672643 14533 0ustar00leoleo000000000000#!/usr/bin/perl use v5.26; use warnings; use Test2::V0; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok();