mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-04 09:05:59 +08:00
84c7cc1801
Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>
40 lines
1023 B
Go
40 lines
1023 B
Go
package term
|
|
|
|
import (
|
|
"github.com/moby/term"
|
|
)
|
|
|
|
// TerminalSize represents the width and height of a terminal.
|
|
type TerminalSize struct {
|
|
Width uint16
|
|
Height uint16
|
|
}
|
|
|
|
// TerminalSizeQueue is capable of returning terminal resize events as they occur.
|
|
type TerminalSizeQueue interface {
|
|
// Next returns the new terminal size after the terminal has been resized. It returns nil when
|
|
// monitoring has been stopped.
|
|
Next() *TerminalSize
|
|
}
|
|
|
|
// GetSize returns the current size of the user's terminal. If it isn't a terminal,
|
|
// nil is returned.
|
|
func (t TTY) GetSize() *TerminalSize {
|
|
outFd, isTerminal := term.GetFdInfo(t.Out)
|
|
if !isTerminal {
|
|
return nil
|
|
}
|
|
return GetSize(outFd)
|
|
}
|
|
|
|
// GetSize returns the current size of the terminal associated with fd.
|
|
func GetSize(fd uintptr) *TerminalSize {
|
|
winsize, err := term.GetWinsize(fd)
|
|
if err != nil {
|
|
// runtime.HandleError(fmt.Errorf("unable to get terminal size: %v", err))
|
|
return nil
|
|
}
|
|
|
|
return &TerminalSize{Width: winsize.Width, Height: winsize.Height}
|
|
}
|