Semantic diff
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: correct colWidth calculation to prevent line wrapping in non-interactive mode

+15 -5
+15 -5
main.go
··· 344 344 return hl[idx] 345 345 } 346 346 347 + // termWidth returns the terminal width by querying stdout, stderr, then stdin. 348 + // Falls back to 200 if none of them report a usable size. 349 + func termWidth() int { 350 + for _, fd := range []uintptr{os.Stdout.Fd(), os.Stderr.Fd(), os.Stdin.Fd()} { 351 + if w, _, err := xterm.GetSize(fd); err == nil && w > 0 { 352 + return w 353 + } 354 + } 355 + return 200 356 + } 357 + 347 358 // printDiff renders the diff to stdout without the TUI. 348 359 func printDiff(m model) { 349 - width, _, err := xterm.GetSize(os.Stdout.Fd()) 350 - if err != nil || width < 20 { 351 - width = 200 352 - } 360 + width := termWidth() 353 361 354 362 st := m.styles 355 - colWidth := width / 2 363 + // Row layout: " "(2) + lNum(4) + " "(1) + leftCell + " │ "(3) + rNum(4) + " "(1) + rightCell 364 + // Total visible width = 3 + 2*colWidth, so colWidth = (width-3)/2 to fit exactly. 365 + colWidth := (width - 3) / 2 356 366 if colWidth < 10 { 357 367 colWidth = 10 358 368 }