fix: provide terminal width from CLI

This commit is contained in:
Jan De Dobbeleer 2022-02-06 11:01:46 +01:00 committed by Jan De Dobbeleer
parent 8f3bfd674b
commit 4c4b97fa8b
6 changed files with 16 additions and 4 deletions

View file

@ -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": "."
```

View file

@ -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) {

View file

@ -56,6 +56,7 @@ type Args struct {
CachePath *bool
Migrate *bool
Write *bool
TerminalWidth *int
}
type CommandError struct {

View file

@ -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
}

View file

@ -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())

View file

@ -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 {