mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-25 11:04:04 -08:00
feat: allow auto hiding of rprompt on Windows
This commit is contained in:
parent
cb9a090ec7
commit
6bef088b83
|
@ -33,11 +33,14 @@ func (e *engine) canWriteRPrompt() bool {
|
|||
}
|
||||
promptWidth := e.ansi.lenWithoutANSI(prompt)
|
||||
availableSpace := consoleWidth - promptWidth
|
||||
if promptWidth > consoleWidth {
|
||||
availableSpace = promptWidth - (promptWidth % consoleWidth)
|
||||
// spanning multiple lines
|
||||
if availableSpace < 0 {
|
||||
overflow := promptWidth % consoleWidth
|
||||
availableSpace = consoleWidth - overflow
|
||||
}
|
||||
promptBreathingRoom := 30
|
||||
return (availableSpace - e.ansi.lenWithoutANSI(e.rprompt)) >= promptBreathingRoom
|
||||
canWrite := (availableSpace - e.ansi.lenWithoutANSI(e.rprompt)) >= promptBreathingRoom
|
||||
return canWrite
|
||||
}
|
||||
|
||||
func (e *engine) render() string {
|
||||
|
|
|
@ -22,7 +22,7 @@ func TestCanWriteRPrompt(t *testing.T) {
|
|||
{Case: "Terminal > Prompt enabled edge", Expected: true, TerminalWidth: 200, PromptLength: 100, RPromptLength: 70},
|
||||
{Case: "Terminal > Prompt disabled no breathing", Expected: false, TerminalWidth: 200, PromptLength: 100, RPromptLength: 71},
|
||||
{Case: "Prompt > Terminal enabled", Expected: true, TerminalWidth: 200, PromptLength: 300, RPromptLength: 70},
|
||||
{Case: "Prompt > Terminal disabled no breathing", Expected: true, TerminalWidth: 200, PromptLength: 300, RPromptLength: 80},
|
||||
{Case: "Prompt > Terminal disabled no breathing", Expected: false, TerminalWidth: 200, PromptLength: 300, RPromptLength: 80},
|
||||
{Case: "Prompt > Terminal disabled no room", Expected: true, TerminalWidth: 200, PromptLength: 400, RPromptLength: 80},
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,6 @@ func TestCanWriteRPrompt(t *testing.T) {
|
|||
engine.rprompt = strings.Repeat("x", tc.RPromptLength)
|
||||
engine.console.WriteString(strings.Repeat("x", tc.PromptLength))
|
||||
got := engine.canWriteRPrompt()
|
||||
assert.Equal(t, tc.Expected, got)
|
||||
assert.Equal(t, tc.Expected, got, tc.Case)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,10 +3,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/Azure/go-ansiterm/winterm"
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
|
@ -70,7 +71,16 @@ func (env *environment) isWsl() bool {
|
|||
|
||||
func (env *environment) getTerminalWidth() (int, error) {
|
||||
defer env.tracer.trace(time.Now(), "getTerminalWidth")
|
||||
return 0, errors.New("Unsupported on Windows")
|
||||
handle, err := syscall.GetStdHandle(syscall.STD_OUTPUT_HANDLE)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
info, err := winterm.GetConsoleScreenBufferInfo(uintptr(handle))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
// return int(float64(info.Size.X) * 0.57), nil
|
||||
return int(info.Size.X), nil
|
||||
}
|
||||
|
||||
func (env *environment) getPlatform() string {
|
||||
|
|
|
@ -3,6 +3,7 @@ module oh-my-posh
|
|||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1
|
||||
github.com/BurntSushi/toml v0.4.1 // indirect
|
||||
github.com/Masterminds/sprig/v3 v3.2.2
|
||||
github.com/StackExchange/wmi v1.2.1 // indirect
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
|
||||
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/BurntSushi/toml v0.4.1 h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw=
|
||||
github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||
|
@ -159,6 +161,7 @@ golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210816074244-15123e1e1f71 h1:ikCpsnYR+Ew0vu99XlDp55lGgDJdIMx3f4a18jfse/s=
|
||||
golang.org/x/sys v0.0.0-20210816074244-15123e1e1f71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
|
Loading…
Reference in a new issue