The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { T } from "gt-react-native"; |
| 2 | import { Platform, ScrollView, type StyleProp, type TextStyle, View } from "react-native"; |
| 3 | |
| 4 | import { AppText as Text } from "../../../../components/ui/AppText"; |
| 5 | import { |
| 6 | resolveMarkdownFontSizes, |
| 7 | resolveMobileCodeSurface, |
| 8 | } from "../../../../lib/appearancePreferences"; |
| 9 | import { getMobileTerminalTheme } from "../../../terminal/terminalTheme"; |
| 10 | import { useAppearancePreferences } from "../AppearancePreferencesProvider"; |
| 11 | |
| 12 | const CODE_FONT_FAMILY = Platform.select({ |
| 13 | ios: "ui-monospace", |
| 14 | android: "monospace", |
| 15 | default: "monospace", |
| 16 | }); |
| 17 | |
| 18 | export function AppearancePreviewSeparator() { |
| 19 | return <View className="h-px bg-separator" />; |
| 20 | } |
| 21 | |
| 22 | export function TextAppearancePreview(props: { readonly fontSize: number }) { |
| 23 | const sizes = resolveMarkdownFontSizes(props.fontSize); |
| 24 | |
| 25 | return ( |
| 26 | <View className="gap-1 p-4"> |
| 27 | <Text |
| 28 | className="text-foreground" |
| 29 | style={{ fontSize: sizes.m, lineHeight: sizes.bodyLineHeight }} |
| 30 | > |
| 31 | <T>The quick brown fox jumps over the lazy dog.</T> |
| 32 | </Text> |
| 33 | <Text |
| 34 | className="text-foreground-muted" |
| 35 | style={{ fontSize: sizes.s, lineHeight: Math.round(sizes.s * 1.4) }} |
| 36 | > |
| 37 | <T>Messages, labels, and headings scale with this size.</T> |
| 38 | </Text> |
| 39 | </View> |
| 40 | ); |
| 41 | } |
| 42 | |
| 43 | export function TerminalAppearancePreview(props: { readonly fontSize: number }) { |
| 44 | const { themeAppearance: scheme, themeId } = useAppearancePreferences(); |
| 45 | const theme = getMobileTerminalTheme(themeId, scheme); |
| 46 | const lineHeight = Math.round(props.fontSize * 1.6); |
| 47 | const lineStyle = { |
| 48 | fontFamily: Platform.OS === "android" ? "monospace" : "Menlo", |
| 49 | fontSize: props.fontSize, |
| 50 | lineHeight, |
| 51 | } as const; |
| 52 | const span = (color: string, extra?: TextStyle): StyleProp<TextStyle> => [ |
| 53 | lineStyle, |
| 54 | { color, ...extra }, |
| 55 | ]; |
| 56 | |
| 57 | return ( |
| 58 | <View className="p-4"> |
| 59 | <Text style={span(theme.foreground)}> |
| 60 | <Text style={span(theme.palette[2])}>→ </Text> |
| 61 | <Text style={span(theme.palette[6])}>t3code </Text> |
| 62 | <Text style={span(theme.palette[4])}>git:(</Text> |
| 63 | <Text style={span(theme.palette[1])}>main</Text> |
| 64 | <Text style={span(theme.palette[4])}>)</Text> |
| 65 | <Text style={span(theme.palette[3])}> ✗</Text> |
| 66 | {/* oxlint-disable-next-line t3code/no-untranslated-copy -- sample terminal output */} |
| 67 | <Text style={span(theme.foreground)}> vpr dev</Text> |
| 68 | </Text> |
| 69 | <Text style={span(theme.foreground)}> |
| 70 | {/* oxlint-disable-next-line t3code/no-untranslated-copy -- sample terminal output */} |
| 71 | <Text style={span(theme.palette[2])}>VITE v7.1.1</Text> |
| 72 | {/* oxlint-disable-next-line t3code/no-untranslated-copy -- sample terminal output */} |
| 73 | <Text style={span(theme.mutedForeground)}> ready in</Text> |
| 74 | <Text style={span(theme.foreground)}> 1.24s</Text> |
| 75 | </Text> |
| 76 | <Text style={span(theme.foreground)}> |
| 77 | <Text style={span(theme.palette[2])}>→ </Text> |
| 78 | {/* oxlint-disable-next-line t3code/no-untranslated-copy -- sample terminal output */} |
| 79 | <Text style={span(theme.mutedForeground)}>Local: </Text> |
| 80 | <Text style={span(theme.palette[6], { textDecorationLine: "underline" })}> |
| 81 | http://127.0.0.1:5173/ |
| 82 | </Text> |
| 83 | </Text> |
| 84 | <Text style={span(theme.foreground)}> |
| 85 | {/* oxlint-disable-next-line t3code/no-untranslated-copy -- sample terminal output */} |
| 86 | <Text style={span(theme.palette[2])}>✓ 85 passed</Text> |
| 87 | {/* oxlint-disable-next-line t3code/no-untranslated-copy -- sample terminal output */} |
| 88 | <Text style={span(theme.palette[3])}> △ 2 warnings</Text> |
| 89 | {/* oxlint-disable-next-line t3code/no-untranslated-copy -- sample terminal output */} |
| 90 | <Text style={span(theme.palette[1])}> ✗ 0 failed</Text> |
| 91 | </Text> |
| 92 | <Text style={span(theme.foreground)}> |
| 93 | <Text style={span(theme.background, { backgroundColor: theme.palette[2] })}> |
| 94 | {" READY "} |
| 95 | </Text> |
| 96 | {/* oxlint-disable-next-line t3code/no-untranslated-copy -- sample terminal output */} |
| 97 | <Text style={span(theme.mutedForeground)}> watching for changes</Text>{" "} |
| 98 | <Text style={span(theme.cursorForeground)}>▏</Text> |
| 99 | </Text> |
| 100 | </View> |
| 101 | ); |
| 102 | } |
| 103 | |
| 104 | interface CodePreviewToken { |
| 105 | readonly text: string; |
| 106 | readonly keyword?: boolean; |
| 107 | } |
| 108 | |
| 109 | interface CodePreviewLine { |
| 110 | readonly id: string; |
| 111 | readonly tokens: ReadonlyArray<CodePreviewToken>; |
| 112 | } |
| 113 | |
| 114 | const CODE_PREVIEW_LINES: ReadonlyArray<CodePreviewLine> = [ |
| 115 | { |
| 116 | id: "signature", |
| 117 | // oxlint-disable-next-line t3code/no-untranslated-copy -- sample code |
| 118 | tokens: [{ text: "function", keyword: true }, { text: " formatUser(user) {" }], |
| 119 | }, |
| 120 | { |
| 121 | id: "body", |
| 122 | tokens: [ |
| 123 | { text: " " }, |
| 124 | { text: "return", keyword: true }, |
| 125 | // oxlint-disable-next-line t3code/no-untranslated-copy -- sample code |
| 126 | { text: " `${user.name} <${user.email}>` // demonstrates how long lines behave" }, |
| 127 | ], |
| 128 | }, |
| 129 | { id: "close", tokens: [{ text: "}" }] }, |
| 130 | ]; |
| 131 | |
| 132 | export function CodeAppearancePreview(props: { |
| 133 | readonly fontSize: number; |
| 134 | readonly wordBreak: boolean; |
| 135 | }) { |
| 136 | const surface = resolveMobileCodeSurface(props.fontSize); |
| 137 | |
| 138 | const lineNumber = (line: CodePreviewLine, index: number) => ( |
| 139 | <Text |
| 140 | className="text-right text-icon-subtle" |
| 141 | key={line.id} |
| 142 | style={{ |
| 143 | fontFamily: CODE_FONT_FAMILY, |
| 144 | fontSize: surface.lineNumberFontSize, |
| 145 | lineHeight: surface.rowHeight, |
| 146 | width: 22, |
| 147 | }} |
| 148 | > |
| 149 | {index + 1} |
| 150 | </Text> |
| 151 | ); |
| 152 | |
| 153 | const codeLine = (line: CodePreviewLine, wrap: boolean) => ( |
| 154 | <Text |
| 155 | className="text-foreground" |
| 156 | key={line.id} |
| 157 | numberOfLines={wrap ? undefined : 1} |
| 158 | style={{ |
| 159 | fontFamily: CODE_FONT_FAMILY, |
| 160 | fontSize: surface.fontSize, |
| 161 | lineHeight: surface.rowHeight, |
| 162 | }} |
| 163 | > |
| 164 | {line.tokens.map((token) => ( |
| 165 | <Text |
| 166 | key={token.text} |
| 167 | className={token.keyword ? "text-md-link" : undefined} |
| 168 | style={{ |
| 169 | fontFamily: CODE_FONT_FAMILY, |
| 170 | fontSize: surface.fontSize, |
| 171 | lineHeight: surface.rowHeight, |
| 172 | }} |
| 173 | > |
| 174 | {token.text} |
| 175 | </Text> |
| 176 | ))} |
| 177 | </Text> |
| 178 | ); |
| 179 | |
| 180 | if (props.wordBreak) { |
| 181 | return ( |
| 182 | <View className="p-4"> |
| 183 | {CODE_PREVIEW_LINES.map((line, index) => ( |
| 184 | <View className="flex-row" key={line.id}> |
| 185 | {lineNumber(line, index)} |
| 186 | <View className="flex-1 pl-3">{codeLine(line, true)}</View> |
| 187 | </View> |
| 188 | ))} |
| 189 | </View> |
| 190 | ); |
| 191 | } |
| 192 | |
| 193 | return ( |
| 194 | <View className="flex-row p-4"> |
| 195 | <View>{CODE_PREVIEW_LINES.map((line, index) => lineNumber(line, index))}</View> |
| 196 | <ScrollView |
| 197 | horizontal |
| 198 | contentContainerStyle={{ paddingLeft: 12 }} |
| 199 | showsHorizontalScrollIndicator={false} |
| 200 | > |
| 201 | <View>{CODE_PREVIEW_LINES.map((line) => codeLine(line, false))}</View> |
| 202 | </ScrollView> |
| 203 | </View> |
| 204 | ); |
| 205 | } |