mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-10 04:54:03 -08:00
refactor(terminalwidth): add debug info
This commit is contained in:
parent
f55da0ebcb
commit
3f1eb821f0
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue