Skip to content

Commit

Permalink
Added some better Text-creation methods
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Mar 1, 2024
1 parent e023442 commit f043ebf
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/core/textbuffer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,20 @@ def append[TextType, ValueType](using buffer: Buffer[TextType])(using textual: T
buffer.append(textual.show(value))

extension (textObject: Text.type)
def create(length: Int)(lambda: Array[Char] => Unit): Text =
new String(new Array[Char](length).tap(lambda(_))).tt

def make(block: (buffer: TextBuffer) ?=> Unit): Text =
val buffer = TextBuffer()
block(using buffer)
buffer()

def fill(length: Int)(lambda: Int => Char): Text =
val array = new Array[Char](length)
(0 until length).each { index => array(index) = lambda(index) }

String(array).tt

abstract class Buffer[TextType]():
protected def put(text: TextType): Unit
protected def wipe(): Unit
Expand Down

0 comments on commit f043ebf

Please sign in to comment.