Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite in Ink #83

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
053d862
Migrate to ink
jopemachine Mar 9, 2022
e53e264
Fix lint
jopemachine Mar 9, 2022
bfe7e95
Update test.js
jopemachine Mar 9, 2022
e50a231
Update main.yml
jopemachine Mar 9, 2022
f192e63
Update package.json
jopemachine Mar 9, 2022
5c3ee92
Update interactive.js
jopemachine Mar 9, 2022
63917ba
Remove mistyped whitespace
jopemachine Mar 9, 2022
833f600
Insert whitespace
jopemachine Mar 9, 2022
7c4f000
Update interactive.js
jopemachine Mar 9, 2022
5896fd9
modal -> dialog
jopemachine Mar 9, 2022
1c43f0f
Update cli.js
jopemachine Mar 9, 2022
c91b50c
[WIP] Reflect feedbacks
jopemachine May 2, 2022
2b6a06c
Fix test
jopemachine May 2, 2022
bd867b1
Use named color
jopemachine May 2, 2022
6e9c91a
Use rawMode to resolve CI issue, replace esc-exit with ink's API
jopemachine May 2, 2022
f21d0be
Remove rawMode
jopemachine May 2, 2022
062aae8
Show help message only first launch
jopemachine Nov 20, 2022
faa89a9
Copy `ink-text-input`' s TextInput
jopemachine Nov 21, 2022
b157fd6
Patch `ink-text-input`' s TextInput
jopemachine Nov 21, 2022
2ecaab0
Refactoring source code directory
jopemachine Nov 21, 2022
d8a0abc
Copy and paste `ink-select-input` and parts of its libs
jopemachine Nov 21, 2022
95490e0
Fix array concat bug
jopemachine Nov 21, 2022
70614d5
Fix a broken test
jopemachine Nov 21, 2022
55a138b
Add port filtering feature back
jopemachine Nov 21, 2022
10764b6
Fix backspace and delete key bug
jopemachine Nov 21, 2022
3592f64
Implement port searching correctly
jopemachine Nov 23, 2022
8ce96be
Add pid to FuzzySearch's keys
jopemachine Nov 23, 2022
7e5c249
Rename function
jopemachine Nov 23, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm run build
jopemachine marked this conversation as resolved.
Show resolved Hide resolved
- run: npm test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
yarn.lock
dist/**
jopemachine marked this conversation as resolved.
Show resolved Hide resolved
39 changes: 35 additions & 4 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#!/usr/bin/env node
import process from 'node:process';
import React from 'react';
import meow from 'meow';
import fkill from 'fkill';
import {render} from 'ink';
import {listAllProcesses} from './utils.js';
jopemachine marked this conversation as resolved.
Show resolved Hide resolved
import {InteractiveUI} from './interactive.js';
import {Dialog} from './dialog.js';

const cli = meow(`
Usage
Expand Down Expand Up @@ -52,8 +57,9 @@ const cli = meow(`

(async () => {
if (cli.input.length === 0) {
// eslint-disable-next-line node/no-unsupported-features/es-syntax
(await import('./interactive.js')).init(cli.flags);
const processes = await listAllProcesses();
const app = render(<InteractiveUI processes={processes} flags={cli.flags}/>);
await app.waitUntilExit();
} else {
const forceAfterTimeout = cli.flags.forceAfterTimeout === undefined ? undefined : cli.flags.forceAfterTimeout * 1000;
const promise = fkill(cli.input, {...cli.flags, forceAfterTimeout, ignoreCase: true});
Expand All @@ -71,8 +77,33 @@ const cli = meow(`
process.exit(1);
}

// eslint-disable-next-line node/no-unsupported-features/es-syntax
(await import('./interactive.js')).handleFkillError(cli.input);
const modalSelectHandler = async answer => {
const processes = cli.input;
const suffix = processes.length > 1 ? 'es' : '';

if (process.stdout.isTTY === false) {
console.error(`Error killing process${suffix}. Try \`fkill --force ${processes.join(' ')}\``);
process.exit(1);
}

if (answer === 'Y') {
await fkill(processes, {
force: true,
ignoreCase: true,
});
}

process.exit(0);
};

await render(
<Dialog
opened
inputPlaceholder="(Y/n)"
message="Error killing process. Would you like to use the force? "
selectHandler={modalSelectHandler}
/>,
).waitUntilExit();
}
}
}
Expand Down
32 changes: 32 additions & 0 deletions dialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {createRequire} from 'node:module';
import React, {useState} from 'react';
import {Box, Text} from 'ink';

const require = createRequire(import.meta.url);
const TextInput = require('ink-text-input').default;

const Dialog = ({opened, inputPlaceholder, message, selectHandler}) => {
const [query, setQuery] = useState('');

if (!opened) {
return null;
}

return (
<Box marginTop={1} marginRight={1}>
<Text bold>
<Text color="green">{'? '}</Text>
<Text>{message}</Text>
</Text>

<TextInput
value={query}
placeholder={inputPlaceholder}
onChange={setQuery}
onSubmit={() => selectHandler(query)}
/>
</Box>
);
};

export {Dialog};