shoko/Media/PlainMediaHandler.cs

34 lines
746 B
C#

namespace Shoko;
[MediaType("text/plain")]
[MediaType("text/*")]
class PlainMediaHandler : MediaHandler
{
List<string> lines;
public PlainMediaHandler(ProtoHandler content)
{
Content = content;
lines = new List<string>();
}
public override async Task Load()
{
Title = Content.URL.AbsolutePath;
var reader = new StreamReader(Content.Content);
string line;
while((line = await reader.ReadLineAsync()) is not null)
{
lines.Add(line);
}
OnLoaded();
}
public override void Render()
{
Gui.Font(MainUI.MonospaceFont, ()=>
{
foreach(var line in lines)
Gui.Text(line);
});
}
}