Rand Stats

Prompt::Expand

zef:lizmat

Actions Status Actions Status Actions Status

NAME

Prompt::Expand - provide prompt expansion logic

SYNOPSIS

use Prompt::Expand;

say expand(":time: >");        # 19:24:11 >

say expand(":date: >", "NL");  # zon 19 jan 2025 >

DESCRIPTION

The Prompt::Expand distribution provides the logic to expand a string (usually intended to be used as a prompt for user input) according to number of escape sequences (the format). As such it exports an expand subroutine that takes such a format, and returns the expanded string.

Expansion currently provided are:

Expansions involving date / time values, can be localized by specifying the language to be used, either as a string (e.g. "NL") or as a custom Locale::Dates object.

EXPANSIONS

ANSI color codes

Note that not all of these are supported everywhere!

:text:function
normalreset to default
boldswitch on bold characters
dimswitch on dimmer characters
italicswitch on italic characters
underlineswitch on underlined characters
blinkswitch on blinking characters
inverseswitch on inverted characters
hiddenswitch on showing spaces instead of characters
strikethroughswitch on strikethrough characters
unboldswitch off bold characters
unitalicswitch off italic characters
ununderlineswitch off underlined characters
uninverseswitch off inverse characters
blackswitch to black foreground
redswitch to red foreground
greenswitch to green foreground
yellowswitch to yellow foreground
blueswitch to blue foreground
magentaswitch to magenta foreground
cyanswitch to cyan foreground
whiteswitch to white foreground
defaultswitch to default foreground
BLACKswitch to black background
REDswitch to red background
GREENswitch to green background
YELLOWswitch to yellow background
BLUEswitch to blue background
MAGENTAswitch to magenta background
CYANswitch to cyan background
WHITEswitch to white background
DEFAULTswitch to default background

Raku escape sequences

Besides most of the standard Raku escape sequences with an associated :text: equivalent, also some other more interactive prompt related :text sequences:

:text:escapefunction
bell\aaudible / visible alert
bksp\bbackspace
escape\einitiate ANSI escape sequence
formfeed\fform feed (FF)
reset\creset to all ANSI defaults
lf\nline feed (LF, newline, $?NL)
cr\rCarriage Return (CR)
tab\ttab
bslash\\backslash
index$*INDEX value
symbol$*SYMBOL value
languagelanguage version
releasecompiler release
compilercompiler version

If the DateTime::strftime is installed:

Code:text:Value
%awkdnameabbreviated weekday name
%Aweekdaynamefull weekday name
%bmnthnameabbreviated month name
%Bmonthnamefull month name
%cdatetimepreferred date/time representation
%Ccenturycentury number (year div 100)
%d0dayday of month ("01" .. "31")
%Dusadateshort for: %m/%d/%y
%edayday of month (" 1" .. "31")
%fsame as %M
%Fisodateshort for: %Y/%m/%d
%gweekYYYY of this week ("00" .. "99")
%GweekYYYYfull year of this week
%hsame as %b
%H0hour24-hour hour ("00" .. "23")
%I0amhour12-hour hour ("01" .. "12")
%jyeardayday of the year ("001" .. "366")
%khour24-hour hour (" 1" .. "23")
%lamhour12-hour hour (" 1" .. "12")
%Lsame as %Y
%mmonthmonth ("01" .. "12")
%Mminuteminute ("00" .. "59")
%nnewline"\n"
%pAMPM"AM" | "PM"
%Pampm"am" | "pm"
%ramtimeshort for: %I:%M:%S %p
%RHHMMshort for: %H:%M
%sepochseconds since epoch (midnight 1970-01-01 UTC)
%Ssecondsecond ("00" .. "59")
%ttab"\t"
%THHMMSSshort for: %H:%M:%S
%uweekdayweekday (1 .. 7)
%UweekSunweek number (first Sunday) ("00" .. "53")
%vDD-MON-YYYYshort for: %e-%b-%Y
%VweekISOweek number (ISO 8601) ("00" .. "53")
%w0weekdayweekday (0 .. 6)
%WweekMonweek number (first Monday) ("00" .. "53")
%xdatepreferred date representation
%Xtimepreferred time representation
%yYYyear without century ("00" .. "99")
%Yyearyear (yyyy)
%ztzoffsetnumeric timezone (±HHMM)
%Ztimezonetimezone (no name: %z)
%+unixdateshort for: %a %b %e %T %Z %G
%%percent"%"

If the Text::Emoji, all of the 1870 conversions are supported.

AUTHOR

Elizabeth Mattijsen liz@raku.rocks

Source can be located at: https://github.com/lizmat/Prompt-Expand . Comments and Pull Requests are welcome.

If you like this module, or what I'm doing more generally, committing to a small sponsorship would mean a great deal to me!

COPYRIGHT AND LICENSE

Copyright 2025 Elizabeth Mattijsen

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.