Browse Source

Create PyIOStream.cs

pull/5/head
Ionite 2 years ago
parent
commit
84f63d9994
No known key found for this signature in database
  1. 47
      StabilityMatrix/PyIOStream.cs

47
StabilityMatrix/PyIOStream.cs

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
namespace StabilityMatrix;
/// <summary>
/// Implement the interface of the sys.stdout redirection
/// </summary>
[SuppressMessage("ReSharper", "InconsistentNaming")]
internal class PyIOStream
{
public event EventHandler<string> OnWriteUpdate;
public TextWriter TextWriter { get; set; }
public PyIOStream(TextWriter writer = null)
{
TextWriter = writer ?? new StringWriter();
}
public void write(string str)
{
TextWriter.Write(str);
OnWriteUpdate?.Invoke(this, str);
}
public void writelines(string[] str)
{
foreach (var line in str)
{
write(line);
}
}
public void flush()
{
TextWriter.Flush();
}
public void close()
{
TextWriter?.Close();
}
}
Loading…
Cancel
Save