Fancyline::StringUtil
String helpers
Constants
TAB_SIZE = 8
Maximum size of a tab on screen in characters
Instance methods
terminal_size(str : String | Nil) : Dimension
Returns the size of str on the terminal:
- Does not count escape sequences
- Counts tabs as up to
TAB_SIZEcharacters - Handles newlines
- Newline is not counted as character
Returns a Dimension of 0 rows and 0 columns if str is nil.
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.