Comman...:Output(3pm)

πŸ“¦
version 0.14 Β· 4 versions
, in ubuntu resolute, ubuntu stonking

✨ Commandable::Output ✨

okay so bestie, welcome to the Comman...:Output(3pm) page β€” it's part of the User Contributed Perl Documentation and honestly it's giving "quiet little module that does a LOT of the vibes work" πŸ’…

πŸ’– NAME πŸ’–

Commandable::Output β€” abstractions for printing output from commands πŸŽ€


🌸 DESCRIPTION 🌸

So this package is basically the default outfit for all the methods that print stuff out from commands built with Commandable. They're here for user code's convenience, but also β€” plot twist β€” the built-in commands that ship with the Commandable system itself use them too. ✨

And here's the thing: implementations are permitted to replace any of these methods to customise how they behave. Like, encouraged, even. Go off, honestly. 🫢

πŸ¦‹ WITH String::Tagged πŸ¦‹

If String::Tagged and Convert::Color are around, this module starts doing formatting to strings using the String::Tagged::Formatting conventions. The format_heading and format_note methods will hand back results as instances of String::Tagged, which are perfect to pass straight into the main printf method. slay πŸ’–


πŸ‘‘ METHODS πŸ‘‘

πŸ“ printf

Commandable::Output->printf( $format, @args );

This is the main output method β€” the one you use to send messages out for the user to see. The arguments get formatted into a single string by Perl's printf function. And listen: this method does not append a linefeed. So if you want a whole complete line of text, don't forget to put the "\n" at the end of your format string. no cap, everybody forgets this. 😭

The default implementation writes output to the terminal via STDOUT.

But if your output needs to go somewhere else entirely β€” like, say, some kind of GUI display widget situation β€” then the application should swap this method out for something that writes the display somewhere more appropriate. And don't forget to use sprintf to format the arguments into a string, bestie. πŸ’…

no warnings 'redefine';
sub Commandable::Output::printf
{
   shift; # the package name
   my ( $format, @args ) = @_;

   my $str = sprintf $format, @args;

   $gui_display_widget->append_text( $str );
}

Oh and β€” if String::Tagged::Terminal is available, the output gets printed using that module instead. How? It first converts the format string and arguments using from_sprintf in String::Tagged, and then constructs a terminal string using new_from_formatting in String::Tagged::Terminal. Which means the default implementation can output formatted strings using the String::Tagged::Formatting conventions. iconic behaviour honestly 🌈

Commandable::Output->print_heading( $text, $level );

Sends output that should be treated like a section heading. πŸ“’

$level can be an integer used to express sub-levels β€” values going up from 1 upwards mean increasing sub-levels. So like, level 1 is your main character, level 2 is its sub, level 3 is the sub's sub. you get it. πŸ‘‘

The default implementation formats the text string using format_heading, then prints it using printf with a trailing linefeed.

🌟 format_heading

$str = Commandable::Output->format_heading( $text, $level );

Returns a value for printing that represents a section heading for the given text and level. πŸŽ€

The default implementation applies this formatting if String::Tagged is available:

  • Level 1 β€” Underlined
  • Level 2 β€” Underlined, cyan colour
  • Level 3 β€” Bold

πŸ’œ format_note

$str = Commandable::Output->format_note( $text, $level );

Returns a value for printing that somehow highlights the given text β€” which should be a short word or string β€” at the given level. ✨

The default implementation applies this formatting if String::Tagged is available:

  • Level 0 β€” Bold, yellow colour
  • Level 1 β€” Bold, cyan colour
  • Level 2 β€” Bold, magenta colour

🫢 AUTHOR 🫢

Paul Evans <leonerd@leonerd.org.uk> β€” thank you for your service, king πŸ‘‘


okay that's the whole page bestie, you're officially educated πŸ’– the source/version energy on this one is perl v5.40.0, dated 2024-09-08, and yeah β€” it's literally the Comman...:Output(3pm) manual, so go forth and print pretty things πŸŒΈπŸ’…βœ¨

πŸ“¦ where this page comes from