Skip to content

Commit

Permalink
refactor: refactor terminal components
Browse files Browse the repository at this point in the history
  • Loading branch information
paradoxuum committed Jul 19, 2024
1 parent 41734e6 commit 337f041
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { ClientAPI } from "@rbxts/centurion";
import { UserInputService } from "@rbxts/services";
import { GuiService, UserInputService } from "@rbxts/services";
import Vide, { derive } from "@rbxts/vide";
import Terminal from "../components/terminal";
import { Suggestions, Terminal } from "../components";
import { Group } from "../components/ui/group";
import { Layer } from "../components/ui/layer";
import { useAPI } from "../hooks/use-api";
import { useAtom } from "../hooks/use-atom";
import { useEvent } from "../hooks/use-event";
import { usePx } from "../hooks/use-px";
import { px, usePx } from "../hooks/use-px";
import {
interfaceOptions,
interfaceVisible,
Expand All @@ -19,7 +20,7 @@ const MOUSE_INPUT_TYPES = new Set<Enum.UserInputType>([
Enum.UserInputType.Touch,
]);

export function TerminalApp(api: ClientAPI) {
export function CenturionApp(api: ClientAPI) {
useAPI(api);
usePx();

Expand All @@ -42,7 +43,19 @@ export function TerminalApp(api: ClientAPI) {

return (
<Layer displayOrder={() => options().displayOrder ?? 0} visible={visible}>
<Terminal />
<Group
anchorPoint={() => options().anchorPoint ?? new Vector2(0, 0)}
size={() => options().size ?? new UDim2(0, px(1024), 1, 0)}
position={() =>
options().position ??
UDim2.fromOffset(px(16), px(8) + GuiService.GetGuiInset()[0].Y)
}
>
<Terminal />
<Suggestions />

<uilistlayout Padding={new UDim(0, px(8))} SortOrder={"LayoutOrder"} />
</Group>
</Layer>
);
}
4 changes: 2 additions & 2 deletions packages/ui/src/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ContentProvider, Players } from "@rbxts/services";
import { mount } from "@rbxts/vide";
import { DEFAULT_INTERFACE_OPTIONS } from "../constants/options";
import { InterfaceOptions } from "../types";
import { TerminalApp } from "./terminal-app";
import { CenturionApp } from "./centurion-app";

export namespace CenturionUI {
const MAX_PRELOAD_ATTEMPTS = 3;
Expand Down Expand Up @@ -40,7 +40,7 @@ export namespace CenturionUI {
});

const target = Players.LocalPlayer.WaitForChild("PlayerGui");
mount(() => TerminalApp(api), target);
mount(() => CenturionApp(api), target);
};
}
}
1 change: 1 addition & 0 deletions packages/ui/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./suggestions";
export * from "./terminal";
28 changes: 0 additions & 28 deletions packages/ui/src/components/terminal.tsx

This file was deleted.

1 change: 1 addition & 0 deletions packages/ui/src/components/terminal/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./terminal";
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import {
import { subscribe } from "@rbxts/charm";
import { UserInputService } from "@rbxts/services";
import Vide, { Derivable, effect, source } from "@rbxts/vide";
import { getAPI } from "../hooks/use-api";
import { useAtom } from "../hooks/use-atom";
import { useEvent } from "../hooks/use-event";
import { px } from "../hooks/use-px";
import { getAPI } from "../../hooks/use-api";
import { useAtom } from "../../hooks/use-atom";
import { useEvent } from "../../hooks/use-event";
import { px } from "../../hooks/use-px";
import {
commandHistory,
commandHistoryIndex,
Expand All @@ -20,12 +20,12 @@ import {
terminalText,
terminalTextParts,
terminalTextValid,
} from "../store";
import { getArgumentNames } from "../util/argument";
import { Frame } from "./ui/frame";
import { Padding } from "./ui/padding";
import { Text } from "./ui/text";
import { TextField } from "./ui/text-field";
} from "../../store";
import { getArgumentNames } from "../../util/argument";
import { Frame } from "../ui/frame";
import { Padding } from "../ui/padding";
import { Text } from "../ui/text";
import { TextField } from "../ui/text-field";

interface TerminalTextFieldProps {
anchorPoint?: Derivable<Vector2>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {
formatPartsAsPath,
} from "@rbxts/centurion/out/shared/util/string";
import Vide, { effect, source } from "@rbxts/vide";
import { HISTORY_TEXT_SIZE } from "../constants/text";
import { getAPI } from "../hooks/use-api";
import { useAtom } from "../hooks/use-atom";
import { useHistory } from "../hooks/use-history";
import { useMotion } from "../hooks/use-motion";
import { px } from "../hooks/use-px";
import { HISTORY_TEXT_SIZE } from "../../constants/text";
import { getAPI } from "../../hooks/use-api";
import { useAtom } from "../../hooks/use-atom";
import { useHistory } from "../../hooks/use-history";
import { useMotion } from "../../hooks/use-motion";
import { px } from "../../hooks/use-px";
import {
currentArgIndex,
currentCommandPath,
Expand All @@ -20,22 +20,22 @@ import {
terminalText,
terminalTextParts,
terminalTextValid,
} from "../store";
import { Suggestion } from "../types";
import { getMissingArgs } from "../util/argument";
} from "../../store";
import { Suggestion } from "../../types";
import { getMissingArgs } from "../../util/argument";
import {
getArgumentSuggestion,
getCommandSuggestion,
} from "../util/suggestion";
import { HistoryList } from "./history";
} from "../../util/suggestion";
import { HistoryList } from "../history";
import { Frame } from "../ui/frame";
import { Padding } from "../ui/padding";
import { TerminalTextField } from "./terminal-text-field";
import { Frame } from "./ui/frame";
import { Padding } from "./ui/padding";

const MAX_HEIGHT = HISTORY_TEXT_SIZE * 10;
const TEXT_FIELD_HEIGHT = 40;

export function TerminalWindow() {
export function Terminal() {
const api = getAPI();
const options = useAtom(interfaceOptions);
const missingArgs = source<string[]>([]);
Expand Down

0 comments on commit 337f041

Please sign in to comment.