Skip to content

Commit

Permalink
More optimizations
Browse files Browse the repository at this point in the history
Signed-off-by: xplshn <xplshn@murena.io>
  • Loading branch information
xplshn committed Dec 11, 2024
1 parent e3abdf3 commit 5dbd931
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion utility.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,22 @@ func getTerminalWidth() int {
return 80
}

// func inputIsPiped() bool {
// fi, _ := os.Stdin.Stat()
// if (fi.Mode() & os.ModeCharDevice) == 0 {
// return true
// }
// return false
// }

// NOTE: \n will always get cut off when using a truncate function, this may also happen to other formatting options
// truncateSprintf formats the string and truncates it if it exceeds the terminal width.
func truncateSprintf(indicator, format string, a ...interface{}) string {
// Format the string first
formatted := fmt.Sprintf(format, a...)

// Check if output is piped
if ! term.IsTerminal(0) {
if !term.IsTerminal(int(os.Stdout.Fd())) {
return formatted // No truncation if output is being piped to another program
}

Expand Down

0 comments on commit 5dbd931

Please sign in to comment.