view ansi enccoded files as html
This commit is contained in:
19
test/package-lock.json
generated
Normal file
19
test/package-lock.json
generated
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"requires": true,
|
||||
"lockfileVersion": 1,
|
||||
"dependencies": {
|
||||
"ansi-to-html": {
|
||||
"version": "0.6.4",
|
||||
"resolved": "https://registry.npmjs.org/ansi-to-html/-/ansi-to-html-0.6.4.tgz",
|
||||
"integrity": "sha512-XuUGfj3zOAg3/NCU7Oyf9PaCyFuDVj8dzMqezMycPxo5U52atXt+R4L/zW7ETNA2GTjyj/KGBVEFI8sgPWUu2w==",
|
||||
"requires": {
|
||||
"entities": "1.1.1"
|
||||
}
|
||||
},
|
||||
"entities": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/entities/-/entities-1.1.1.tgz",
|
||||
"integrity": "sha1-blwtClYhtdra7O+AuQ7ftc13cvA="
|
||||
}
|
||||
}
|
||||
}
|
49
test/project.json
Normal file
49
test/project.json
Normal file
@ -0,0 +1,49 @@
|
||||
{
|
||||
"version": "1.0.5-*",
|
||||
"title": "Yavsc - les tests",
|
||||
"description": "Yavsc xUnit testing",
|
||||
"authors": [
|
||||
"Paul Schneider <paul@pschneider.fr>"
|
||||
],
|
||||
"packOptions": {
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/pazof/yavsc"
|
||||
},
|
||||
"licenseUrl": "https://github.com/pazof/yavsc/blob/vnext/LICENSE",
|
||||
"requireLicenseAcceptance": true,
|
||||
"owners": [
|
||||
"Paul Schneider <paul@pschneider.fr>"
|
||||
],
|
||||
"summary": "Yet another very small company",
|
||||
"projectUrl": "http://yavsc.pschneider.fr",
|
||||
"tags": [
|
||||
"Blog",
|
||||
"Blog",
|
||||
"PoS",
|
||||
"Chat"
|
||||
]
|
||||
},
|
||||
"tooling": {
|
||||
"defaultNamespace": "Yavsc"
|
||||
},
|
||||
"dependencies": {
|
||||
"Yavsc": {
|
||||
"target": "project"
|
||||
},
|
||||
"Newtonsoft.Json": "9.0.1",
|
||||
"xunit": "2.1.0",
|
||||
"xunit.analyzers": "0.9.0",
|
||||
"xunit.assert": "2.1.0",
|
||||
"xunit.runner.console": "2.1.0",
|
||||
"Microsoft.Dnx.TestHost": "1.0.0-rc1-final",
|
||||
"Microsoft.Dnx.Runtime": "1.0.0-rc1-final",
|
||||
"xunit.runner.dnx": "2.1.0-rc1-build204"
|
||||
},
|
||||
"frameworks": {
|
||||
"dnx451": {}
|
||||
},
|
||||
"commands": {
|
||||
"test": "xunit.runner.dnx"
|
||||
}
|
||||
}
|
59
test/src/YavscDnxUnitTests.cs
Executable file
59
test/src/YavscDnxUnitTests.cs
Executable file
@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using System.Diagnostics;
|
||||
using Yavsc.Helpers;
|
||||
|
||||
namespace tests
|
||||
{
|
||||
public class YavscDnxUnitTests
|
||||
{
|
||||
[Fact]
|
||||
void TestNodeJsForAnsitohtml ()
|
||||
{
|
||||
var procStart = new ProcessStartInfo("env", "/usr/bin/nodejs node_modules/ansi-to-html/bin/ansi-to-html");
|
||||
procStart.UseShellExecute = false;
|
||||
procStart.RedirectStandardInput = true;
|
||||
procStart.RedirectStandardOutput = true;
|
||||
procStart.RedirectStandardError = true;
|
||||
var proc = Process.Start(procStart);
|
||||
proc.StandardInput.WriteLine("\x001b[30mblack\x1b[37mwhite");
|
||||
proc.StandardInput.Close();
|
||||
while (!proc.StandardOutput.EndOfStream)
|
||||
{
|
||||
Console.Write(proc.StandardOutput.ReadToEnd());
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
void AnsiToHtml()
|
||||
{
|
||||
var procStart = new ProcessStartInfo("ls", "-l --color=always");
|
||||
procStart.UseShellExecute = false;
|
||||
procStart.RedirectStandardInput = false;
|
||||
procStart.RedirectStandardOutput = true;
|
||||
var proc = Process.Start(procStart);
|
||||
var encoded = GetStream(proc.StandardOutput);
|
||||
var reader = new StreamReader(encoded);
|
||||
var txt = reader.ReadToEnd();
|
||||
Console.WriteLine(txt);
|
||||
}
|
||||
|
||||
public static Stream GetStream(StreamReader reader)
|
||||
{
|
||||
var procStart = new ProcessStartInfo("/usr/bin/nodejs", "node_modules/ansi-to-html/bin/ansi-to-html");
|
||||
procStart.UseShellExecute = false;
|
||||
procStart.RedirectStandardInput = true;
|
||||
procStart.RedirectStandardOutput = true;
|
||||
procStart.RedirectStandardError = true;
|
||||
var mem = new MemoryStream();
|
||||
StreamWriter writer = new StreamWriter(mem);
|
||||
var proc = Process.Start(procStart);
|
||||
var text = reader.ReadToEnd();
|
||||
proc.StandardInput.WriteLine(text);
|
||||
proc.StandardInput.Close();
|
||||
return proc.StandardOutput.BaseStream;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user