Skip to content
Merged
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
10 changes: 5 additions & 5 deletions src/components/terminal/KeyBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,7 @@ export function KeyBar({
};

return (
<Animated.View
style={[styles.row, padStyle]}
onTouchStart={() => onPagerScrollEnabled?.(false)}
onTouchEnd={() => onPagerScrollEnabled?.(true)}
onTouchCancel={() => onPagerScrollEnabled?.(true)}>
<Animated.View style={[styles.row, padStyle]}>
<View
style={[
styles.capsule,
Expand All @@ -107,6 +103,10 @@ export function KeyBar({
showsVerticalScrollIndicator={false}
alwaysBounceVertical={false}
directionalLockEnabled
keyboardShouldPersistTaps="always"
onScrollBeginDrag={() => onPagerScrollEnabled?.(false)}
onScrollEndDrag={() => onPagerScrollEnabled?.(true)}
onMomentumScrollEnd={() => onPagerScrollEnabled?.(true)}
contentContainerStyle={styles.capsuleContent}>
<CapsuleButton label="esc" onPress={() => send(ESC)} />
<ModifierKey
Expand Down
32 changes: 24 additions & 8 deletions src/components/terminal/TerminalView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ActivityIndicator, Keyboard, Pressable, StyleSheet, Text, TextInput, Vi
import { useReanimatedKeyboardAnimation } from 'react-native-keyboard-controller';
import Animated, { useAnimatedStyle } from 'react-native-reanimated';

import { stringToBase64 } from '@/lib/base64';
import { bytesToBase64, stringToBase64 } from '@/lib/base64';
import { getNerdFont, NERD_FONT_FAMILY, subscribeNerdFont } from '@/lib/nerdFont';
import {
recordDimensions,
Expand All @@ -29,12 +29,14 @@ type Props = {
onPagerScrollEnabled?: (enabled: boolean) => void;
};

const INPUT_SENTINEL = '​';

export function TerminalView({ paneId, onPagerScrollEnabled }: Props) {
const tokens = useTokens();
const webRef = useRef<TerminalWebViewHandle>(null);
const inputRef = useRef<TextInput>(null);
const lastSentRef = useRef('');
const [inputValue, setInputValue] = useState('');
const [inputValue, setInputValue] = useState(INPUT_SENTINEL);

const lastTheme = useDevicesStore((s) => s.lastAppliedTheme);
const activePairing = useDevicesStore((s) => {
Expand Down Expand Up @@ -128,24 +130,32 @@ export function TerminalView({ paneId, onPagerScrollEnabled }: Props) {

const handleInputChange = useCallback(
(text: string) => {
const newlineIdx = text.indexOf('\n');
const sentinelIdx = text.lastIndexOf(INPUT_SENTINEL);
if (sentinelIdx === -1) {
sendTerminalInput(paneId, bytesToBase64(new Uint8Array([0x7f])));
lastSentRef.current = '';
setInputValue(INPUT_SENTINEL);
return;
}
const body = text.slice(sentinelIdx + INPUT_SENTINEL.length);
const newlineIdx = body.indexOf('\n');
if (newlineIdx === -1) {
setInputValue(text);
sendInputDiff(text);
setInputValue(INPUT_SENTINEL + body);
sendInputDiff(body);
return;
}
const before = text.slice(0, newlineIdx);
const before = body.slice(0, newlineIdx);
sendInputDiff(before);
sendTerminalInput(paneId, stringToBase64('\r'));
lastSentRef.current = '';
setInputValue('');
setInputValue(INPUT_SENTINEL);
},
[paneId, sendInputDiff],
);

const handleInputBlur = useCallback(() => {
lastSentRef.current = '';
setInputValue('');
setInputValue(INPUT_SENTINEL);
}, []);

const keyboardVisibleRef = useRef(false);
Expand All @@ -171,6 +181,11 @@ export function TerminalView({ paneId, onPagerScrollEnabled }: Props) {
inputRef.current?.focus();
}, []);

const inputSelection = useMemo(
() => ({ start: inputValue.length, end: inputValue.length }),
[inputValue],
);

const { height } = useReanimatedKeyboardAnimation();
const slideStyle = useAnimatedStyle(() => ({
paddingBottom: -height.value,
Expand All @@ -195,6 +210,7 @@ export function TerminalView({ paneId, onPagerScrollEnabled }: Props) {
<TextInput
ref={inputRef}
value={inputValue}
selection={inputSelection}
onChangeText={handleInputChange}
onBlur={handleInputBlur}
multiline
Expand Down
Loading