From 4c4b97fa8b37e0126e91dd3f26f6c378bb864470 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Sun, 6 Feb 2022 11:01:46 +0100 Subject: [PATCH] fix: provide terminal width from CLI --- docs/docs/config-block.md | 4 ++-- src/engine/init/omp.ps1 | 3 ++- src/environment/shell.go | 1 + src/environment/unix.go | 5 ++++- src/environment/windows.go | 3 +++ src/main.go | 4 ++++ 6 files changed, 16 insertions(+), 4 deletions(-) diff --git a/docs/docs/config-block.md b/docs/docs/config-block.md index d0f3ff98..34ec5b7b 100644 --- a/docs/docs/config-block.md +++ b/docs/docs/config-block.md @@ -47,10 +47,10 @@ Tell the engine if the block should be left or right-aligned. ### Filler When you want to join a right and left aligned block with a repeated set of characters, add the character -to be repeated to this property. Add this property to the _left_ aligned block. +to be repeated to this property. Add this property to the _right_ aligned block. ```json -"alignment": "left", +"alignment": "right", "filler": "." ``` diff --git a/src/engine/init/omp.ps1 b/src/engine/init/omp.ps1 index 60b48f12..c11d64b1 100644 --- a/src/engine/init/omp.ps1 +++ b/src/engine/init/omp.ps1 @@ -89,7 +89,8 @@ function global:Initialize-ModuleSupport { $executionTime = ($history.EndExecutionTime - $history.StartExecutionTime).TotalMilliseconds $global:omp_lastHistoryId = $history.Id } - $standardOut = @(&$omp --error="$errorCode" --pwd="$cleanPWD" --pswd="$cleanPSWD" --execution-time="$executionTime" --stack-count="$stackCount" --config="$config" 2>&1) + $terminalWidth = $Host.UI.RawUI.WindowSize.Width + $standardOut = @(&$omp --error="$errorCode" --pwd="$cleanPWD" --pswd="$cleanPSWD" --execution-time="$executionTime" --stack-count="$stackCount" --config="$config" --terminal-width=$terminalWidth 2>&1) # make sure PSReadLine knows we have a multiline prompt $extraLines = $standardOut.Count - 1 if ($extraLines -gt 0) { diff --git a/src/environment/shell.go b/src/environment/shell.go index 316ad346..7452f386 100644 --- a/src/environment/shell.go +++ b/src/environment/shell.go @@ -56,6 +56,7 @@ type Args struct { CachePath *bool Migrate *bool Write *bool + TerminalWidth *int } type CommandError struct { diff --git a/src/environment/unix.go b/src/environment/unix.go index 435a0643..39ec54d1 100644 --- a/src/environment/unix.go +++ b/src/environment/unix.go @@ -45,9 +45,12 @@ func (env *ShellEnvironment) IsWsl2() bool { func (env *ShellEnvironment) TerminalWidth() (int, error) { defer env.trace(time.Now(), "TerminalWidth") + if *env.args.TerminalWidth != 0 { + return *env.args.TerminalWidth, nil + } width, err := terminal.Width() if err != nil { - env.log(Error, "RunCommand", err.Error()) + env.log(Error, "TerminalWidth", err.Error()) } return int(width), err } diff --git a/src/environment/windows.go b/src/environment/windows.go index 1c01b999..b71da0dd 100644 --- a/src/environment/windows.go +++ b/src/environment/windows.go @@ -86,6 +86,9 @@ func (env *ShellEnvironment) IsWsl2() bool { func (env *ShellEnvironment) TerminalWidth() (int, error) { defer env.trace(time.Now(), "TerminalWidth") + if *env.args.TerminalWidth != 0 { + return *env.args.TerminalWidth, nil + } handle, err := syscall.Open("CONOUT$", syscall.O_RDWR, 0) if err != nil { env.log(Error, "TerminalWidth", err.Error()) diff --git a/src/main.go b/src/main.go index 3c42bb60..f891f12d 100644 --- a/src/main.go +++ b/src/main.go @@ -129,6 +129,10 @@ func main() { "write", false, "Write the config to the file"), + TerminalWidth: flag.Int( + "terminal-width", + 0, + "The width of the terminal"), } flag.Parse() if *args.Version {