Skip to content

Commit 90de6e4

Browse files
branchseerclaude
andcommitted
refactor(vite_pty): separate read_to_end and screen_contents
- Change read_to_end to return Result<()> instead of Result<String> - Users now call screen_contents() separately to get screen contents - This separates concerns: reading/processing vs retrieving state - Update all tests to use the new API All tests pass on macOS (8/8) and Windows (8/8). Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 4268d09 commit 90de6e4

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

crates/vite_pty/src/terminal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl Terminal {
134134
Ok(())
135135
}
136136

137-
pub fn read_to_end(&mut self) -> anyhow::Result<String> {
137+
pub fn read_to_end(&mut self) -> anyhow::Result<()> {
138138
// `read_to_end` will move cursor to the end, so clear any buffered data for `read_until`
139139
self.read_until_buffer.clear();
140140

@@ -147,7 +147,7 @@ impl Terminal {
147147
break;
148148
}
149149
}
150-
Ok(self.screen_contents())
150+
Ok(())
151151
}
152152

153153
pub fn screen_contents(&self) -> String {

crates/vite_pty/tests/terminal.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ fn is_terminal() {
1717
}));
1818

1919
let mut terminal = Terminal::spawn(ScreenSize { rows: 80, cols: 80 }, cmd).unwrap();
20-
let output = terminal.read_to_end().unwrap();
20+
terminal.read_to_end().unwrap();
21+
let output = terminal.screen_contents();
2122
assert_eq!(output.trim(), "true true true");
2223
}
2324

@@ -30,7 +31,8 @@ fn read_until_single() {
3031

3132
let mut terminal = Terminal::spawn(ScreenSize { rows: 80, cols: 80 }, cmd).unwrap();
3233
terminal.read_until("hello").unwrap();
33-
let output = terminal.read_to_end().unwrap();
34+
terminal.read_to_end().unwrap();
35+
let output = terminal.screen_contents();
3436
// After reading until "hello", the buffer should contain " world"
3537
// read_to_end should process the buffered data and continue reading
3638
assert!(output.contains("world"));
@@ -49,7 +51,8 @@ fn read_until_multiple_sequential() {
4951
terminal.read_until("first").unwrap();
5052
terminal.read_until("second").unwrap();
5153
terminal.read_until("third").unwrap();
52-
let output = terminal.read_to_end().unwrap();
54+
terminal.read_to_end().unwrap();
55+
let output = terminal.screen_contents();
5356
// All three words should be in the screen
5457
assert!(output.contains("first"));
5558
assert!(output.contains("second"));
@@ -83,7 +86,8 @@ fn read_until_with_read_to_end() {
8386
let mut terminal = Terminal::spawn(ScreenSize { rows: 80, cols: 80 }, cmd).unwrap();
8487
terminal.read_until("middle").unwrap();
8588
// At this point, " suffix" should be buffered
86-
let output = terminal.read_to_end().unwrap();
89+
terminal.read_to_end().unwrap();
90+
let output = terminal.screen_contents();
8791
// The full output should include everything
8892
assert!(output.contains("prefix"));
8993
assert!(output.contains("middle"));
@@ -118,7 +122,8 @@ fn read_until_boundary_spanning() {
118122
let mut terminal = Terminal::spawn(ScreenSize { rows: 80, cols: 80 }, cmd).unwrap();
119123
// Search for a pattern that's likely to span boundaries
120124
terminal.read_until("abcd").unwrap();
121-
let output = terminal.read_to_end().unwrap();
125+
terminal.read_to_end().unwrap();
126+
let output = terminal.screen_contents();
122127
assert!(output.contains("abcdef"));
123128
}
124129

@@ -137,7 +142,8 @@ fn read_until_exact_boundary() {
137142
let mut terminal = Terminal::spawn(ScreenSize { rows: 80, cols: 80 }, cmd).unwrap();
138143
// This should find "second" even if "first" was in a previous read
139144
terminal.read_until("second").unwrap();
140-
let output = terminal.read_to_end().unwrap();
145+
terminal.read_to_end().unwrap();
146+
let output = terminal.screen_contents();
141147
assert!(output.contains("first"));
142148
assert!(output.contains("second"));
143149
}
@@ -156,7 +162,8 @@ fn read_until_after_read_to_end() {
156162
terminal.read_until("world").unwrap();
157163

158164
// Read everything else
159-
let output = terminal.read_to_end().unwrap();
165+
terminal.read_to_end().unwrap();
166+
let output = terminal.screen_contents();
160167
assert!(output.contains("hello world foo bar"));
161168

162169
// After read_to_end, buffer is empty and we're at EOF

0 commit comments

Comments
 (0)