mirror of
https://github.com/Dvorinka/Containr.git
synced 2026-10-28 15:51:26 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
401daf69aa |
No files matched your search
@@ -4,9 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
@@ -44,20 +42,13 @@ var ShellCmd = &cobra.Command{
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
defer term.Restore(fd, oldState)
|
defer term.Restore(fd, oldState)
|
||||||
}
|
}
|
||||||
if w, h, err := term.GetSize(fd); err == nil {
|
sendSize := func() {
|
||||||
_ = conn.WriteJSON(map[string]interface{}{"type": "resize", "cols": w, "rows": h})
|
|
||||||
}
|
|
||||||
// Forward SIGWINCH resizes.
|
|
||||||
sigCh := make(chan os.Signal, 1)
|
|
||||||
signal.Notify(sigCh, syscall.SIGWINCH)
|
|
||||||
defer signal.Stop(sigCh)
|
|
||||||
go func() {
|
|
||||||
for range sigCh {
|
|
||||||
if w, h, err := term.GetSize(fd); err == nil {
|
if w, h, err := term.GetSize(fd); err == nil {
|
||||||
_ = conn.WriteJSON(map[string]interface{}{"type": "resize", "cols": w, "rows": h})
|
_ = conn.WriteJSON(map[string]interface{}{"type": "resize", "cols": w, "rows": h})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
sendSize()
|
||||||
|
defer watchResize(sendSize)()
|
||||||
}
|
}
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
//go:build !windows
|
||||||
|
|
||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
// watchResize forwards SIGWINCH events to send. Returns a stop func.
|
||||||
|
func watchResize(send func()) func() {
|
||||||
|
sigCh := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(sigCh, syscall.SIGWINCH)
|
||||||
|
done := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-sigCh:
|
||||||
|
send()
|
||||||
|
case <-done:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
return func() {
|
||||||
|
signal.Stop(sigCh)
|
||||||
|
close(done)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
//go:build windows
|
||||||
|
|
||||||
|
package commands
|
||||||
|
|
||||||
|
// watchResize is a no-op on Windows — console resize events don't map to a
|
||||||
|
// signal. The initial size is still sent, and Windows Terminal resize is rare
|
||||||
|
// enough to accept stale dimensions for now.
|
||||||
|
func watchResize(send func()) func() { return func() {} }
|
||||||
Reference in new issue
Block a user