Class Typewriter
Reveals text one character at a time. Optional fake cursor between characters and optional Alpha fade-in (brightness ramp on the final glyph). The trailing cursor, if any, is always erased before Type(string, int, Color?, TypewriterCursor, TypewriterFade, (Color from, Color to)?) returns.
Assumes one terminal cell per char: surrogate pairs (emoji), combining marks, and wide CJK glyphs break the cursor-overwrite tracking used by cursor mode and alpha fade. Stick to BMP single-cell characters for animated reveals.
public static class Typewriter
- Inheritance
-
Typewriter
- Inherited Members
Methods
Blink(int, TypewriterCursor, Color?, int)
Sit at the current cursor position and blink a fake cursor for
totalMs milliseconds — useful for the Matrix-
style "pause before the next phrase" beats. The glyph is erased
before this method returns, so the next write starts on a clean
cell. Without ANSI support the call is a plain
Sleep(int).
public static void Blink(int totalMs, TypewriterCursor cursor = TypewriterCursor.MatrixBlock, Color? fg = null, int blinkRateMs = 500)
Parameters
totalMsintHow long to blink, in total. Values ≤0 return immediately.
cursorTypewriterCursorGlyph to blink. None just sleeps.
fgColor?Optional color for the cursor.
blinkRateMsintHalf-period of the blink — time the cursor stays in each on/off state.
BlinkAsync(int, TypewriterCursor, Color?, int, CancellationToken)
Async variant of Blink(int, TypewriterCursor, Color?, int) with cancellation support.
public static Task BlinkAsync(int totalMs, TypewriterCursor cursor = TypewriterCursor.MatrixBlock, Color? fg = null, int blinkRateMs = 500, CancellationToken cancellationToken = default)
Parameters
totalMsintcursorTypewriterCursorfgColor?blinkRateMsintcancellationTokenCancellationToken
Returns
Type(string, int, Color?, TypewriterCursor, TypewriterFade, (Color from, Color to)?)
Reveal text character-by-character. Blocks the
calling thread between characters via Sleep(int).
public static void Type(string text, int msPerChar = 30, Color? fg = null, TypewriterCursor cursor = TypewriterCursor.None, TypewriterFade fade = TypewriterFade.None, (Color from, Color to)? gradient = null)
Parameters
textstringText to reveal.
msPerCharintTime budget per character. Zero writes the whole string instantly.
fgColor?Static foreground color. Ignored when
gradientis set.cursorTypewriterCursorCursor glyph shown while waiting for the next char.
fadeTypewriterFadeHow each character appears.
gradient(Color from, Color to)?If set, color is interpolated across the string. Both endpoints must be truecolor.
TypeAsync(string, int, Color?, TypewriterCursor, TypewriterFade, (Color from, Color to)?, CancellationToken)
Async variant of Type(string, int, Color?, TypewriterCursor, TypewriterFade, (Color from, Color to)?). Pauses with
Delay(int, CancellationToken), so cancellation
aborts the reveal immediately and the finally block restores
the cursor and color before propagating
OperationCanceledException.
public static Task TypeAsync(string text, int msPerChar = 30, Color? fg = null, TypewriterCursor cursor = TypewriterCursor.None, TypewriterFade fade = TypewriterFade.None, (Color from, Color to)? gradient = null, CancellationToken cancellationToken = default)
Parameters
textstringmsPerCharintfgColor?cursorTypewriterCursorfadeTypewriterFadegradient(Color from, Color to)?cancellationTokenCancellationToken
Returns
TypeLine(string, int, Color?, TypewriterCursor, TypewriterFade, (Color from, Color to)?)
Type(string, int, Color?, TypewriterCursor, TypewriterFade, (Color from, Color to)?) followed by a newline.
public static void TypeLine(string text, int msPerChar = 30, Color? fg = null, TypewriterCursor cursor = TypewriterCursor.None, TypewriterFade fade = TypewriterFade.None, (Color from, Color to)? gradient = null)
Parameters
textstringmsPerCharintfgColor?cursorTypewriterCursorfadeTypewriterFadegradient(Color from, Color to)?
TypeLineAsync(string, int, Color?, TypewriterCursor, TypewriterFade, (Color from, Color to)?, CancellationToken)
TypeAsync(string, int, Color?, TypewriterCursor, TypewriterFade, (Color from, Color to)?, CancellationToken) followed by a newline.
public static Task TypeLineAsync(string text, int msPerChar = 30, Color? fg = null, TypewriterCursor cursor = TypewriterCursor.None, TypewriterFade fade = TypewriterFade.None, (Color from, Color to)? gradient = null, CancellationToken cancellationToken = default)
Parameters
textstringmsPerCharintfgColor?cursorTypewriterCursorfadeTypewriterFadegradient(Color from, Color to)?cancellationTokenCancellationToken