Skip to content

Commit

Permalink
fix: provide terminal width from CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
JanDeDobbeleer committed Feb 6, 2022
1 parent 8f3bfd6 commit 4c4b97f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docs/docs/config-block.md
Expand Up @@ -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": "."
```

Expand Down
3 changes: 2 additions & 1 deletion src/engine/init/omp.ps1
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/environment/shell.go
Expand Up @@ -56,6 +56,7 @@ type Args struct {
CachePath *bool
Migrate *bool
Write *bool
TerminalWidth *int
}

type CommandError struct {
Expand Down
5 changes: 4 additions & 1 deletion src/environment/unix.go
Expand Up @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions src/environment/windows.go
Expand Up @@ -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())
Expand Down
4 changes: 4 additions & 0 deletions src/main.go
Expand Up @@ -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 {
Expand Down

0 comments on commit 4c4b97f

Please sign in to comment.