Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
faedac0
commit 19ab67d
Showing
6 changed files
with
72 additions
and
59 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
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,44 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
"syscall" | ||
"unsafe" | ||
|
||
"golang.org/x/crypto/ssh/terminal" | ||
) | ||
|
||
type winsize struct { | ||
Row uint16 | ||
Col uint16 | ||
Xpixel uint16 | ||
Ypixel uint16 | ||
} | ||
|
||
func isTerminal(fd *os.File) bool { | ||
return terminal.IsTerminal(int(fd.Fd())) | ||
} | ||
|
||
func getTermWidth(scall uintptr) uint { | ||
ws := &winsize{} | ||
retCode, _, errno := syscall.Syscall(syscall.SYS_IOCTL, | ||
uintptr(scall), | ||
uintptr(syscall.TIOCGWINSZ), | ||
uintptr(unsafe.Pointer(ws))) | ||
|
||
if int(retCode) == -1 { | ||
panic(errno) | ||
} | ||
return uint(ws.Col) | ||
} | ||
|
||
func padToWidth(text string, w int) string { | ||
spCount := w - len(text) | ||
if spCount < 0 { | ||
spCount = 0 | ||
} | ||
sp := strings.Repeat(" ", spCount) | ||
return fmt.Sprintf("%s%s", text, sp) | ||
} |
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