module Fancyline::StringUtil

Overview

String helpers

Extended Modules

Defined in:

fancyline/string_util.cr

Constant Summary

TAB_SIZE = 8

Maximum size of a tab on screen in characters

Instance Method Summary

Instance Method Detail

def 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_SIZE characters
  • Handles newlines
  • Newline is not counted as character

Returns a Dimension of 0 rows and 0 columns if str is nil.


[View source]
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.


[View source]