From 98ad66d6b58cd8e1e2f34e8aae5ae790c5de9734 Mon Sep 17 00:00:00 2001 From: Liam Galvin Date: Wed, 26 Feb 2020 13:29:22 +0000 Subject: [PATCH] Configure nesting in API --- pkg/terminal/terminal.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/pkg/terminal/terminal.go b/pkg/terminal/terminal.go index 10fd661..75faa29 100644 --- a/pkg/terminal/terminal.go +++ b/pkg/terminal/terminal.go @@ -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 @@ -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