fix: handle zero terminal cell height#1184
Conversation
floatpanebot
left a comment
There was a problem hiding this comment.
Hi @Haroka-74! Please fix the following issues with your PR:
- Title: Is too long (56 characters). The PR title must be strictly under 40 characters.
floatpanebot
left a comment
There was a problem hiding this comment.
Hi @Haroka-74! Please fix the following issues with your PR:
- Title: Is too long (43 characters). The PR title must be strictly under 40 characters.
Formatting issues have been resolved. Thank you!
|
@Haroka-74, actually, found a piece of code func getTerminalCellSize() int {
const defaultCellHeight = 18
// Try stdout, stdin, stderr, then /dev/tty as last resort
fds := []int{int(os.Stdout.Fd()), int(os.Stdin.Fd()), int(os.Stderr.Fd())}
for _, fd := range fds {
if cellHeight := getCellHeightFromFd(fd); cellHeight > 0 {
return cellHeight
}
}
// Try /dev/tty directly - this works even when stdio is redirected (e.g., in Bubble Tea)
if tty, err := os.Open("/dev/tty"); err == nil {
defer tty.Close()
if cellHeight := getCellHeightFromFd(int(tty.Fd())); cellHeight > 0 {
return cellHeight
}
}
debugImageProtocol("using default cell height: %d pixels", defaultCellHeight)
return defaultCellHeight
}
where we do have a fallback value. @andrinoff will have to check this out later, he is extremely busy right now, so no promises |
|
Good point, I didn’t notice |
this might still be a good fix, if it is determined that we can find a |
andrinoff
left a comment
There was a problem hiding this comment.
Good fallback in case the system says the cellHeight = 0.
lgtm
|
/approve |
floatpanebot
left a comment
There was a problem hiding this comment.
Approved on behalf of @andrinoff via /approve command.
What?
Added a check for
cellHeight == 0in theimageRowsfunction withinview/html.go. If the terminal height cannot be determined, it now defaults to a standard16pxfallback.Why?
When running in terminals that don't report cell size via
ioctl,getTerminalCellSize()returns0. This previously caused a "division by zero" runtime panic during the row calculation for inline images:(h + cellHeight - 1) / cellHeight.Closes #865