class Reline::Unicode

def self.take_range(str, start_col, max_width)

Experimental RBS support (using type sampling data from the type_fusion project).

def self.take_range: (String str, Integer start_col, Integer max_width) -> String

This signature was generated using 1 sample from 1 application.

Take a chunk of a String cut by width with escape sequences.
def self.take_range(str, start_col, max_width)
  chunk = String.new(encoding: str.encoding)
  total_width = 0
  rest = str.encode(Encoding::UTF_8)
  in_zero_width = false
  rest.scan(WIDTH_SCANNER) do |non_printing_start, non_printing_end, csi, osc, gc|
    case
    when non_printing_start
      in_zero_width = true
    when non_printing_end
      in_zero_width = false
    when csi
      chunk << csi
    when osc
      chunk << osc
    when gc
      if in_zero_width
        chunk << gc
      else
        mbchar_width = get_mbchar_width(gc)
        total_width += mbchar_width
        break if (start_col + max_width) < total_width
        chunk << gc if start_col < total_width
      end
    end
  end
  chunk
end