Skip to content

Commit

Permalink
Configure nesting in API
Browse files Browse the repository at this point in the history
  • Loading branch information
liamg committed Feb 26, 2020
1 parent 232dd5f commit 98ad66d
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions pkg/terminal/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import (

// Terminal communicates with the underlying terminal which is running shox
type Terminal struct {
shell string
proxy *proxy.Proxy
pty *os.File
shell string
proxy *proxy.Proxy
pty *os.File
enableNesting bool
}

// NewTerminal creates a new terminal instance
Expand Down Expand Up @@ -52,15 +53,21 @@ func (t *Terminal) Pty() *os.File {
return t.pty
}

// SetNestingAllowed sets whether multiple shox bars can be nested inside each other
func (t *Terminal) SetNestingAllowed(allowed bool) {
t.enableNesting = allowed
}

// Run starts the terminal/shell proxying process
func (t *Terminal) Run() error {

if os.Getenv("SHOX") != "" {
return fmt.Errorf("shox is already running in this terminal")
if !t.enableNesting {
if os.Getenv("SHOX") != "" {
return fmt.Errorf("shox is already running in this terminal")
}
_ = os.Setenv("SHOX", "1")
}

_ = os.Setenv("SHOX", "1")

t.proxy.Start()
defer t.proxy.Close()
t.proxy.Write([]byte("\033c")) // reset term
Expand Down

0 comments on commit 98ad66d

Please sign in to comment.