module Fancyline::StringUtil
Overview
String helpers
Extended Modules
Defined in:
fancyline/string_util.crConstant Summary
-
TAB_SIZE =
8
-
Maximum size of a tab on screen in characters
Instance Method Summary
-
#terminal_size(str : String | Nil) : Dimension
Returns the size of
str
on the terminal: * Does not count escape sequences * Counts tabs as up toTAB_SIZE
characters * Handles newlines * Newline is not counted as character -
#terminal_sub(str : String, offset, length) : String | Nil
Returns a sub-string of str of
[offset...(offset+length)]
, retaining surrounding coloring.
Instance Method Detail
Returns the size of str
on the terminal:
- Does not count escape sequences
- Counts tabs as up to
TAB_SIZE
characters - Handles newlines
- Newline is not counted as character
Returns a Dimension
of 0 rows and 0 columns if str is nil
.
def terminal_sub(str : String, offset, length) : String | Nil
#
Returns a sub-string of str of [offset...(offset+length)]
, retaining
surrounding coloring.
Usage is like String#[]
, except that escape sequences are skipped
in the character counting. Example:
StringUtil.terminal_sub("\e[1mfoobar\e[0m", 3, 3) # => "\e[1mbar\e[0m"
Note: This method is meant to be used with color-changing escape sequences only.