mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-20 13:48:16 +08:00
Added initial support for rendering composites
This is far from complete, but it's a start and it will enable us to create things like tables and other complex objects in the long run.
This commit is contained in:

committed by
Patrik Svensson

parent
e596e6eb4f
commit
8e4f33bba4
50
src/Spectre.Console/Internal/Text/StringBuffer.cs
Normal file
50
src/Spectre.Console/Internal/Text/StringBuffer.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Spectre.Console.Internal
|
||||
{
|
||||
internal sealed class StringBuffer : IDisposable
|
||||
{
|
||||
private readonly StringReader _reader;
|
||||
private readonly int _length;
|
||||
|
||||
public int Position { get; private set; }
|
||||
public bool Eof => Position >= _length;
|
||||
|
||||
public StringBuffer(string text)
|
||||
{
|
||||
text ??= string.Empty;
|
||||
|
||||
_reader = new StringReader(text);
|
||||
_length = text.Length;
|
||||
|
||||
Position = 0;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_reader.Dispose();
|
||||
}
|
||||
|
||||
public char Peek()
|
||||
{
|
||||
if (Eof)
|
||||
{
|
||||
throw new InvalidOperationException("Tried to peek past the end of the text.");
|
||||
}
|
||||
|
||||
return (char)_reader.Peek();
|
||||
}
|
||||
|
||||
public char Read()
|
||||
{
|
||||
if (Eof)
|
||||
{
|
||||
throw new InvalidOperationException("Tried to read past the end of the text.");
|
||||
}
|
||||
|
||||
Position++;
|
||||
return (char)_reader.Read();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user