TextBuffer.create constructor

TextBuffer.create(
  1. int length, {
  2. WidthMethod widthMethod = WidthMethod.unicode,
})

Creates a TextBuffer with at least length cells, using the given widthMethod.

Implementation

factory TextBuffer.create(
  int length, {
  WidthMethod widthMethod = WidthMethod.unicode,
}) {
  // Validate length - match Go's validation pattern
  if (length <= 0) {
    throw ArgumentError('Invalid length: must be greater than 0');
  }

  final bindings = OpenTuiBindings();
  final ptr = bindings.createTextBuffer(length, widthMethod.value);
  if (ptr == nullptr) {
    throw StateError('Failed to create TextBuffer');
  }
  return TextBuffer._(bindings, ptr);
}