mirror of
https://github.com/wavetermdev/inshellisense.git
synced 2026-08-05 13:43:30 -07:00
feat: ask for desired shell if no args (#43)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
import { initRender } from "../ui/ui-init.js";
|
||||
import { render } from "../ui/ui-root.js";
|
||||
import { executeShellCommandTTY, ExecuteShellCommandTTYResult } from "../runtime/utils.js";
|
||||
import { saveCommand, loadCommand } from "../utils/cache.js";
|
||||
@@ -21,7 +22,7 @@ export const action = async (options: RootCommandOptions) => {
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const shell = options.shell ?? "";
|
||||
const shell = options.shell ?? (await initRender()) ?? "";
|
||||
if (!shells.map((s) => s.valueOf()).includes(shell)) {
|
||||
console.error(`Unsupported shell: '${shell}', supported shells: ${supportedShells}`);
|
||||
process.exit(1);
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
import React, { useState } from "react";
|
||||
import { Box, Text, render, useApp, useInput } from "ink";
|
||||
|
||||
import { supportedShells } from "../utils/bindings.js";
|
||||
|
||||
let uiResult = undefined;
|
||||
|
||||
function UI() {
|
||||
const { exit } = useApp();
|
||||
const [selectionIdx, setSelectionIdx] = useState(0);
|
||||
const [exited, setExited] = useState(false);
|
||||
|
||||
useInput(async (_, key) => {
|
||||
if (key.upArrow) {
|
||||
setSelectionIdx(Math.max(0, selectionIdx - 1));
|
||||
} else if (key.downArrow) {
|
||||
setSelectionIdx(Math.min(supportedShells.length - 1, selectionIdx + 1));
|
||||
} else if (key.return) {
|
||||
uiResult = supportedShells[selectionIdx];
|
||||
setExited(true);
|
||||
setTimeout(exit, 0);
|
||||
}
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
{exited ? null : (
|
||||
<Box flexDirection="column">
|
||||
<Box>
|
||||
<Text bold>Select your desired shell</Text>
|
||||
</Box>
|
||||
<Box flexDirection="column">
|
||||
{supportedShells.map((shell, idx) => {
|
||||
if (idx == selectionIdx) {
|
||||
return (
|
||||
<Text color="cyan" underline key={idx}>
|
||||
{">"} {shell}
|
||||
</Text>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<Text key={idx}>
|
||||
{" "}
|
||||
{shell}
|
||||
</Text>
|
||||
);
|
||||
})}
|
||||
</Box>
|
||||
</Box>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export const initRender = async (): Promise<string | undefined> => {
|
||||
uiResult = undefined;
|
||||
const { waitUntilExit } = render(<UI />);
|
||||
await waitUntilExit();
|
||||
|
||||
return uiResult;
|
||||
};
|
||||
Reference in New Issue
Block a user