Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@XY0797
Copy link
Contributor

@XY0797 XY0797 commented Jan 23, 2025

Fix Explanation

This logic is divided into two phases:

Data Acquisition Phase --> Data Output Phase

The idea is:

In the Data Acquisition Phase

If the data in read_buf is sufficient, there is no need to fetch additional data from reader_out_rx, and the data of the size specified by the user can be directly returned from read_buf. Therefore, the acquisition phase returns an empty string.

If the data in read_buf is insufficient, additional data should be fetched from reader_out_rx. Therefore, the acquisition phase returns the data taken from reader_out_rx.

If reader_out_rx returns None, an empty string can be returned first, delaying the throwing of the Standard out reached EOF exception to the Data Output Phase.

In the Data Output Phase

Merge the data returned from the Data Acquisition Phase into read_buf, and return as much data as possible based on the user's request, without exceeding the size specified by the user.

Before returning the data, if it is found that:

  1. The length of data requested by the user is not 0
  2. The returned string is empty
  3. During the execution of this request, reader_out_rx has returned None (indicating that the current state is EOF)

Then throw the Standard out reached EOF exception.

Otherwise, return the prepared data.

Other Notes

I am not familiar with the Rust language, having only seen Rust code for the first time three days ago. I can only understand Rust code with the help of GPT. Therefore, my modifications may have issues, and I hope you can review and test them in detail.

@XY0797 XY0797 changed the title fix: prevent PTY output truncation by correctly handling EOF in cache_thread fix: prevent PTY output truncation by correctly handling EOF in cache_thread (#84) Jan 23, 2025
@XY0797
Copy link
Contributor Author

XY0797 commented Jan 23, 2025

This PR attempts to fix #84

@codecov-commenter
Copy link

codecov-commenter commented Jan 23, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 54.54545% with 5 lines in your changes missing coverage. Please review.

Project coverage is 78.46%. Comparing base (544cfd5) to head (e74f075).

Files with missing lines Patch % Lines
src/pty/base.rs 54.54% 5 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #85      +/-   ##
==========================================
- Coverage   78.59%   78.46%   -0.14%     
==========================================
  Files           7        7              
  Lines        1308     1314       +6     
==========================================
+ Hits         1028     1031       +3     
- Misses        280      283       +3     
Flag Coverage Δ
unittests 78.46% <54.54%> (-0.14%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants