Skip to content

Commit

Permalink
Merge pull request #259 from mizdra/support-pager-for-windows
Browse files Browse the repository at this point in the history
Fix problem with printing lint results using pager in windows
  • Loading branch information
mizdra authored Feb 4, 2023
2 parents a215d05 + 0984804 commit 147b2c0
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 21 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
"estraverse": "^5.3.0",
"find-cache-dir": "^4.0.0",
"is-installed-globally": "^0.4.0",
"node-pager": "^0.3.6",
"ora": "^6.1.2",
"table": "^6.8.1",
"terminal-link": "^3.0.0",
Expand Down
26 changes: 11 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/action/print-result-details.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Remote } from 'comlink';
import { ESLint } from 'eslint';
import pager from 'node-pager';
import { pager } from '../cli/pager.js';
import { promptToInputDisplayMode } from '../cli/prompt.js';
import { SerializableCore } from '../core-worker.js';

Expand Down
34 changes: 34 additions & 0 deletions src/cli/pager.ts
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;
}
}
4 changes: 0 additions & 4 deletions src/typings/node-pager.d.ts

This file was deleted.

0 comments on commit 147b2c0

Please sign in to comment.