@@ -33,7 +33,7 @@ function stripTerminalControl(text: string) {
3333 . replace ( / \x1b [ @ - _ ] / g, "" ) ;
3434}
3535
36- function createFixtureFiles ( ) {
36+ function createFixtureFiles ( lines = 1 ) {
3737 const dir = mkdtempSync ( join ( tmpdir ( ) , "hunk-tty-smoke-" ) ) ;
3838 tempDirs . push ( dir ) ;
3939
@@ -43,8 +43,21 @@ function createFixtureFiles() {
4343 const patch = join ( dir , "input.patch" ) ;
4444 const coloredPatch = join ( dir , "input-colored.patch" ) ;
4545
46- writeFileSync ( before , "export const answer = 41;\n" ) ;
47- writeFileSync ( after , "export const answer = 42;\nexport const added = true;\n" ) ;
46+ if ( lines <= 1 ) {
47+ writeFileSync ( before , "export const answer = 41;\n" ) ;
48+ writeFileSync ( after , "export const answer = 42;\nexport const added = true;\n" ) ;
49+ } else {
50+ writeFileSync (
51+ before ,
52+ Array . from ( { length : lines } , ( _ , index ) => `export const before_${ String ( index + 1 ) . padStart ( 2 , "0" ) } = ${ index + 1 } ;` ) . join ( "\n" ) +
53+ "\n" ,
54+ ) ;
55+ writeFileSync (
56+ after ,
57+ Array . from ( { length : lines } , ( _ , index ) => `export const after_${ String ( index + 1 ) . padStart ( 2 , "0" ) } = ${ index + 101 } ;` ) . join ( "\n" ) +
58+ "\n" ,
59+ ) ;
60+ }
4861 writeFileSync (
4962 agent ,
5063 JSON . stringify ( {
@@ -124,12 +137,13 @@ async function runTtySmoke(options: { mode?: "split" | "stack"; pager?: boolean;
124137 return stripTerminalControl ( await Bun . file ( transcript ) . text ( ) ) ;
125138}
126139
127- async function runStdinPagerSmoke ( ) {
128- const fixture = createFixtureFiles ( ) ;
140+ async function runStdinPagerSmoke ( options ?: { input ?: string ; inputCommand ?: string ; lines ?: number } ) {
141+ const fixture = createFixtureFiles ( options ?. lines ?? 1 ) ;
129142 const transcript = join ( fixture . dir , "stdin-pager-transcript.txt" ) ;
130143 const patchCommand = `cat ${ shellQuote ( fixture . coloredPatch ) } | bun run src/main.tsx patch -` ;
131144 const scriptCommand = `timeout 5 script -q -f -e -c ${ shellQuote ( patchCommand ) } ${ shellQuote ( transcript ) } ` ;
132- const proc = Bun . spawnSync ( [ "bash" , "-lc" , `(sleep 1; printf q) | ${ scriptCommand } ` ] , {
145+ const inputCommand = options ?. inputCommand ?? `(sleep 1; printf ${ shellQuote ( options ?. input ?? "q" ) } )` ;
146+ const proc = Bun . spawnSync ( [ "bash" , "-lc" , `${ inputCommand } | ${ scriptCommand } ` ] , {
133147 cwd : process . cwd ( ) ,
134148 stdin : "ignore" ,
135149 stdout : "pipe" ,
@@ -207,4 +221,18 @@ describe("TTY render smoke", () => {
207221 expect ( output ) . toContain ( "@@ -1 +1,2 @@" ) ;
208222 expect ( output ) . toContain ( "export const answer = 42;" ) ;
209223 } ) ;
224+
225+ test ( "stdin pager mode pages forward by a full viewport on space" , async ( ) => {
226+ if ( ! ttyToolsAvailable ) {
227+ return ;
228+ }
229+
230+ const output = await runStdinPagerSmoke ( {
231+ lines : 40 ,
232+ inputCommand : `(sleep 1; printf ' '; sleep 1; printf q)` ,
233+ } ) ;
234+
235+ expect ( output ) . toContain ( "before_23" ) ;
236+ expect ( output ) . toContain ( "after_06" ) ;
237+ } ) ;
210238} ) ;
0 commit comments