terminal: scrollback lines longer than 4096 bytes are cut off

Open Beginner friendly
#2,524 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Domain
cli, desktop-dev

Research direction

Start with terminal_sb_line_extract in extensions/terminal/terminal.c, where the fixed 4097-byte scrollback buffer truncates long UTF-8 rows. Review how the buffer is sized from the terminal column count, including the proposed cols * 4 * VTERM_MAX_CHARS_PER_CELL + 1 calculation and combining-character handling. Run verify after changing the allocation or bounds logic and confirm that long CJK and emoji rows remain intact in scrollback.

Written by the indexing model from the issue text.

Description

Lines stored in the scrollback of M-x terminal are cut off without a sign once they are longer than 4096 bytes in UTF-8.

terminal_sb_line_extract (extensions/terminal/terminal.c) writes into terminal->sb_line_buf, 4097 bytes, and stops at if (pos + N > max) break; when it is full: the rest of the row is dropped.

To reproduce: a terminal wider than about 1024 columns (a maximized window on a large display with a small font) full of CJK text (3 bytes each) or emoji (4 bytes): only the first 1024 to 1365 glyphs of each row that scrolls off are kept in the history.

Fix: size the buffer from cols (cols * 4 * VTERM_MAX_CHARS_PER_CELL + 1 once combining characters are kept, see the issue on combining characters), or allocate it when cols is larger than the fixed buffer.

Found by the review of #2522 (a pre-existing issue, not changed there).

An agent can fix this and check it with verify.

Dominant language
Common Lisp
Stars
3.1k
Forks
261
Avg merge
1d 1h
Merged PRs (30d)
117

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from lem-project/lem

All issues in lem-project/lem

Similar issues

More CLI issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.