summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgregor herrmann <gregoa@debian.org>2022-05-07 17:47:27 +0200
committergregor herrmann <gregoa@debian.org>2022-05-07 17:47:27 +0200
commited81870975cf1014f09972bc93470b6c177e9fec (patch)
tree516b6d48c283956f72d5306128ac7ccc16e33f04
parent3f0886f27067e92728c5cbd204f367f7f60f8fb6 (diff)
New upstream version 0.28
-rw-r--r--Changes5
-rw-r--r--LICENSE18
-rw-r--r--MANIFEST10
-rw-r--r--META.json10
-rw-r--r--META.yml8
-rw-r--r--Makefile.PL18
-rw-r--r--lib/Tickit/Widget/Scroller.pm2
-rw-r--r--lib/Tickit/Widget/Scroller/Item/RichText.pm48
-rw-r--r--lib/Tickit/Widget/Scroller/Item/Text.pm2
-rw-r--r--t/03item-richtext-formatting.t66
10 files changed, 142 insertions, 45 deletions
diff --git a/Changes b/Changes
index d8bbd5b..9185a35 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,10 @@
Revision history for Tickit-Widget-Scroller
+0.28 2022-04-25
+ [CHANGES]
+ * Added `new_from_formatting` convenience constructor to
+ Tickit::Widget::Scroller::Item::RichText
+
0.27 2021-11-20
[CHANGES]
* Updates for Object::Pad 0.57
diff --git a/LICENSE b/LICENSE
index f15476d..7f7fca7 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,4 @@
-This software is copyright (c) 2021 by Paul Evans <leonerd@leonerd.org.uk>.
+This software is copyright (c) 2022 by Paul Evans <leonerd@leonerd.org.uk>.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
@@ -12,7 +12,7 @@ b) the "Artistic License"
--- The GNU General Public License, Version 1, February 1989 ---
-This software is Copyright (c) 2021 by Paul Evans <leonerd@leonerd.org.uk>.
+This software is Copyright (c) 2022 by Paul Evans <leonerd@leonerd.org.uk>.
This is free software, licensed under:
@@ -272,7 +272,7 @@ That's all there is to it!
--- The Artistic License 1.0 ---
-This software is Copyright (c) 2021 by Paul Evans <leonerd@leonerd.org.uk>.
+This software is Copyright (c) 2022 by Paul Evans <leonerd@leonerd.org.uk>.
This is free software, licensed under:
@@ -292,21 +292,21 @@ Definitions:
- "Package" refers to the collection of files distributed by the Copyright
Holder, and derivatives of that collection of files created through
- textual modification.
+ 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.
+ Holder.
- "Copyright Holder" is whoever is named in the copyright or copyrights for
- the package.
+ 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.)
+ 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.
+ 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
@@ -373,7 +373,7 @@ 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
-MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
The End
diff --git a/MANIFEST b/MANIFEST
index 7202cf5..d760c9b 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -6,15 +6,11 @@ lib/Tickit/Widget/Scroller.pm
lib/Tickit/Widget/Scroller/Item.pod
lib/Tickit/Widget/Scroller/Item/RichText.pm
lib/Tickit/Widget/Scroller/Item/Text.pm
-LICENSE
-Makefile.PL
MANIFEST This list of files
-META.json
-META.yml
-README
t/00use.t
t/01item-text.t
t/02item-richtext.t
+t/03item-richtext-formatting.t
t/10initial.t
t/11scroll.t
t/12resize-bottom.t
@@ -29,3 +25,7 @@ t/23pop-bottom.t
t/23pop-top.t
t/30indicator.t
t/99pod.t
+README
+LICENSE
+META.yml
+META.json
diff --git a/META.json b/META.json
index 01e8bc1..5deeb8b 100644
--- a/META.json
+++ b/META.json
@@ -35,15 +35,15 @@
"provides" : {
"Tickit::Widget::Scroller" : {
"file" : "lib/Tickit/Widget/Scroller.pm",
- "version" : "0.27"
+ "version" : "0.28"
},
"Tickit::Widget::Scroller::Item::RichText" : {
"file" : "lib/Tickit/Widget/Scroller/Item/RichText.pm",
- "version" : "0.27"
+ "version" : "0.28"
},
"Tickit::Widget::Scroller::Item::Text" : {
"file" : "lib/Tickit/Widget/Scroller/Item/Text.pm",
- "version" : "0.27"
+ "version" : "0.28"
}
},
"release_status" : "stable",
@@ -53,6 +53,6 @@
],
"x_IRC" : "irc://irc.freenode.net/#tickit"
},
- "version" : "0.27",
- "x_serialization_backend" : "JSON::PP version 4.05"
+ "version" : "0.28",
+ "x_serialization_backend" : "JSON::PP version 4.06"
}
diff --git a/META.yml b/META.yml
index 084fb35..00bb722 100644
--- a/META.yml
+++ b/META.yml
@@ -15,13 +15,13 @@ name: Tickit-Widget-Scroller
provides:
Tickit::Widget::Scroller:
file: lib/Tickit/Widget/Scroller.pm
- version: '0.27'
+ version: '0.28'
Tickit::Widget::Scroller::Item::RichText:
file: lib/Tickit/Widget/Scroller/Item/RichText.pm
- version: '0.27'
+ version: '0.28'
Tickit::Widget::Scroller::Item::Text:
file: lib/Tickit/Widget/Scroller/Item/Text.pm
- version: '0.27'
+ version: '0.28'
requires:
Object::Pad: '0.57'
String::Tagged: '0'
@@ -33,5 +33,5 @@ requires:
resources:
IRC: irc://irc.freenode.net/#tickit
license: http://dev.perl.org/licenses/
-version: '0.27'
+version: '0.28'
x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
diff --git a/Makefile.PL b/Makefile.PL
deleted file mode 100644
index d8d3a0b..0000000
--- a/Makefile.PL
+++ /dev/null
@@ -1,18 +0,0 @@
-# Note: this file was auto-generated by Module::Build::Compat version 0.4220
-use ExtUtils::MakeMaker;
-WriteMakefile
-(
- 'NAME' => 'Tickit::Widget::Scroller',
- 'VERSION_FROM' => 'lib/Tickit/Widget/Scroller.pm',
- 'PREREQ_PM' => {
- 'String::Tagged' => 0,
- 'Tickit::Pen' => '0.19',
- 'Tickit::RenderBuffer' => '0.43',
- 'Tickit::Widget' => '0.35',
- 'Tickit::Window' => '0.57'
- },
- 'INSTALLDIRS' => 'site',
- 'EXE_FILES' => [],
- 'PL_FILES' => {}
-)
-;
diff --git a/lib/Tickit/Widget/Scroller.pm b/lib/Tickit/Widget/Scroller.pm
index e47beeb..81c7b6b 100644
--- a/lib/Tickit/Widget/Scroller.pm
+++ b/lib/Tickit/Widget/Scroller.pm
@@ -6,7 +6,7 @@
use v5.26; # signatures
use Object::Pad 0.57;
-package Tickit::Widget::Scroller 0.27;
+package Tickit::Widget::Scroller 0.28;
class Tickit::Widget::Scroller
:isa(Tickit::Widget);
diff --git a/lib/Tickit/Widget/Scroller/Item/RichText.pm b/lib/Tickit/Widget/Scroller/Item/RichText.pm
index c532fa8..add77f7 100644
--- a/lib/Tickit/Widget/Scroller/Item/RichText.pm
+++ b/lib/Tickit/Widget/Scroller/Item/RichText.pm
@@ -5,7 +5,7 @@
use Object::Pad 0.57;
-package Tickit::Widget::Scroller::Item::RichText 0.27;
+package Tickit::Widget::Scroller::Item::RichText 0.28;
class Tickit::Widget::Scroller::Item::RichText
:isa(Tickit::Widget::Scroller::Item::Text);
@@ -38,10 +38,54 @@ with rendering attributes, used to apply formatting. The attributes are stored
by supplying the text in an instance of a L<String::Tagged> object.
The recognised attributes are those of L<Tickit::Pen>, taking the same names
-and values.
+and values. To use a L<String::Tagged::Formatting> instance instead, use the
+L</new_from_formatting> constructor.
=cut
+=head1 CONSTRUCTOR
+
+=cut
+
+=head2 new_from_formatting
+
+ $item = Tickit::Widget::Scroller::Item::RichText->new_from_formatting( $str, %opts )
+
+Constructs a new item containing the text given by the L<String::Tagged>
+instance, converting the tags from the L<String::Tagged::Formatting>
+convention into native L<Tickit::Pen> format.
+
+=cut
+
+sub _convert_color_tag ($n, $v)
+{
+ return $n => $v->as_xterm->index;
+}
+
+my %convert_tags = (
+ bold => "b",
+ under => "u",
+ italic => "i",
+ strike => "strike",
+ blink => "blink",
+ monospace => sub ($, $v) { "af" => ( $v ? 1 : 0 ) },
+ reverse => "rv",
+ fg => \&_convert_color_tag,
+ bg => \&_convert_color_tag,
+);
+
+sub new_from_formatting ( $class, $str, %opts )
+{
+ return $class->new(
+ # TODO: Maybe this should live somewhere more fundamental in Tickit itself?
+ $str->clone(
+ only_tags => [ keys %convert_tags ],
+ convert_tags => \%convert_tags,
+ ),
+ %opts
+ );
+}
+
method _build_chunks_for ( $str )
{
my @chunks;
diff --git a/lib/Tickit/Widget/Scroller/Item/Text.pm b/lib/Tickit/Widget/Scroller/Item/Text.pm
index 21051ca..3f37c89 100644
--- a/lib/Tickit/Widget/Scroller/Item/Text.pm
+++ b/lib/Tickit/Widget/Scroller/Item/Text.pm
@@ -5,7 +5,7 @@
use Object::Pad 0.27;
-package Tickit::Widget::Scroller::Item::Text 0.27;
+package Tickit::Widget::Scroller::Item::Text 0.28;
class Tickit::Widget::Scroller::Item::Text;
use Tickit::Utils qw( textwidth cols2chars );
diff --git a/t/03item-richtext-formatting.t b/t/03item-richtext-formatting.t
new file mode 100644
index 0000000..192ceec
--- /dev/null
+++ b/t/03item-richtext-formatting.t
@@ -0,0 +1,66 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More;
+
+plan skip_all => "Convert::Color::XTerm is not available"
+ unless eval { require Convert::Color::XTerm };
+
+use Tickit::Test;
+use Tickit::RenderBuffer;
+
+use String::Tagged;
+use Tickit::Widget::Scroller::Item::RichText;
+
+my $term = mk_term;
+
+my $rb = Tickit::RenderBuffer->new( lines => $term->lines, cols => $term->cols );
+
+# String::Tagged::Formatting conventions
+my $str = String::Tagged->new( "plain" )
+ ->append_tagged( "b", bold => 1 )
+ ->append_tagged( "u", under => 1 )
+ ->append_tagged( "i", italic => 1 )
+ ->append_tagged( "rv", reverse => 1 )
+ ->append_tagged( "af", monospace => 1 )
+ ->append_tagged( "fg", fg => Convert::Color::XTerm->new( "5" ) )
+ ->append_tagged( "bg", bg => Convert::Color::XTerm->new( "2" ) )
+;
+
+my $item = Tickit::Widget::Scroller::Item::RichText->new_from_formatting( $str );
+
+$item->height_for_width( 80 );
+
+$item->render( $rb, top => 0, firstline => 0, lastline => 0, width => 80, height => 25 );
+$rb->flush_to_term( $term );
+
+flush_tickit;
+
+is_termlog( [ GOTO(0,0),
+ SETPEN,
+ PRINT("plain"),
+ SETPEN(b => 1),
+ PRINT("b"),
+ SETPEN(u => 1),
+ PRINT("u"),
+ SETPEN(i => 1),
+ PRINT("i"),
+ SETPEN(rv => 1),
+ PRINT("rv"),
+ SETPEN(af => 1),
+ PRINT("af"),
+ SETPEN(fg => 5),
+ PRINT("fg"),
+ SETPEN(bg => 2),
+ PRINT("bg"),
+ SETBG(undef),
+ ERASECH(64) ],
+ 'Termlog for render from Formatting' );
+
+is_display( [ [TEXT("plain"), TEXT("b",b=>1), TEXT("u",u=>1), TEXT("i",i=>1), TEXT("rv",rv=>1),
+ TEXT("af",af=>1), TEXT("fg",fg=>5), TEXT("bg",bg=>2) ] ],
+ 'Display for render from Formatting' );
+
+done_testing;