Skip to content

Commit

Permalink
revert: hide rprompt when the prompt is too large
Browse files Browse the repository at this point in the history
This reverts commit a8d4e51.
  • Loading branch information
JanDeDobbeleer committed May 22, 2021
1 parent a8d4e51 commit 5e9b04a
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Expand Up @@ -7,7 +7,7 @@
"request": "launch",
"mode": "debug",
"program": "${workspaceRoot}/src",
"args": ["--config=${workspaceRoot}/themes/jandedobbeleer.omp.json", "--shell=pwsh"]
"args": ["--config=${workspaceRoot}/themes/jandedobbeleer.omp.json"]
},
{
"name": "Launch tests",
Expand Down
17 changes: 1 addition & 16 deletions src/engine.go
Expand Up @@ -25,21 +25,6 @@ func (e *engine) string() string {
return e.console.String()
}

func (e *engine) canWriteRPrompt() bool {
prompt := e.string()
consoleWidth, err := e.env.getTerminalWidth()
if err != nil {
return true
}
promptWidth := e.ansi.lenWithoutANSI(prompt)
availableSpace := consoleWidth - promptWidth
if promptWidth > consoleWidth {
availableSpace = promptWidth - (promptWidth % consoleWidth)
}
promptBreathingRoom := 30
return (availableSpace - e.ansi.lenWithoutANSI(e.rprompt)) >= promptBreathingRoom
}

func (e *engine) render() string {
for _, block := range e.config.Blocks {
e.renderBlock(block)
Expand Down Expand Up @@ -166,7 +151,7 @@ func (e *engine) print() string {
prompt += fmt.Sprintf("\nRPROMPT=\"%s\"", e.rprompt)
return prompt
case pwsh, powershell5, bash, plain:
if e.rprompt == "" || !e.canWriteRPrompt() {
if e.rprompt == "" {
break
}
e.write(e.ansi.saveCursorPosition)
Expand Down
43 changes: 0 additions & 43 deletions src/engine_test.go

This file was deleted.

7 changes: 0 additions & 7 deletions src/environment.go
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/distatus/battery"
"github.com/shirou/gopsutil/host"
"github.com/shirou/gopsutil/process"
terminal "github.com/wayneashleyberry/terminal-dimensions"
)

const (
Expand Down Expand Up @@ -74,7 +73,6 @@ type environmentInfo interface {
hasParentFilePath(path string) (fileInfo *fileInfo, err error)
isWsl() bool
stackCount() int
getTerminalWidth() (int, error)
}

type commandCache struct {
Expand Down Expand Up @@ -325,11 +323,6 @@ func (env *environment) stackCount() int {
return *env.args.StackCount
}

func (env *environment) getTerminalWidth() (int, error) {
width, err := terminal.Width()
return int(width), err
}

func cleanHostName(hostName string) string {
garbage := []string{
".lan",
Expand Down
3 changes: 1 addition & 2 deletions src/go.mod
Expand Up @@ -26,8 +26,7 @@ require (
github.com/stretchr/objx v0.3.0 // indirect
github.com/stretchr/testify v1.7.0
github.com/tklauser/go-sysconf v0.3.5 // indirect
github.com/wayneashleyberry/terminal-dimensions v1.0.0
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a // indirect
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb
golang.org/x/sys v0.0.0-20210324051608-47abb6519492
golang.org/x/text v0.3.5
Expand Down
6 changes: 2 additions & 4 deletions src/go.sum
Expand Up @@ -101,14 +101,12 @@ github.com/tklauser/go-sysconf v0.3.5/go.mod h1:MkWzOF4RMCshBAMXuhXJs64Rte09mITn
github.com/tklauser/numcpus v0.2.2 h1:oyhllyrScuYI6g+h/zUvNXNp1wy7x8qQy3t/piefldA=
github.com/tklauser/numcpus v0.2.2/go.mod h1:x3qojaO3uyYt0i56EW/VUYs7uBvdl2fkfZFu0T9wgjM=
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/wayneashleyberry/terminal-dimensions v1.0.0 h1:LawtS1nqKjAfqrmKOzkcrDLAjSzh38lEhC401JPjQVA=
github.com/wayneashleyberry/terminal-dimensions v1.0.0/go.mod h1:PW2XrtV6KmKOPhuf7wbtcmw1/IFnC39mryRET2XbxeE=
github.com/zclconf/go-cty v1.2.0/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a h1:kr2P4QFmQr29mSLA43kwrOcgcReGTfbE9N577tCTuBc=
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 h1:It14KIkyBFYkHkwZ7k45minvA9aorojkyjGk9KJ5B/w=
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb h1:fqpd0EBDzlHRCjiphRR5Zo/RSWWQlWv34418dnEixWk=
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/net v0.0.0-20180811021610-c39426892332/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down
5 changes: 0 additions & 5 deletions src/segment_path_test.go
Expand Up @@ -142,11 +142,6 @@ func (env *MockedEnvironment) isWsl() bool {
return false
}

func (env *MockedEnvironment) getTerminalWidth() (int, error) {
args := env.Called(nil)
return args.Int(0), args.Error(1)
}

const (
homeBill = "/home/bill"
homeJan = "/usr/home/jan"
Expand Down

0 comments on commit 5e9b04a

Please sign in to comment.