Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v16] Add search to ssh player in session recordings #49507

Merged
merged 1 commit into from
Nov 29, 2024
Merged
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
47 changes: 44 additions & 3 deletions web/packages/teleport/src/Player/Xterm/Xterm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import React, { useEffect, useRef } from 'react';
import React, { useEffect, useCallback, useRef, useState } from 'react';

import { getPlatformType } from 'design/platform';
import { useTheme } from 'styled-components';
import styled, { useTheme } from 'styled-components';
import { TerminalSearch } from 'shared/components/TerminalSearch';

import Terminal from 'teleport/lib/term/terminal';
import Tty from 'teleport/lib/term/tty';
Expand All @@ -30,6 +31,19 @@ export default function Xterm({ tty }: { tty: Tty }) {
const refContainer = useRef<HTMLDivElement>();
const theme = useTheme();
const terminalPlayer = useRef<TerminalPlayer>();
const [showSearch, setShowSearch] = useState(false);

const onSearchClose = useCallback(() => {
setShowSearch(false);
}, []);

const onSearchOpen = useCallback(() => {
setShowSearch(true);
}, []);

const isSearchKeyboardEvent = useCallback((e: KeyboardEvent) => {
return (e.metaKey || e.ctrlKey) && e.key === 'f';
}, []);

useEffect(() => {
const term = new TerminalPlayer(tty, {
Expand Down Expand Up @@ -70,7 +84,22 @@ export default function Xterm({ tty }: { tty: Tty }) {
terminalPlayer.current?.updateTheme(theme.colors.terminal);
}, [theme]);

return <StyledXterm ref={refContainer} />;
return (
<>
<StyledXterm ref={refContainer} />
{terminalPlayer.current && (
<TerminalAddonsContainer>
<TerminalSearch
show={showSearch}
isSearchKeyboardEvent={isSearchKeyboardEvent}
onClose={onSearchClose}
onOpen={onSearchOpen}
terminalSearcher={terminalPlayer.current}
/>
</TerminalAddonsContainer>
)}
</>
);
}

class TerminalPlayer extends Terminal {
Expand All @@ -90,3 +119,15 @@ class TerminalPlayer extends Terminal {
// prevent user resize requests
_requestResize() {}
}

const TerminalAddonsContainer = styled.div`
position: absolute;
right: ${p => p.theme.space[2]}px;
top: ${p => p.theme.space[2]}px;
z-index: 10;
display: flex;
flex-direction: column;
align-items: flex-end;
gap: ${p => p.theme.space[2]}px;
min-width: 500px;
`;
Loading