refactor(terminalwidth): add debug info

This commit is contained in:
Jan De Dobbeleer 2023-08-04 21:02:21 +02:00 committed by Jan De Dobbeleer
parent f55da0ebcb
commit 3f1eb821f0
2 changed files with 13 additions and 3 deletions

View file

@ -55,15 +55,20 @@ func (env *Shell) IsWsl2() bool {
func (env *Shell) TerminalWidth() (int, error) {
defer env.Trace(time.Now())
if env.CmdFlags.TerminalWidth > 0 {
env.DebugF("terminal width: %d", env.CmdFlags.TerminalWidth)
return env.CmdFlags.TerminalWidth, nil
}
width, err := terminal.Width()
if err != nil {
env.Error(err)
}
return int(width), err
env.DebugF("terminal width: %d", width)
env.CmdFlags.TerminalWidth = int(width)
return env.CmdFlags.TerminalWidth, err
}
func (env *Shell) Platform() string {

View file

@ -87,22 +87,27 @@ func (env *Shell) IsWsl2() bool {
func (env *Shell) TerminalWidth() (int, error) {
defer env.Trace(time.Now())
if env.CmdFlags.TerminalWidth > 0 {
env.DebugF("terminal width: %d", env.CmdFlags.TerminalWidth)
return env.CmdFlags.TerminalWidth, nil
}
handle, err := syscall.Open("CONOUT$", syscall.O_RDWR, 0)
if err != nil {
env.Error(err)
return 0, err
}
info, err := winterm.GetConsoleScreenBufferInfo(uintptr(handle))
if err != nil {
env.Error(err)
return 0, err
}
// return int(float64(info.Size.X) * 0.57), nil
return int(info.Size.X), nil
env.CmdFlags.TerminalWidth = int(info.Size.X)
env.DebugF("terminal width: %d", env.CmdFlags.TerminalWidth)
return env.CmdFlags.TerminalWidth, nil
}
func (env *Shell) Platform() string {