Skip to content

Commit ae96cc7

Browse files
authored
Merge branch 'main' into tzafon-computer-use
2 parents 4db9163 + 9f7b3df commit ae96cc7

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

cmd/browsers.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"strconv"
1616
"strings"
1717

18+
"github.com/kernel/cli/pkg/table"
1819
"github.com/kernel/cli/pkg/util"
1920
"github.com/kernel/kernel-go-sdk"
2021
"github.com/kernel/kernel-go-sdk/option"
@@ -3256,6 +3257,9 @@ func runBrowsersComputerWriteClipboard(cmd *cobra.Command, args []string) error
32563257
}
32573258

32583259
func truncateURL(url string, maxLen int) string {
3260+
if !table.IsStdoutTTY() {
3261+
return url
3262+
}
32593263
if len(url) <= maxLen {
32603264
return url
32613265
}

pkg/table/table.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package table
22

33
import (
4+
"os"
45
"strings"
56
"unicode/utf8"
67

78
"github.com/pterm/pterm"
9+
"golang.org/x/term"
810
)
911

1012
// PrintTableNoPad renders a table similar to pterm.DefaultTable, but it avoids
@@ -17,12 +19,15 @@ func PrintTableNoPad(data pterm.TableData, hasHeader bool) {
1719
return
1820
}
1921

20-
// Get terminal width and truncate data to fit
21-
termWidth := pterm.GetTerminalWidth()
22-
if termWidth <= 0 {
23-
termWidth = 80 // fallback
22+
// Only truncate columns when outputting to a terminal.
23+
// When piped (non-TTY), output full values so grep/awk/etc. work correctly.
24+
if term.IsTerminal(int(os.Stdout.Fd())) {
25+
termWidth := pterm.GetTerminalWidth()
26+
if termWidth <= 0 {
27+
termWidth = 80 // fallback
28+
}
29+
data = truncateTableData(data, termWidth)
2430
}
25-
data = truncateTableData(data, termWidth)
2631

2732
// Determine number of columns from the first row
2833
numCols := len(data[0])
@@ -90,6 +95,11 @@ func PrintTableNoPad(data pterm.TableData, hasHeader bool) {
9095
pterm.Print(b.String())
9196
}
9297

98+
// IsStdoutTTY reports whether stdout is connected to a terminal.
99+
func IsStdoutTTY() bool {
100+
return term.IsTerminal(int(os.Stdout.Fd()))
101+
}
102+
93103
// truncateTableData intelligently truncates table cells to fit within terminal width
94104
func truncateTableData(data pterm.TableData, termWidth int) pterm.TableData {
95105
if len(data) == 0 {

0 commit comments

Comments
 (0)