Skip to content

Update default PSHost console width to 120 #129

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

Closed
daviwil opened this issue Feb 3, 2016 · 20 comments
Closed

Update default PSHost console width to 120 #129

daviwil opened this issue Feb 3, 2016 · 20 comments
Labels
Issue-Enhancement A feature request (enhancement).
Milestone

Comments

@daviwil
Copy link
Contributor

daviwil commented Feb 3, 2016

Now that VS Code shows the Debug Console and Output Window in a horizontal window it makes sense to increase the default width of the PSHost so that more text can be displayed on a single line.

@rkeithhill
Copy link
Contributor

I mentioned this on the vscode issue but I'll repeat it here. The script output is not prematurely wrapped. This happens when I execute a command from the debug console when I'm debugging. This makes it more corner case. And I can workaround it in the debug console by executing:

gci | out-string -width 120

@daviwil
Copy link
Contributor Author

daviwil commented Feb 4, 2016

I think only output formatters (Format-*) obey the console width requirements. Any calls to Write-Output will write the lines as wide as they're given. Setting the default console width to be a lot wider will fix the formatter issue.

@rkeithhill
Copy link
Contributor

I think I found the method to modify:

        private Command GetOutputCommand(bool endOfStatement)
        {
            Command outputCommand =
                new Command(
                    command: this.IsDebuggerStopped ? "Out-String" : "Out-Default",
                    isScript: false,
                    useLocalScope: true);

            if (this.IsDebuggerStopped)
            {
                // Out-String needs the -Stream parameter added
                outputCommand.Parameters.Add("Stream");
            }

            return outputCommand;
        }

If the debugger is stopped we need to use Out-String but we need to pass it the width parameter. Should I hardcode that to 120 or should that be a setting? Haven't figured out to add settings yet (and reference them from PSES code).

OK updated that to:

...
            if (this.IsDebuggerStopped)
            {
                // The default width of 79 chars is too narrow.
                outputCommand.Parameters.Add("Width", 120);

                // Out-String needs the -Stream parameter added
                outputCommand.Parameters.Add("Stream");
            }
...

Works good. Now just to determine if that 120 should be a setting or not.

@daviwil
Copy link
Contributor Author

daviwil commented Feb 4, 2016

You should only need to change this line:

https://github.com/PowerShell/PowerShellEditorServices/blob/master/src/PowerShellEditorServices/Session/SessionPSHostRawUserInterface.cs#L22

I'm pretty sure this is what's controlling the width of the output. If you change the first value from 80 to 120 it should work. The fix you're making helps for the debug adapter but we need this to work for the Run Selection (F8) command as well.

@daviwil
Copy link
Contributor Author

daviwil commented Feb 4, 2016

Making a setting for this will take a bit more work because you'll have to plumb a settings object all the way down through the PSHost classes. I'd say hold off on that for now because I need to figure out a good strategy for passing settings around in the design.

@rkeithhill
Copy link
Contributor

I'll give this a go tonight. Thanks for the pointer.

@daviwil
Copy link
Contributor Author

daviwil commented Feb 4, 2016

Cool, thanks!

@daviwil
Copy link
Contributor Author

daviwil commented Feb 5, 2016

I was messing around with debugger stuff so I made the change to see if it would work. Here's what gci looks like with a width of 120:

-a----         2/4/2016   7:39 PM         331264 Microsoft.PowerShell.EditorServices.pdb                               
-a----         2/4/2016   7:39 PM         133120 Microsoft.PowerShell.EditorServices.Protocol.dll                      
-a----         2/4/2016   7:39 PM         357888 Microsoft.PowerShell.EditorServices.Protocol.pdb                      
-a----         2/4/2016   7:39 PM         162572 Microsoft.PowerShell.EditorServices.xml                               
-a----         2/4/2016   7:29 PM         176128 Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll          
-a----         2/4/2016   7:29 PM         345600 Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.pdb          
-a----         2/4/2016   7:29 PM         133632 Microsoft.Windows.PowerShell.ScriptAnalyzer.dll                       
-a----         2/4/2016   7:29 PM         335360 Microsoft.Windows.PowerShell.ScriptAnalyzer.pdb                       
-a----        7/24/2015   3:57 PM         520192 Newtonsoft.Json.dll                                      

Since I've already made the fix, mind if I just include it with my next PR?

@rkeithhill
Copy link
Contributor

Not at all. BTW don't we need to update this code as well?

public override Size MaxPhysicalWindowSize
{
    get { return new Size(80, 20); }
}

/// <summary>
/// Gets the maximum size of the console window.
/// </summary>
public override Size MaxWindowSize
{
    get { return new Size(80, 20); }
}

Also it would "ideal" if VSCode sent us a message at debug start and whenever the dbg console window dimensions (rows, cols) change during debug. Then these sizes could reflect the actual size of the dbg console.

@daviwil
Copy link
Contributor Author

daviwil commented Feb 5, 2016

hah! Looks like you're working on it now too. I don't think those need to be changed, they may only get used if advanced buffer math is involved. You should submit the PR since you've been looking into it already.

@rkeithhill
Copy link
Contributor

No problem. It's just that one line right? I'll submit it in a few minutes.

@daviwil
Copy link
Contributor Author

daviwil commented Feb 5, 2016

Yep, just that one line. No rush at all!

@rkeithhill
Copy link
Contributor

That max info does show up if you query $host.ui.rawui in the dbg con:

[DBG]: PS C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\src\PowerShellEditorServices.Host\bin\Debug> 
$host.ui.rawui


ForegroundColor       : White
BackgroundColor       : Black
CursorPosition        : 0,0
WindowPosition        : 0,0
CursorSize            : 0
BufferSize            : 80,100
WindowSize            : 0,0
MaxWindowSize         : 80,20
MaxPhysicalWindowSize : 80,20
KeyAvailable          : False
WindowTitle           :

I don't think it would interfere with anything to keep the widths consistently 120. What do think?

@daviwil
Copy link
Contributor Author

daviwil commented Feb 5, 2016

Shouldn't be a problem, go ahead and change those too

@rkeithhill
Copy link
Contributor

Just about done with this. I feel like a dufus here but I just noticed the "Output" window. I had been so hung on the Debug Console. What I don't get is - what determines where script output goes? I see that it goes to the Debug Console. The only thing I see appear in the Output window is when I execute using F8. Does that sound about right?

@daviwil
Copy link
Contributor Author

daviwil commented Feb 5, 2016

Yep, your understanding is correct. Debug Console is for debugger output, Output window is for F8 output.

@daviwil
Copy link
Contributor Author

daviwil commented Feb 5, 2016

Fixed by commit 506d713

@daviwil daviwil closed this as completed Feb 5, 2016
@daviwil
Copy link
Contributor Author

daviwil commented Feb 5, 2016

By the way, in the future you can write your commit messages in a certain way so that GitHub automatically resolves them once your PR is merged. If you write something like "Fix #129", "Fixes #129", or "Resolves #129" in your commit message, it will happen automatically :)

@rkeithhill
Copy link
Contributor

Didn't know that. Thanks for the tip!

@daviwil
Copy link
Contributor Author

daviwil commented Feb 5, 2016

Yep, you can write it anywhere in the message. Sometimes I write it in the top line, other times I write it on its own line at the end of the commit message. It's pretty smart about picking those up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Enhancement A feature request (enhancement).
Projects
None yet
Development

No branches or pull requests

2 participants