-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #259 from mizdra/support-pager-for-windows
Fix problem with printing lint results using pager in windows
- Loading branch information
Showing
5 changed files
with
46 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { spawnSync } from 'child_process'; | ||
import { writeFile } from 'fs/promises'; | ||
import { join } from 'path'; | ||
import { getCacheDir } from '../util/cache.js'; | ||
|
||
const PAGER_CONTENT_FILE_PATH = join(getCacheDir(), 'pager-content.txt'); | ||
|
||
export async function pager(content: string): Promise<void> { | ||
if (process.platform == 'win32') { | ||
return pagerForWindows(content); | ||
} else { | ||
return pagerForPOSIX(content); | ||
} | ||
} | ||
|
||
async function pagerForWindows(content: string): Promise<void> { | ||
await writeFile(PAGER_CONTENT_FILE_PATH, content, 'utf-8'); | ||
try { | ||
spawnSync('more', [PAGER_CONTENT_FILE_PATH], { shell: true, stdio: 'inherit' }); | ||
} catch (e) { | ||
console.error('Failed to execute `more` command. Please install `more` command.'); | ||
throw e; | ||
} | ||
} | ||
|
||
async function pagerForPOSIX(content: string): Promise<void> { | ||
await writeFile(PAGER_CONTENT_FILE_PATH, content, 'utf-8'); | ||
try { | ||
spawnSync('less', ['-R', PAGER_CONTENT_FILE_PATH], { shell: true, stdio: 'inherit' }); | ||
} catch (e) { | ||
console.error('Failed to execute `less` command. Please install `less` command.'); | ||
throw e; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.