May 12 2024 11:56 AM
Is it possible to get powershell to horizontally scroll for long lines of text instead of having them wrap automatically to the next line?
I'm running python, and if you're familiar with python dataframes you can think of it like a speadsheet. I'm having python output many columns, and right now it's wrapping the output to separate lines. Think of having a sheet in excel where for more columns instead of having a horizontal scroll excel wraps it - it's very unreadable.
Right now, I have to redirect my output to a .txt file and then open in notepad, where I can horizontally scroll without word wrap, to see the output in a readable fashion. However, if I could make powershell horizontally scroll instead of wrapping, this would save me a step.
Alternately, if not possible in powershell but possible in plain old command prompt I can run python in the command prompt. However, I'd prefer not to as I can't SSH into remote servers from plain command prompt, and sometimes I need to run python remotely so it would be useful to do it in powershell, thanks.
May 12 2024 01:10 PM
May 12 2024 01:14 PM
May 12 2024 01:29 PM - edited May 12 2024 01:31 PM
@sawtooth500 If you use PowerShell ands store something in a variable, you can pipe and wrap it using $variable | Format-Table -Wrap. If you use Get-Content c:\temp\xyz\123.txt, it should wrap it for you.
Example of using -Wrap, first output was without, then I edited the script and then you can see the difference.
May 12 2024 04:35 PM
Hi, Taras.
Try the following, where in this example, I've used a buffer width of 256.
$host.UI.RawUI.BufferSize = [System.Management.Automation.Host.Size]::new(256, ($host.UI.RawUI.BufferSize.Height));
Note: This is only worth using under the default shells. If you try it under Windows Terminal, it creates issues as Windows Terminal suppresses the horizontal scroll bar.
Cheers,
Lain
May 12 2024 07:33 PM
May 12 2024 07:51 PM - edited May 12 2024 07:51 PM
Are you using the standard shell?
I've tested the standard shells for both Windows PowerShell and PowerShell and I do get the horizontal scroll bar as show below.
Given you said you wanted a value of 7,000, you might want to try that instead of the 256 value I was using, since if your current width is greater than 256 characters, you wouldn't expect to see a horizontal scroll bar.
The PowerShell default shell behaves the same way, so I haven't bothered including the almost-identical screenshots from it.
Cheers,
Lain
May 12 2024 08:33 PM
May 12 2024 09:33 PM
I haven't watched the video, however, if you're resizing your window after running the command then the application window property shown below will undo the command's changes.
You'd need to uncheck this property to avoid the undoing of the programmatic changing of the buffer width.
Note that unchecking this option means the unchecking will persist between sessions, impacting all future windows as they're opened.
I guess that leads to perhaps a final point: if you don't need to change the buffer width dynamically, just set the properties above to your liking and walk away, as that'd be job done.
However, if you're saying that even after doing this (and this also applies to the programmatic change method) you still don't see the horizontal scroll bar, then I can't help as I'm not seeing that behaviour on my client using the default shells.
Cheers,
Lain
May 12 2024 09:38 PM
And don't forget to use your own value instead of what I used (256 characters) in my simple example. Perhaps try something like 2,048 and see how you go.
Cheers,
Lain