Module mfr

lua formatter

Functions

cut_string (str, length) cut string into slices of certain length.
deepcopy (orig) recursively copy table.
belongs (element, sequence) check if element belongs to array.
space_split (str) split string by whitespaces.
split (str, separator) split string by `separator` and return array.

system

execute_system_command (command) execute system shell command.
is_supporting_colors () check if terminal supports colors.

color setters

set_bg (message, color, is_closed, is_forced) apply background color to string.
set_fg (message, color, is_forced) apply foreground color to string.
set_special_style (message, style, is_forced) apply special style to string.

prettifyers

clear_screen () clear terminal screen.
prettify_table (ugly_table) make a good-looking string out of a table.
pprint (object) make a good-looking string out of anything.
create_frame (message, width, pattern) create frame with message in terminal.
create_line_borders (text, length, border) create line borders.
create_page_borders (message, width, pattern) create page borders.

showing

describe_fg_colors (is_forced) send available foreground colors to stdout.
describe_bg_colors (is_forced) send available background colors to stdout.
describe_special_styles (is_forced) send available special styles to stdout.

settings

set_max_recursion (value) set maximal recursion level.
get_max_recursion () get maximal recursion level.
set_tab_representation (value) set tab representation.
get_tab_representation () get tab representation.


Functions

cut_string (str, length)
cut string into slices of certain length.

Parameters:

  • str string string to be sliced
  • length number slices' length

Returns:

    table list of slices

Raises:

if str is not a string if length is not a number
deepcopy (orig)
recursively copy table. note that this is a recursive function. always check the data you process for safety! if `orig` is a table and is more nested than mfr._MAX_RECURSION, then `orig` will be copied up to mfr._MAX_RECURSION nested level without warning.

Parameters:

  • orig any original value. if it is not a table-like object, it is just returned

Returns:

    any copy of orig (same type, as `orig` parameter)
belongs (element, sequence)
check if element belongs to array.

Parameters:

  • element element to search for
  • sequence table array to search in

Returns:

    boolean true if element exists in sequence, otherwise false

Raises:

if sequence is not a table
space_split (str)
split string by whitespaces. note that this function works faster than `mfr.split` with separator=" ".

Parameters:

  • str string string to be splitted

Returns:

    table array of strings
split (str, separator)
split string by `separator` and return array.

Parameters:

  • str string text to be splitted by `separator`
  • separator string string to split `str` with

Returns:

    table array of splitted strings.

Raises:

if str is not a string or separator is not a string and not nil.

system

execute_system_command (command)
execute system shell command.

Parameters:

  • command string command to be sent for execution

Returns:

    any shell answer. nil if command returned non-zero exit code (failed)

Raises:

if command is not a string
is_supporting_colors ()
check if terminal supports colors.

Returns:

  1. number number of supported colors
  2. boolean false if colors aren't supported

color setters

set_bg (message, color, is_closed, is_forced)
apply background color to string.

Parameters:

  • message string string apply background color to (or table, if passing all arguments as 1 table). see usage for more
  • color string background color to be applied to message
  • is_closed boolean whether style will be disabled with end of message
  • is_forced boolean whether style will be applied evem if colors are not supported

Returns:

    string colorful message

Raises:

if colors are not supported and is_forced is not true

See also:

Usage:

    mfr.apply_bg_color("hello", "red")
    mfr.apply_bg_color{message = "message", color = "red", is_closed = true,
    is_forced = false}
set_fg (message, color, is_forced)
apply foreground color to string.

Parameters:

  • message string string apply color to
  • color string color to be applied to message
  • is_forced boolean whether style will be applied even if colors are not supported

Returns:

    string colorful message

Raises:

if colors are not supported and is_forced is not true

See also:

set_special_style (message, style, is_forced)
apply special style to string.

Parameters:

  • message string string apply style to
  • style string style to be applied to message
  • is_forced boolean whether style will be applied even if colors are not supported

Returns:

    string styled message

Raises:

if colors are not supported and is_forced is not true

See also:

prettifyers

clear_screen ()
clear terminal screen. please, use with caution.
prettify_table (ugly_table)
make a good-looking string out of a table.

Parameters:

Returns:

    string pretty table ready to be sent to stdout

Raises:

error if ugly_table is not a table.

Usage:

    useless_list = {1, 2, a = {"text", "text"}}
    pretty_table = mfr.prettify_table(useless_list))
    io.write(pretty_table)
pprint (object)
make a good-looking string out of anything.

Parameters:

  • object anything to be pretty-printed

Usage:

    perfect_table = {1, 2, a = {"text1", "text2"}}
    mfr.pprint(perfect_table)
create_frame (message, width, pattern)
create frame with message in terminal. note that all tabs will be converted to character sequence defined by `set_tab_representation` - 4 spaces is a default value. please, note that pattern param is cut, and only its 1st symbol is used.

Parameters:

  • message string text to be displayed
  • width number width of the frame
  • pattern string pattern to be used to create frame

Returns:

    string framed message

Raises:

if message is not a string, or width is not a number, or pattern is not a string

See also:

create_line_borders (text, length, border)
create line borders. note that all tabs will be converted to character sequence defined by `set_tab_representation` - 4 spaces is a default value. please, note that border param is cut, and only its 1st symbol is used.

Parameters:

  • text string text to be displayed put inside borders
  • length number length of the frame
  • border string border to put text into

Returns:

    string bordered text

Raises:

if text is not a string, or length is not a number, or border is not a string

See also:

create_page_borders (message, width, pattern)
create page borders. note that all tabs will be converted to character sequence defined by `set_tab_representation` - 4 spaces is a default value. please, note that pattern param is cut, and only its 1st symbol is used.

Parameters:

  • message string message to be displayed put inside borders
  • width number width of the page
  • pattern string border pattern to put message into

Returns:

    string bordered page of text

Raises:

if message is not a string

See also:

showing

describe_fg_colors (is_forced)
send available foreground colors to stdout.

Parameters:

  • is_forced boolean if true, output is provided even if terminal does not support colors.

Raises:

if colors are not supported and is_forced is not true
describe_bg_colors (is_forced)
send available background colors to stdout.

Parameters:

  • is_forced boolean if true, output is provided even if terminal does not support colors.

Raises:

if colors are not supported and is_forced is not true
describe_special_styles (is_forced)
send available special styles to stdout.

Parameters:

  • is_forced boolean if true, output is provided even if terminal does not support colors.

Raises:

if colors are not supported and is_forced is not true

settings

set_max_recursion (value)
set maximal recursion level. for instance, recursion level 7 means that recursive function cannot call itself more than 7 times.

Parameters:

  • value number new recursion level

Raises:

error if value param is not a signed number.

See also:

get_max_recursion ()
get maximal recursion level.

Returns:

    number maximal recursion level

See also:

set_tab_representation (value)
set tab representation. for instance, tab representation " " (default value) means that tab symbol will be substituted for 4 spaces in functions that need tab to have stable length.

Parameters:

  • value string new tab representation

Raises:

error if value param is not a string.

See also:

get_tab_representation ()
get tab representation.

Returns:

    string current tab representation

See also:

generated by LDoc 1.5.0 Last updated 2023-07-18 17:46:51