Skip to content

curses window reads are capped at 2047 and silently truncate longer lines #156230

Description

@serhiy-storchaka

Bug report

window.instr(), in_wstr() and in_wchstr() clamp the count to 2047, so a longer line is cut off with no indication. A pad can be wider than that.

import curses

def check(stdscr):
    pad = curses.newpad(1, 3000)
    pad.addstr(0, 2500, 'X')
    return len(pad.instr(0, 0)), 'X' in pad.instr(0, 0).decode()

print(curses.wrapper(check))     # (2047, False), want (3000, True)

A window read is bounded by the window, so the count only needs to be capped by the columns left on the line, in the unit each method counts: cells for in_wchstr(), characters for in_wstr(), bytes for instr() -- at most CCHARW_MAX characters of MB_CUR_MAX bytes per cell.

The default could then mean the rest of the line, as n < 0 already does inside curses, instead of the arbitrary 2047.

getstr() and get_wstr() read the keyboard rather than the window, so their cap stays.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions