nohwnd / Profiler

Script, ScriptBlock and module performance profiler for PowerShell 5, and PowerShell 7.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Present multiline commands better

nohwnd opened this issue · comments

#34 broke Text for multi-line commands. Line 1 entry showing text-value spanning 5 lines is kinda weird too, but new way currently loses some content, like Foreach-Object in demo below.

Before:
image

After:
image

Btw. I promise it's not my intention to just be complaining. 😄

Originally posted by @fflaten in #34 (comment)

It was like this before when I used files, and changed when I started using the Text from the hit. Then it went back again., it is balance between seeing multiline commands here, or not seeing all commands per line (as in your { 1; 2 } example. I think we could look at the hits and figure out if this is a multi line span (there should be property for that on sb, or we can look at startline != endline), and print the biggest one as:

Line
------
1-5

Or have StartLine EndLine but that will be making the result wider and will be same for lot of the lines.

Or have StartLine EndLine but that will be making the result wider and will be same for lot of the lines.

We can store it as start/end and use formatdata to display it as a single Line column showing range if multiline.

It is an option, but I don't like changing what is shown via format xml much, because then you write where and you can never filter against what you see on the screen and that sucks :)

How about a custom Line-class so we can allow most common filtering?

# Using PS class just for quick PoC
class Line {
    [int]$StartLine
    [int]$EndLine

    [string]ToString() {
        if($this.StartLine -ne $this.EndLine) {
            return "$($this.StartLine)-$($this.EndLine)"
        } else {
            return "$($this.StartLine)"
        }    
    }
    [bool]Equals([object]$o) {
        $result = $false
        switch ($o) {
            {$_ -is [int]} { $result = @(($this.StartLine)..($this.EndLine)) -contains $_ }
            {$_ -is [string]} { $result = ($this.ToString() -eq $_) }
        }
        return $result
    }
}

class LineProfile {
    [Line]$Lines
    [string]$Description = 'Exciting demo!'

    LineProfile([int]$StartLine, [int]$EndLine) {
        $this.Lines = [Line]@{ StartLine = $StartLine; EndLine = $EndLine }
    }
}

$lines = [lineprofile]::new(1,3), [lineprofile]::new(4,4)
$lines 

Description    Lines
-----------    -----
Exciting demo! 1-3
Exciting demo! 4

$lines | ? lines -eq 2

Description    Lines
-----------    -----
Exciting demo! 1-3

$lines | ? lines -eq '1-3'

Description    Lines
-----------    -----
Exciting demo! 1-3

$lines | ? lines -eq 3

Description    Lines
-----------    -----
Exciting demo! 1-3

$lines | ? lines -eq 4

Description    Lines
-----------    -----
Exciting demo! 4

Will think about it when I am done with the CC stuff for Pester.