react-terminal-viewer
Version:
<h1 align="center"> react-terminal-viewer </h1>
141 lines (140 loc) • 5.43 kB
TypeScript
/**
* 从 https://github.com/xtermjs/xterm.js/blob/master/addons/xterm-addon-search/src/SearchAddon.ts 复制以解决部分问题
*/
import { Terminal, ITerminalAddon } from 'xterm';
export interface ISearchOptions {
regex?: boolean;
wholeWord?: boolean;
caseSensitive?: boolean;
incremental?: boolean;
decorations?: ISearchDecorationOptions;
noScroll?: boolean;
}
interface ISearchDecorationOptions {
matchForegroundColor?: string;
matchBackground?: string;
matchBorder?: string;
matchOverviewRuler: string;
activeMatchBackground?: string;
activeMatchBorder?: string;
activeMatchColorOverviewRuler: string;
}
export interface ISearchPosition {
startCol: number;
startRow: number;
}
export interface ISearchResult {
term: string;
col: number;
row: number;
size: number;
}
export declare class SearchAddon implements ITerminalAddon {
private _terminal;
private _cachedSearchTerm;
private _selectedDecoration;
private _resultDecorations;
private _searchResults;
private _onDataDisposable;
private _onResizeDisposable;
private _lastSearchOptions;
private _highlightTimeout;
/**
* translateBufferLineToStringWithWrap is a fairly expensive call.
* We memoize the calls into an array that has a time based ttl.
* _linesCache is also invalidated when the terminal cursor moves.
*/
private _linesCache;
private _linesCacheTimeoutId;
private _cursorMoveListener;
private _resizeListener;
private _resultIndex;
private readonly _onDidChangeResults;
readonly onDidChangeResults: import("./EventEmiter").IEvent<{
resultIndex: number;
resultCount: number;
} | undefined, void>;
activate(terminal: Terminal): void;
private _updateMatches;
dispose(): void;
clearDecorations(retainCachedSearchTerm?: boolean): void;
clearActiveDecoration(): void;
/**
* Find the next instance of the term, then scroll to and select it. If it
* doesn't exist, do nothing.
* @param term The search term.
* @param searchOptions Search options.
* @return Whether a result was found.
*/
findNext(term: string, searchOptions?: ISearchOptions): boolean;
private _highlightAllMatches;
private _find;
private _findNextAndSelect;
/**
* Find the previous instance of the term, then scroll to and select it. If it
* doesn't exist, do nothing.
* @param term The search term.
* @param searchOptions Search options.
* @return Whether a result was found.
*/
findPrevious(term: string, searchOptions?: ISearchOptions): boolean;
private _fireResults;
private _findPreviousAndSelect;
/**
* Sets up a line cache with a ttl
*/
private _initLinesCache;
private _destroyLinesCache;
/**
* A found substring is a whole word if it doesn't have an alphanumeric character directly adjacent to it.
* @param searchIndex starting indext of the potential whole word substring
* @param line entire string in which the potential whole word was found
* @param term the substring that starts at searchIndex
*/
private _isWholeWord;
/**
* Searches a line for a search term. Takes the provided terminal line and searches the text line, which may contain
* subsequent terminal lines if the text is wrapped. If the provided line number is part of a wrapped text line that
* started on an earlier line then it is skipped since it will be properly searched when the terminal line that the
* text starts on is searched.
* @param term The search term.
* @param position The position to start the search.
* @param searchOptions Search options.
* @param isReverseSearch Whether the search should start from the right side of the terminal and search to the left.
* @return The search result if it was found.
*/
protected _findInLine(term: string, searchPosition: ISearchPosition, searchOptions?: ISearchOptions, isReverseSearch?: boolean): ISearchResult | undefined;
private _stringLengthToBufferSize;
private _bufferColsToStringOffset;
/**
* Translates a buffer line to a string, including subsequent lines if they are wraps.
* Wide characters will count as two columns in the resulting string. This
* function is useful for getting the actual text underneath the raw selection
* position.
* @param line The line being translated.
* @param trimRight Whether to trim whitespace to the right.
*/
private _translateBufferLineToStringWithWrap;
/**
* Selects and scrolls to a result.
* @param result The result to select.
* @return Whether a result was selected.
*/
private _selectResult;
/**
* Applies styles to the decoration when it is rendered
* @param element the decoration's element
* @param backgroundColor the background color to apply
* @param borderColor the border color to apply
* @returns
*/
private _applyStyles;
/**
* Creates a decoration for the result and applies styles
* @param result the search result for which to create the decoration
* @param options the options for the decoration
* @returns the {@link IDecoration} or undefined if the marker has already been disposed of
*/
private _createResultDecoration;
}
export {};