Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions components/AutoComplete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const React = require("react");
const TextInput = require("ink-text-input").default;
const { Box, Text, useInput } = require("ink");

const AutoComplete = ({valueControl={val, setValue}, baseList, handleSubmit}) => {
const [suggestion, setSuggestion] = React.useState('');
const updateSuggestion = (input) => {
valueControl.setValue(input);
if (input.length > 0) {
const match = baseList.find(w => w.trim().toLowerCase().startsWith(input.toLowerCase()));
setSuggestion(match || "");
} else {
setSuggestion("");
}
};

useInput((input, key) => {
if (key.tab && suggestion) {
valueControl.setValue(suggestion);
setSuggestion("");
}
});

return (
<Box>
<Box>
<TextInput value={valueControl.val} onChange={updateSuggestion} onSubmit={handleSubmit} showCursor={true}/>
</Box>
<Text color="gray">
{suggestion.slice(valueControl.val.length)}
</Text>
</Box>

)
};

module.exports = AutoComplete;
20 changes: 7 additions & 13 deletions components/CheckoutBranch.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const React = require("react");
const importJsx = require("import-jsx");
const { useState } = require("react");
const { render, Box, Text, Newline } = require("ink");
const { Box, Text } = require("ink");
const { execSync } = require("child_process");
const TextInput = require("ink-text-input").default;
const AutoComplete = importJsx("./AutoComplete");
const {defaultColor, accentColor} = require('../styleFile')
//Uses git for-each-ref to display all available branches to checkout to
//Also removes the astrix that displays the current branch you are on
Expand All @@ -14,10 +15,8 @@ const CheckoutBranch = (props) => {
let { refreshTab } = props;

let branches = execSync(
"git for-each-ref --format='%(refname:short)' refs/heads/"
)
.toString()
.split("\n");
"git for-each-ref --format=%(refname:short) refs/heads/"
).toString().split("\n");

const checkoutBranch = (query) => {
if (branches.includes(query)) {
Expand All @@ -43,18 +42,13 @@ const CheckoutBranch = (props) => {
</Box>
<Box>
<Text color={accentColor}> Branches: </Text>
<Text color={defaultColor}>{branches.join(" ")}</Text>
<Text color={defaultColor}>{branches.join(" | ")}</Text>
</Box>
<Box>
<Box marginRight={1}>
<Text color={accentColor}> Checkout branch:</Text>
<AutoComplete valueControl={{val: query, setValue: setQuery}} baseList={branches} handleSubmit={checkoutBranch} />
</Box>
<TextInput
color={defaultColor}
value={query}
onChange={setQuery}
onSubmit={checkoutBranch}
/>
</Box>
<Box marginLeft={1}>
<Text color="grey">Press ESC to go back</Text>
Expand Down
9 changes: 5 additions & 4 deletions components/DeleteBranch.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const React = require("react");
const importJsx = require("import-jsx");
const { useState } = require("react");
const { render, Box, Text, Newline } = require("ink");
const { Box, Text, Newline } = require("ink");
const { execSync } = require("child_process");
const TextInput = require("ink-text-input").default;
const AutoComplete = importJsx("./AutoComplete");

const DeleteTab = (props) => {
//Uses git branch and displays all local branches
Expand All @@ -28,12 +29,12 @@ const DeleteTab = (props) => {
</Box>
<Box>
<Text color="red"> Branches: </Text>
<Text>{branches.join(" ")}</Text>
<Text>{branches.join(" | ")}</Text>
</Box>
<Box>
<Box>
<Text color="red"> Delete Branch: </Text>
<TextInput value={del} onChange={setDelete} onSubmit={handleSubmit} />
<AutoComplete valueControl={{val: del, setValue: setDelete}} baseList={branches} handleSubmit={handleSubmit} />
</Box>
</Box>
<Newline />
Expand Down