spectre.console icon indicating copy to clipboard operation
spectre.console copied to clipboard

feat/write list irenderable

Open jos3s opened this issue 1 year ago • 5 comments
trafficstars

  • new overload of the write method receiving IEnumerable<IRenderable> or IRenderable[] params
  • implementing a new overload in the classes that implement IAnsiConsole
  • implementing a new overload in the TestConsole
  • new unit tests for Write, TextPath, BarChart and Table

fixes #1437

  • [x] I have read the Contribution Guidelines
  • [x] I have commented on the issue above and discussed the intended changes
  • [ ] A maintainer has signed off on the changes and the issue was assigned to me
  • [x] All newly added code is adequately covered by tests
  • [x] All existing tests are still running without errors
  • [ ] The documentation was modified to reflect the changes OR no documentation changes are required.

Changes

I created an overload in the Write method of the IAnsiConsole interface and implemented it in all the classes that implement this interface. The purpose of this overload is to receive a list of IRenderable objects and render them together without having to call AnsiConsole.Write for each IRenderable object.

jos3s avatar Jan 30 '24 03:01 jos3s

Wouldn't adding an extension method for IAnsiConsole that accomplishes the same thing suffice?

public static void Write(this IAnsiConsole console, params IRenderable[] renderables)
{
    foreach(var renderable in renderables) 
    {
        console.Write(renderable);
    }
}

patriksvensson avatar Jan 31 '24 16:01 patriksvensson

Yes, it could be. When analyzing the code, I noticed that AnsiConsole's extension methods always receive pure values ("string", double, int and others), so I thought that in this case, since it will receive an IRenderable, it would be a class method rather than an extension.

I will remove these changes and just add an extension method that receives the IRenderable[] params

jos3s avatar Jan 31 '24 17:01 jos3s

@patriksvensson

I don't know why the build is breaking, I looked for the file displayed in the log and it doesn't exist

/home/runner/work/spectre.console/spectre.console/test/Spectre.Console.Tests/Unit/Widgets/ProgressBarTests.cs(3,2): error CS0619: 'UsesVerifyAttribute' is obsolete: 'No longer required. Usages of this attribute can be removed.'

*Resolved

jos3s avatar Jan 31 '24 20:01 jos3s

Looks like a nice clean implementation @jos3s at first glance, I'll prioritise reviewing this in the coming week.

FrankRay78 avatar Feb 01 '24 22:02 FrankRay78

@FrankRay78 I've already started the review

patriksvensson avatar Feb 01 '24 22:02 patriksvensson