forked from marszall87/lambda-pure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtexts.tsx
180 lines (161 loc) · 3.93 KB
/
texts.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import { relative } from "node:path";
import packageJson from "@/package.json";
import { Newline, Text } from "ink";
import Spinner from "ink-spinner";
import {
type ComponentProps,
type PropsWithChildren,
type ReactNode,
memo,
} from "react";
export const convertToRelativePathFromHome = ({ to }: { to: string }) => {
const pathFromHome = relative(process.env.HOME ?? "~", to);
return `~/${pathFromHome}`;
};
export const NormalText = memo(({ children }: PropsWithChildren) => (
<Text color="white">{children}</Text>
));
export const Highlight = memo(
({
children,
on = true,
}: PropsWithChildren<{
on?: boolean;
}>) => <Text color={on ? "white" : "gray"}>{children}</Text>,
);
export const BoldHighlight = memo(
({
children,
on = true,
}: PropsWithChildren<{
on?: boolean;
}>) => (
<Text bold={on} color={on ? "white" : "gray"}>
{children}
</Text>
),
);
export const SuggestionText = memo(({ children }: PropsWithChildren) => (
<Text bold>{children}</Text>
));
export const TmiText = memo(({ children }: PropsWithChildren) => (
<Text color="gray">{children}</Text>
));
export const NoticeText = memo(({ children }: PropsWithChildren) => (
<Text bold color="yellow">
{children}
</Text>
));
export const SymbolText = memo(({ children }: PropsWithChildren) => (
<Text color="magentaBright">{children}</Text>
));
export const FilenameText = memo(({ children }: PropsWithChildren) => (
<Text color="green">{children}</Text>
));
export const LinkText = memo(({ children }: PropsWithChildren) => (
<Text color="blueBright">{children}</Text>
));
export const CodeText = memo(({ children }: PropsWithChildren) => (
<Text color="cyan">{children}</Text>
));
export const TerminationText = memo(() => (
<Text>
<Newline />
<Newline />
<Text bold color="whiteBright">
Terminating the program...
</Text>
<Newline />
</Text>
));
export const ErrorText = memo(({ error }: { error: Error | ReactNode }) => (
<Text>
<Newline />
<Text color="red">
Failed. Error details↓
<Newline />
{error instanceof Error ? error.message : error}
</Text>
<Newline />
</Text>
));
export const FailedTextWithSudoSuggestion = memo(
({ error }: ComponentProps<typeof ErrorText>) => (
<Text>
<ErrorText error={error} />
<SuggestionText>
This is mostly caused by permission. Try:{" "}
<CodeText>sudo {packageJson.name}</CodeText>
</SuggestionText>
<TerminationText />
</Text>
),
);
export const FailedTextWith3rdPartyLink = memo(
({
appLookUpPath,
appName,
error,
link,
}: ComponentProps<typeof ErrorText> & {
appLookUpPath: ReactNode;
appName: ReactNode;
link: ReactNode;
}) => (
<Text>
<ErrorText error={error} />
Couldn't find <SymbolText>{appName}</SymbolText> at{" "}
<FilenameText>{appLookUpPath}</FilenameText>.
<Newline />
<SuggestionText>
Try it again after installing it first: <LinkText>{link}</LinkText>
</SuggestionText>
<TerminationText />
</Text>
),
);
export const FailedTextWithManualConfigSuggestion = memo(
({
config,
error,
filename,
}: ComponentProps<typeof ErrorText> & {
config: ReactNode;
filename: ReactNode;
}) => (
<Text>
<ErrorText error={error} />
<SuggestionText>
Try to manually put the following config in{" "}
<SymbolText>{filename}</SymbolText>:<Newline />
<CodeText>{config}</CodeText>
</SuggestionText>
<TerminationText />
</Text>
),
);
export const ProgressIndicator = memo(
({
isError,
isLoading,
isSuccess,
}: { isError: boolean; isLoading: boolean; isSuccess: boolean }) => (
<Text color="green">
{isError ? "❌" : isSuccess ? "✔︎" : isLoading ? <Spinner /> : null}{" "}
</Text>
),
);
export const SelectText = memo(
({
label,
on,
value,
}: { label: ReactNode; on: boolean; value: ReactNode }) => (
<Text>
<Text color="green">{value ? "✔︎" : "?"} </Text>
<BoldHighlight on={on}>{label}</BoldHighlight>
<Text dimColor> › </Text>
<Text>{value}</Text>
</Text>
),
);