Fix counting extra lines when lines wrap - #180
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds ChangesLogUpdate line-wrap fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/utils/log-update.ts`:
- Around line 72-75: The clear() method calls this.done() before erasing lines,
but this.done() sets this.prevLines to null, causing the lineCount getter to
return 0 and eraseLines(0) to produce an empty string. Fix this by reordering
the operations in the clear() method: call
this.write(eraseLines(this.lineCount)) before this.done() so that lineCount is
computed while prevLines is still set, ensuring lines are actually erased before
the state is reset.
- Around line 84-91: In the _onData method, the prevLines property is typed as
string | null and initialized as null, but at line 88 where this.prevLines +=
data is executed, if prevLines is still null, the += operator will concatenate
the string "null" to the data, corrupting the buffer. Add a guard to check if
prevLines is null before performing the concatenation—either initialize it to an
empty string if null, or use conditional logic to ensure the assignment only
happens when prevLines is a valid string.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 5242c2be-df6b-4c45-9fab-e8a98633d439
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (2)
package.jsonsrc/utils/log-update.ts
0f1cb60 to
4a335b0
Compare
Previously, extra lines were counted only by the number of line breaks in them, so the number of lines cleared would be incorrect if any lines wrapped. Additionally, prevLineCount could be wrong if the size of the terminal changes between renders. To fix this, the number of lines to clear is calculated immediately before clearing them, and the 'string-width' library is used to determine accurate widths. This is the same library used by 'wrap-ansi', so it should be reliable, and it is not actually a new dependency.
4a335b0 to
4f7d1de
Compare
(note: this PR was originally submitted as #165, but I needed to change the source branch, so I am re-creating it)
Fixes #164
Previously, extra lines were counted only by the number of line breaks in them, so the number of lines cleared would be incorrect if any lines wrapped. Additionally, prevLineCount could be wrong if the size of the terminal changes between renders.
To fix this, the number of lines to clear is calculated immediately before clearing them, and the 'string-width' library is used to determine accurate widths and line counts. This is the same library used by 'wrap-ansi', so it should be reliable, and it is not actually a new dependency.
Summary by CodeRabbit