Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! Add word-wrap support based on terminal size
try using low-level platform-specific implementation
- Loading branch information
Showing
6 changed files
with
61 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// +build !aix | ||
// +build !darwin | ||
// +build !dragonfly | ||
// +build !freebsd | ||
// +build !linux,!appengine | ||
// +build !netbsd | ||
// +build !openbsd | ||
// +build !windows | ||
|
||
// The build constraints above are intended to be the negation of the | ||
// single-line constraint in termwidth_unix.go and also !windows. | ||
|
||
package cli | ||
|
||
import ( | ||
"errors" | ||
) | ||
|
||
func termWidth() (int, error) { | ||
return -1, errors.New("Unsupported platform") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// +build aix darwin dragonfly freebsd linux,!appengine netbsd openbsd | ||
// Only tested on linux and darwin so far... | ||
|
||
package cli | ||
|
||
import ( | ||
"os" | ||
|
||
"golang.org/x/sys/unix" | ||
) | ||
|
||
func termWidth() (int, error) { | ||
ws, err := unix.IoctlGetWinsize(int(os.Stdout.Fd()), unix.TIOCGWINSZ) | ||
if err != nil { | ||
return -1, err | ||
} | ||
|
||
return int(ws.Col), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package cli | ||
|
||
import ( | ||
"golang.org/x/sys/windows" | ||
) | ||
|
||
func termWidth() (int, error) { | ||
var info windows.ConsoleScreenBufferInfo | ||
|
||
// This seems to work in cmd.exe, powershell and cmder, but not in | ||
// git-bash. (Tested on windows 10.) | ||
err = windows.GetConsoleScreenBufferInfo(windows.Stdout, &info) | ||
if err != nil { | ||
return -1, err | ||
} | ||
|
||
return int(info.Size.X), nil | ||
} |