NAME

TUI::Gadgets::FileViewer - file viewer gadget for text files

HIERARCHY

TObject
  TView
    TScroller
      TFileViewer

SYNOPSIS

use TUI::Objects::Rect;
use TUI::Gadgets::FileViewer;
use TUI::Views::Const qw( :sbXXXX );

my $r = $self->getExtent();
$r->grow( -1, -1 );
$self->insert(
  TFileViewer->new(
    bounds     => $r,
    hScrollBar => $self->standardScrollBar( sbHorizontal | sbHandleKeyboard ),
    vScrollBar => $self->standardScrollBar( sbVertical | sbHandleKeyboard ),
    fileName   => $fileName,
  )
);

DESCRIPTION

TFileViewer displays the contents of a text file inside a scrollable view.

The viewer reads the specified file into an internal line collection and renders the visible portion of the file. Horizontal and vertical scrolling are provided through the inherited scrolling support from TScroller.

ATTRIBUTES

fileLines

Collection containing the currently loaded file contents (TLineCollection).

fileName

Name of the currently loaded file (Str).

isValid

Indicates whether the file was loaded successfully (Bool).

CONSTRUCTOR

new

my $viewer = TFileViewer->new(
  bounds     => $bounds,
  hScrollBar => $hScrollBar,
  vScrollBar => $vScrollBar,
  fileName   => $fileName,
);

Creates a new file viewer and loads the specified file.

bounds

Bounding rectangle defining the position and size of the view (TRect).

hScrollBar

Optional horizontal scroll bar (TScrollBar).

vScrollBar

Optional vertical scroll bar (TScrollBar).

fileName

Name of the file to load (Str).

new_TFileViewer

my $viewer = new_TFileViewer(
  $bounds,
  $hScrollBar | undef,
  $vScrollBar | undef,
  $fileName
);

Factory-style constructor using positional arguments.

METHODS

draw

$viewer->draw();

Draws the currently visible portion of the file.

readFile

$viewer->readFile($fileName);

Loads a text file into the viewer and updates the scrolling limits.

scrollDraw

$viewer->scrollDraw();

Refreshes the display after a scrolling operation.

setState

$viewer->setState($state, $enable);

Updates the viewer state. When the view becomes exposed, the scrolling limits are synchronized with the loaded file.

valid

my $bool = $viewer->valid($command);

Returns true if the viewer contains valid file data.

SEE ALSO

TScroller, TLineCollection, TFileWindow

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).