-
Notifications
You must be signed in to change notification settings - Fork 374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NullReferenceException when redirecting output from ScreenView #883
Comments
Right, this was just a conceptual misunderstanding on my behalf. I didn't actually need a new ContentView("Hello World!").Render(consoleRenderer, Region.EntireTerminal); The |
@flakey-bit did you ever get it to render properly? I am glad that my code is no longer throwing NullReferenceExceptions, but the output of a TableView is broken in every terminal: namespace FileInfoRender;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.CommandLine.Rendering;
using System.CommandLine.Rendering.Views;
using System.IO;
using System.Linq;
class Program
{
static void Main(string[] args)
{
var rootCommand = new RootCommand();
rootCommand.Handler = CommandHandler.Create<InvocationContext>(Print);
rootCommand.Invoke(args);
}
static void Print(InvocationContext context)
{
var consoleRenderer = new ConsoleRenderer(
context.Console,
context.BindingContext.OutputMode(),
true);
var tableView = new TableView<FileInfo>
{
Items = new DirectoryInfo(".").EnumerateFiles().ToList()
};
tableView.AddColumn(f => f.Name, "Name");
tableView.AddColumn(f => f.LastWriteTime, "Modified");
tableView.AddColumn(f => f.Length, "Size");
tableView.Render(consoleRenderer, Region.EntireTerminal);
}
} With DragonFruit and ScreenView everything works, but I would like to not use DragonFruit: static void Main(InvocationContext context, DirectoryInfo argument= null)
{
argument ??= new DirectoryInfo(".");
var consoleRenderer = new ConsoleRenderer(
context.Console,
context.BindingContext.OutputMode(),
true);
var tableView = new TableView<FileInfo>
{
Items = argument.EnumerateFiles().ToList()
};
tableView.AddColumn(f => f.Name, "Name");
tableView.AddColumn(f => f.LastWriteTime, "Modified");
tableView.AddColumn(f => f.Length, "Size");
var screen = new ScreenView(consoleRenderer, context.Console) { Child = tableView };
screen.Render();
} |
Given the following program:
Running as
.\bin\Debug\net471\Program.exe
gives the output
However attempting to redirect output to a file with
.\bin\Debug\net471\Program.exe > c:\temp\output.txt
throws a NullReferenceException:
The text was updated successfully, but these errors were encountered: