PowerShell / ConsoleGuiTools

Modules that mix PowerShell and GUIs/CUIs!
https://www.powershellgallery.com/packages/Microsoft.PowerShell.ConsoleGuiTools
MIT License
776 stars 59 forks source link

Add `Show-ObjectTree` cmdlet #179

Closed tznind closed 10 months ago

tznind commented 1 year ago

PR Summary

Adds the out-ShowObject command which presents the passed objects in a tree. Below each object passed appear its public fields/properties.

TreeView fetches children as branches are expanded so the full tree is not built up front which helps with performance in cases of deep or expansive nesting.

out-showobject

PR Context

This is my first time working with powershell commandlets so please be gentle.

I thought I would look into implementing #178 . Let me know if this is not what you were expecting. If its not wildly out.

I am happy to look into adding whatever else is required (e.g. filtering / highlighting etc).

tznind commented 1 year ago

@microsoft-github-policy-service agree

I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.

claudio-salvio commented 1 year ago

Hello @tznind

First of all, thank you for your contribution

I would like to propose you to consider another name, out-showobject seems to me a bit strange. Maybe, you could consider something like Show-ObjectTree or Show-ObjectAsTree.

Best regards

tznind commented 1 year ago

I would like to propose you to consider another name, out-showobject seems to me a bit strange. Maybe, you could consider something like Show-ObjectTree or Show-ObjectAsTree.

Good point. I've renamed it Show-ObjectTree.

I also added a StatusBar that shows original object count and selected leaf Type. And I've made it expand IEnumerable values (except string) similarly to how VisualStudio watch window does:

image

MrFly72 commented 1 year ago

I like this idea. It helps debugging object values. That would even drive me to put it on a windows-box :-)

SteveL-MSFT commented 1 year ago

@tznind This is really neat, are you still working on this? I think you can do it iteratively when thinking about adding more features.

tig commented 1 year ago

@tznind This is really neat, are you still working on this? I think you can do it iteratively when thinking about adding more features.

I am now curious about how we can make ocgv and this work together seemlessly. By default selecting something in ocgv and having show-object launch will cause a bunch of screeen repaint.

We really need non-full-screen Terminal.Gui apps... https://github.com/gui-cs/Terminal.Gui/issues/272

tznind commented 1 year ago

@tznind This is really neat, are you still working on this? I think you can do it iteratively when thinking about adding more features.

Yes! I'm excited to get back to this. I agree an iterative approach would be good. I've marked it ready for review. Let me know if there are required features for a first version. Theres a lot that would be nice to add later (e.g. search, handling big arrays smarter).

I am now curious about how we can make ocgv and this work together seemlessly. By default selecting something in ocgv and having show-object launch will cause a bunch of screeen repaint.

Yes I'd love to explore this also. Maybe a shortcut or something in ocgv to show a modal with the tree for currently selected object (or all objects)?

andyleejordan commented 1 year ago

@tig, @tznind, and @SteveL-MSFT are we thinking this is good to review and potentially merge? I can't quite tell from the discussion above.

tznind commented 1 year ago

@tig, @tznind, and @SteveL-MSFT are we thinking this is good to review and potentially merge? I can't quite tell from the discussion above.

Its a yes from me.

In terms of iterative improvement of this feature, I have a PR in Terminal.Gui to support filtering in TreeView<T> component (https://github.com/gui-cs/Terminal.Gui/pull/2599).

It is merged to develop and will be in the next library release. Once that is out I can update this feature to have search. But can do that on a subsequent PR.

But if you want to wait and review it all at once that's fine too.

tig commented 1 year ago

If I can get T.Gui v1.11 out before Andrew gets to this we should include it. I'll try in next 24 hrs but no promises.

tig commented 1 year ago

I wanted to use Show-ObjectTree to act as an interactive version of tree.

How would I do that?

tznind commented 1 year ago

I wanted to use Show-ObjectTree to act as an interactive version of tree.

How would I do that?

So Get-ChildItem | Show-ObjectTree probably makes the most sense for this use case.

This gives DirectoryInfo and FileInfo typed objects.

The current behaviour of Show-ObjectTree for any object type is to show the public fields/properties of the objects passed. In the case of DirectoryInfo this is Length, IsReadOnly, LastAccessTime etc.

We could detect when all the passed objects are IO objects and change the behaviour to enumerate children on expansion instead.

Optionally the user could pass a flag to prevent that behaviour?

tig commented 1 year ago

@tznind - A bunch of the comments I added above have not been addressed in this PR.

Will you be able to tackle these sometime soon?

tznind commented 1 year ago

Yes sorry has fallen down my list a bit but can look again at it.

ALthough with the new TreeTable data source in v2 I have been wondering if just adding a --tree flag to existing command would be easier.

It would allow viewing and selecting child elements in line. For example pipe some folders to ocgv then expand one and select some files within as the ogcv command output.

On Wed, 19 Jul 2023, 15:45 Tig, @.***> wrote:

@tznind https://github.com/tznind - A bunch of the comments I added above have not been addressed in this PR.

  • docs
  • lowercase show-object isn't working
  • inconsistent UI with ocgv
  • ...

Will you be able to tackle these sometime soon?

— Reply to this email directly, view it on GitHub https://github.com/PowerShell/GraphicalTools/pull/179#issuecomment-1642229729, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHO3C5FGMXTEYTTZIXFI4VDXQ7XJHANCNFSM6AAAAAATQ2JIDY . You are receiving this because you were mentioned.Message ID: @.***>

tznind commented 1 year ago

I wanted to use Show-ObjectTree to act as an interactive version of tree.

How would I do that?

The default 'child getter' is to enumerate the properties on the PSObject and express as <prop name>:<prop value>. This works well for all objects I have tried it with.

I have added a 'special cases' method called GetExtraChildren which allows adding additional tree elements for specific types of objects. So now DirectoryInfo objects also show child files/directories.

image

I am open to suggestions on how to do this. Some ideas I thought about included:

I don't really like the Contents idea as it adds an extra layer to the tree you have to expand which is onerous for deep trees and just generally annoying.

andyleejordan commented 1 year ago

@tig are you happy enough with this for me to do a review and potential merge now?

StartAutomating commented 1 year ago

@tznind @tig really cool work!

Can't wait to figure out how it will integrate with Write-FormatTreeView so that any object can be formatted as a tree!

andyleejordan commented 10 months ago

@tznind - A bunch of the comments I added above have not been addressed in this PR.

@tig it looks like this has been updated since you last looked. I'd prefer to merge this before the next release! Do you agree?

tig commented 10 months ago

@tznind - A bunch of the comments I added above have not been addressed in this PR.

@tig it looks like this has been updated since you last looked. I'd prefer to merge this before the next release! Do you agree?

@tznind can you add support for -Debug and -UseNetConsole as I did to ocgv so we remain consistent?

tznind commented 10 months ago

@tznind - A bunch of the comments I added above have not been addressed in this PR.

@tig it looks like this has been updated since you last looked. I'd prefer to merge this before the next release! Do you agree?

@tznind can you add support for -Debug and -UseNetConsole as I did to ocgv so we remain consistent?

I have added these settings in 3c654e9

image