NAME
TUI::Help::HelpTopic - help-topic paragraphs, wrapping, and cross-references
HIERARCHY
TObject
THelpTopic
SYNOPSIS
use TUI::Help;
my $topic = new_THelpTopic();
$topic->setWidth( 40 );
my $text = 'Introduction to the help system';
$topic->addParagraph(
TParagraph->new( text => $text, size => length( $text ), wrap => 1 ),
);
my $buffer = '';
my $line = $topic->getLine( 1, \$buffer, 80 );
DESCRIPTION
THelpTopic follows the Turbo Vision topic design. It holds a linked list of paragraphs and an array of cross-references. The TParagraph and TCrossRef records are defined in TUI::Help::HelpBase. TUI::Help does not export them, but they are available once it is loaded.
Paragraphs may use explicit line breaks or word wrapping at the configured width. Wrapping retains the whitespace at a word boundary and does not split long words merely to fit the width. Line breaks are recognized with Perl's \R and removed from returned text. Unlike the original fixed buffers, internal line processing has no 256-character limit.
Displayed lines are numbered from one. Cross-reference array indices are zero-based; their text offsets are one-based across concatenated paragraph text. Cross-reference locations use a zero-based column and a one-based displayed line.
The topic supports Storable persistence through TStreamable and TStream. Paragraph text, sizes, wrap flags, and cross-reference values are preserved. The display width and line-reading cache are not persisted; set the width again after restoring a topic.
Commonly Used Features
Set the width, append paragraphs, and use "numLines" and "getLine" to read the displayed text. Sequential line requests reuse a cached paragraph position; requests for earlier lines restart from the beginning. Finish constructing the topic and setting its width before reading lines, since changes do not reset this cache.
Add cross-references by value, then use "getCrossRef" to translate their text offsets into displayed locations. Scalar output parameters use scalar references.
ATTRIBUTES
The following attributes are read/write. Use the methods below to keep the paragraph chain and cross-reference count consistent.
- paragraphs
-
Objectwhen populated: the firstTParagraphin the linked list. Initially0, indicating an empty topic. - numRefs
-
Int. Number of cross-references, initially zero. - crossRefs
-
ArrayRef[Object]when populated, containingTCrossRefrecords. Initially undefined. New records allocated by "setNumCrossRefs" have undefined fields until filled by "setCrossRef".
CONSTRUCTOR
new
my $topic = THelpTopic->new();
Creates an empty topic with zero cross-references and an initial width of zero. Takes no arguments.
new_THelpTopic
my $topic = new_THelpTopic();
Factory for the same empty topic.
METHODS
addCrossRef
$topic->addCrossRef( $ref );
Appends a value copy of the TCrossRef object and increments the count. Later changes to the supplied record do not change the stored copy.
addParagraph
$topic->addParagraph( $p );
Appends the TParagraph object to the paragraph chain without copying it. Its next field is set to undef, making it the final paragraph. Supply text as Str, size as the text length, and wrap as Bool.
getCrossRef
$topic->getCrossRef( $i, $loc, \$length, \$ref );
Accepts $i as Int, a TPoint object, ScalarRef[PositiveOrZeroInt] for length, and ScalarRef[Int] for the target context. Initialize the referenced scalars before calling.
Updates the point's zero-based column and one-based line, and writes the stored length and target context to the scalar outputs. The index must be within the current cross-reference count; an assertion checks this precondition. The stored offset must not exceed the total length of the paragraph text; a larger offset is not checked and fails with a Perl error.
getLine
my $line = $topic->getLine( $lineNumber, \$buffer, $buflen );
Accepts a one-based Int line number, ScalarRef[Str] output buffer, and Int output length limit. Initialize the buffer to a string first. Returns the displayed line as Str and writes the same text to the buffer.
At most $buflen characters are returned; truncation does not change where the next displayed line starts. A missing line returns an empty string and clears the output buffer.
getNumCrossRefs
my $count = $topic->getNumCrossRefs();
Returns the current cross-reference count as Int.
numLines
my $count = $topic->numLines();
Counts displayed lines across all paragraphs using the current width and each paragraph's wrap flag. Returns Int; an empty topic returns zero.
setCrossRef
$topic->setCrossRef( $i, $ref );
Replaces the record at Int index $i with a value copy of the supplied TCrossRef. An index at or beyond the count is ignored. The index must be non-negative; an assertion checks this precondition.
setNumCrossRefs
$topic->setNumCrossRefs( $i );
Sets the cross-reference count to Int $i, preserving existing records up to the new count. Growing appends empty TCrossRef records; shrinking discards the trailing records. An unchanged count does nothing.
The count must be non-negative; an assertion checks this precondition. Fill newly allocated records before requesting their displayed locations.
setWidth
$topic->setWidth( $aWidth );
Sets the Int word-wrapping width. Does not reset the line-reading cache. Paragraphs with wrapping disabled are not limited to this width.
SEE ALSO
TUI::Help, TUI::Help::HelpBase, THelpFile, THelpIndex, TObject
AUTHORS
Borland International (original Turbo Vision design)
J. Schneider <brickpool@cpan.org> (Perl implementation and maintenance)
COPYRIGHT AND LICENSE
Copyright (c) 1990-1994, 1997 by Borland International
Copyright (c) 2026 the "AUTHORS" as listed above.
This software is licensed under the MIT license (see the LICENSE file, which is part of the distribution).