GithubHelp home page GithubHelp logo

term-hr's Introduction

NAME

Term::hr - define a thematic change in the content of a terminal session

SYNOPSIS

    use Term::hr {
      char      => '=',   # character to use
      fg        => 'fg',  # foreground color, fg = default fg color
      bg        => 'bg',  # background color, bg = default bg color
      bold      => 0,     # no bold attribute
      crlf      => 1,     # add a newline to the returned hr
      italic    => 0,     # no italic attribute
      post      => 0,     # post whitespace
      pre       => 0,     # pre whitespace
      reverse   => 0,     # reverse video attribute
      underline => 0,     # underline attribute
      width     => 80,    # total width of the hr
    };

    ...
    print hr();
    ...

DESCRIPTION

screenshot

Term::hr exports a single function into the callers namespace, hr. It exposes a feature very similar to the HTML <hr> tag; a simple way to define a thematic change in content.

It gives you a way to divide output into sections when you or your program produces a lot of output.

Normally one might want to define the looks of the hr a single time, in the beginning of a program. That way, every invocation will be styled the same.

You can do that in the same statement as the use statement, as seen above.

There are however many reasons why you might want to setup a bunch of options as your defaults, and later in your program modify them a bit to suit your needs.

Many different possibilities and combinations is allowed, see below.

EXAMPLES

    use Term::hr;
    use Term::Size;

    my $hr = hr(
      {
        char   => '#',
        fg     => 197,
        bg     => 'bg',
        bold   => 1,
        italic => 1,
        width  => ((Term::Size::chars())[0] / 4),
        pre    => 1,
        post   => 1,
        crlf   => 1,
      },
    );

    print $hr;

Because the hr above was crafted with provided options at invocation time, they are temporary. This means that the hr below will have all module default options, except for the character.

    my $another_hr = hr('_');
    print $another_hr;

If you wanted to change the character, but keep all the other options you crafted, set the options at use-time instead:

    use Term::hr {
      fg        => 196,  # foreground color, fg = default fg color
      bg        => 220,  # background color, bg = default bg color
    };

    # uses '=' as character
    print hr();

    # use another one
    my $hr = hr('_');

Combinations are possible, as well as unicode:

    use Term::hr {
      fg     => 197,
      bold   => 1,
      italic => 1,
      crlf   => 1,
    };

    print hr();
    print hr({char => '๐„˜', italic => 0});
    print hr('๐„˜');
    print hr({char => '๐„˜', italic => 0, underline => 1,});
    print hr({char => '๐„˜', reverse => 1, underline => 1,});
    $ ls; perl -MTerm::hr -E 'say hr({char=>"๐ŸŒŽ",width=>15})'; date

Create a shell alias:

    $ alias hr"=perl -MTerm::hr -E 'say hr({fg=>196, char=> q[ ], bold=>1,underline=>1,italic=>1})'"
    $ cat /var/log/Xorg.0.log; hr; ls

Options and attributes

These are options that can be passed to hr as a key-value hash.

char

The character to use to build up the hr. Defaults to '='.

width, size

The total width of the hr, including pre and post. Defaults to 80.

fg

Foreground color. Defaults to your default terminal foreground color.

bg

Background color. Defaults to your default terminal background color.

crlf

If provided with a non-zero value, a newline will be added to the end of the hr. Defaults to no newline added.

pre

Amount of whitespace to add before the hr string. Defaults to zero.

post

Amount of whitespace to add after the hr string. Defaults to zero.

bold

If provided with a non-zero value, bold attribute will be added. Defaults to zero.

italic

If provided with a non-zero value, italic attribute will be added. Defaults to zero.

underline

If provided with a non-zero value, underline attribute will be added. Defaults to zero.

reverse

If provided with a non-zero value, reverse video attribute will be added. Defaults to zero.

AUTHOR

Magnus Woldrich
CPAN ID: WOLDRICH
[email protected]
http://japh.se
http://github.com/trapd00r

COPYRIGHT

Copyright 2022 THIS APPLICATIONs "AUTHOR" and "CONTRIBUTORS" as listed above.

LICENSE

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

term-hr's People

Contributors

trapd00r avatar

Stargazers

Thibault Duponchelle avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.