import { Buffer } from 'buffer'; import { EventEmitter } from 'events'; import _localforage from 'localforage'; import * as Path from 'node:path'; import { ICommandInfo, WebTerm, parseCommand } from 'web-term-ui'; export declare function getMaxCommonHead(values: string[], start?: number): string; export type NodePath = typeof Path; export type IFileType = "empty" | "file" | "dir" | "link"; export interface IFileStats { size: number; type: IFileType; isDirectory(): boolean; isFile(): boolean; } /* * @Author: chenzhongsheng * @Date: 2024-11-30 11:30:49 * @Description: Coding something */ export type IPromiseData> = T extends Promise ? U : any; export type IPromiseMaybe = Promise | T; export type IFnMaybe = T | (() => T); export type IOprateResult = {}> = { success: boolean; info: string; } & T; export interface ICommand { name: string; helpDetails?: IFnMaybe; version?: IFnMaybe; helpInfo?: IFnMaybe; run(cmd: ICommandInfo, context: { commands: ICommandInfo[]; disk: T; data: string; term: WebTerm; run: (line: string | ICommandInfo[]) => Promise; }): IPromiseMaybe; activate?(disk: T, provider: ICommandProvider): void; dispose?(): void; } export interface ICommandProvider { getPwd: () => string; onTab?: (value: string, full: string) => IPromiseMaybe<({ line?: string; result: string; })>; onCommand: (commands: ICommandInfo[], methods: { setPwd: (v: string) => void; clearTerminal: () => void; getHeader: () => string; openEditor: (options: { path: string; content: string; save: (v: string) => void; }) => void; }) => IPromiseMaybe; registerCommand?(command: ICommand): IOprateResult; removeCommand?(name: string): IOprateResult; } export interface IPos { x: number; y: number; } export declare const TerminalControlKey: { readonly "\r": "Enter"; readonly "": "Backspace"; readonly "\u001B[A": "Up"; readonly "\u001B[B": "Down"; readonly "\u001B[D": "Left"; readonly "\u001B[C": "Right"; readonly "\t": "Tab"; }; export declare const TerminalKeys: ("Enter" | "Tab" | "Backspace" | "Up" | "Down" | "Left" | "Right")[]; export declare const TerminalKeysSet: Set<"Enter" | "Tab" | "Backspace" | "Up" | "Down" | "Left" | "Right">; export type ITerminalKey = typeof TerminalKeys[number]; export interface ITerminalEditor { addRecord(v: string): void; clearRecord(): void; edit(v: string): void; back(): void; onKey(key: ITerminalKey, v?: string): boolean; initTerminalManager(manager: ITerminalManager): void; isEditing: boolean; } export interface ITerminalInfo { x: number; y: number; length: number; rows: number; cols: number; } export interface ITerminalProvider { editor?: ITerminalEditor; title?: string; write(data: string): void; getHeader(): string; onTab?(value: string, full: string): IPromiseMaybe; onCommand?(commands: ICommandInfo[]): IPromiseMaybe; onEnter?(line: string): IPromiseMaybe; onData(ln: (data: string) => void): void; getTermInfo(): ITerminalInfo; } export interface ITerminalManager { name: string; line: string; cursorIndex: number; provider: ITerminalProvider; get header(): string; clear(pure?: boolean): void; setCursorPos(x: number, y: number): void; write(data: string): void; writeLine(text: string, lines?: number): void; writeEmptyLine(): void; cursorMove(count?: number): number; cursorMoveToTail(): void; cursorMoveToHead(): void; replaceCurrentLine(value: string): void; delete(count?: number): void; deleteAll(): void; onHandleTerminalData(data: string): Promise; insertLine(content: string): void; } export declare function notImplemented(): void; export declare function notImplementedAsync(): Promise; export declare function attachTarget(obj: any, target: any): void; export declare function withResolve(): { ready: Promise; resolve: (data?: T) => void; reject: (Err?: Err) => void; }; export declare function mergeU8s(...u8s: Uint8Array[]): Uint8Array; export declare function isU8sEqual(u8s1: Uint8Array, u8s2: Uint8Array | null): boolean; export declare function copyU8s(u8s: Uint8Array): Uint8Array; export declare function io>(promise: T): Promise<[ IPromiseData, any ]>; export declare function encode(v: string): Uint8Array; export declare function decode(v: Uint8Array): string; export declare function runPromises(ps: (() => Promise)[]): Promise; export declare function createPromises(): { add: (v: Promise) => void; run: () => Promise[]>; }; export type DebounceFunction any> = (this: ThisParameterType, ...args: Parameters) => void; export declare function debounce any>(func: T, delay: number): DebounceFunction; export declare function splitPathInfo(path: string): { path: string; parent: string; name: string; }; export declare function asyncAll(): { add(pro: Promise): void; run(): Promise[]>; }; export declare function runPromiseMaybe(v: IPromiseMaybe): Promise; export declare function runFnMaybe(v: T | (() => T)): T; export declare function mergePositions(...ps: IPos[]): IPos; export declare function mergeText(target: string, addon: string, index?: number): string; export declare function removeText(text: string, index: number): string; export declare function geneText(size: number, fill: string): string; export declare function isMac(): boolean; export declare function isHttpLink(v: string): boolean; export declare function fetchJson = Record>(url: string): Promise; export declare function fetchText(url: string): Promise; export declare function executeJS(code: string): Promise; export declare function executeJSWithFn(code: string, args?: Record): T; export interface ICommandOptions { commands: ICommandInfo[]; disk: T; data: string; term: WebTerm; run: (line: string | ICommandInfo[]) => Promise; } export declare class BaseCommand implements ICommand { name: string; helpInfo: IFnMaybe; helpDetails: IFnMaybe; term: WebTerm; disk: T; provider: ICommandProvider; activate(disk: T, provider: ICommandProvider): void; run(cmd: ICommandInfo, options: ICommandOptions): IPromiseMaybe; } export declare function parseGithubFile(v: string, dfFile?: string): string; export declare function parseNPMFile(v: string, useUnpkg?: boolean): string; declare class StorageBackEnd { static Supported(): boolean; private root; init(): Promise; read(path: string): Promise; write(path: string, data: Uint8Array): Promise; private _writeFile; append(path: string, data: Uint8Array): Promise; remove(path: string): Promise; stat(path: string, recursive?: boolean): Promise>; private _isLinkFile; private traverse; traverseContent(callback: (path: string, content: Promise, name: string) => IPromiseMaybe, path?: string, read?: boolean): Promise; private _traverseContent; exist(path: string): Promise; ls(path: string): Promise; private existInDir; createLink(path: string, target: string, overwrite?: boolean): Promise; createFile(path: string, content?: Uint8Array, overwrite?: boolean): Promise; createDir(path: string, overwrite?: boolean): Promise; private clearTarget; private _readFile; private getHandleByPath; private getParentByPath; getType(path: string): Promise; } export type IDiskBankEnd = Pick, "init" | "read" | "write" | "append" | "remove" | "stat" | "exist" | "ls" | "createDir" | "createFile" | "traverseContent" | "getType">; declare class SyncMiddleware { /** * 内存中存在的存储所有文件的map,用于同步方法的实现 * 初始化时需要遍历存储的所有文件,将其加载到内存中 * 读写时需要同步 */ private fileMap; init(backend: IDiskBankEnd): Promise; read(key: string): Uint8Array | null; pureRead(key: string): Uint8Array; write(key: string, content: Uint8Array): boolean; append(key: string, content: Uint8Array): boolean; remove(path: string, onRemove?: (path: string) => void): boolean; private _removeSingle; stat(path: string, recursive?: boolean): { size: number; type: IFileType; }; exist(path: string): boolean; ls(path: string): string[]; createFile(path: string, content?: Uint8Array, overwrite?: boolean): boolean; createDir(path: string, overwrite?: boolean): boolean; getType(path: string): IFileType; traverse(path: string, callback: (data: { path: string; parent: string; name: string; }) => void, includeSelf?: boolean): void; traverseContent(callback: (path: string, content: Uint8Array | null) => void, path?: string): void; } declare class Link { backend: IDiskBankEnd; syncMiddleware?: SyncMiddleware | undefined; constructor(backend: IDiskBankEnd, syncMiddleware?: SyncMiddleware | undefined); get(path: string, data?: Uint8Array): Promise; getSync(path: string, data?: Uint8Array): string; private _get; } declare class Zip { disk: Disk; constructor(disk: Disk); zip(paths: string[], target?: string): Promise; private zipSingleFile; unzip(path: string, target?: string): Promise<{ path: string; isDir: boolean; }[]>; private unzipU8Arr; isZip(path: string): Promise; private isZipData; private getZipData; } export type IWatchEncoding = BufferEncoding | "buffer"; export interface IWatchOptions { persistent?: boolean; recursive?: boolean; encoding?: IWatchEncoding; } export type IWatchCallback = (event: "rename" | "change", path: string | Buffer) => void; declare class FSWatcher extends EventEmitter<{ change: [ "rename" | "change", string | Buffer ]; error: [ Error ]; }> { watch: Watch; options: Required; callback: IWatchCallback; path: string; constructor({ watch, options, callback, path, }: { watch: Watch; options: IWatchOptions; callback: IWatchCallback; path: string; enabled?: boolean; }); static empty(): FSWatcher; close(): void; checkChange(path: string, type: "rename" | "change"): void; } export type IFileListener = (curr: IFileStats, prev: IFileStats) => void; export interface IFileWatchOptions { bigint?: boolean; persistent?: boolean; interval?: number; } declare class Watch { disk: Disk; events: EventEmitter<[ never ]>; watchers: FSWatcher[]; fileWatchers: Record; constructor(disk: Disk); fireRename(path: string, isRemove?: boolean, emit?: boolean): void; fireChange(path: string, emit?: boolean): Promise<(() => void) | null>; fireChangeSync(path: string, emit?: boolean): (() => void) | null; watch(path: string, options: IWatchOptions | IWatchEncoding | IWatchCallback, callback?: IWatchCallback): FSWatcher; watchFile(path: string, options: IFileWatchOptions | IFileListener, callback?: IFileListener): void; unwatchFile(path: string, callback?: IFileListener): void; } declare class SyncProxy { syncMiddleware: SyncMiddleware; disk: Disk; constructor(disk: Disk); init(): Promise; fmtPath(path: string): string; get _link(): Link; get _watch(): Watch; get backend(): IDiskBankEnd; size(path?: string): number; cd(path: string): boolean; isDir(path: string): boolean; getType(path: string): IFileType; pwd(): string; copy(files: string | string[]): boolean; cut(files: string | string[]): boolean; move(source: string, target: string, onFinalName?: (v: string) => void): string; rename(path: string, name: string, onFinalName?: (v: string) => void): string; paste(targetDir: string, renameMap?: Record, onFinalName?: (map: Record) => void): string; pasteBase(targetDir: string, clipboard: IClipboard, renameMap?: Record, onFinalName?: (map: Record) => void): string; ls(path?: string): string[] | null; remove(path: string): boolean; clear(): void; copySingle(source: string, target: string): boolean; traverseContent(path: string, callback: (path: string, content: Uint8Array | null, name: string) => void): void; traverse(path: string, callback: (data: { path: string; parent: string; name: string; }) => void): void; read(path: string): Uint8Array | null; readText(path: string): string | null; write(path: string, data: Uint8Array): boolean; append(path: string, data: Uint8Array): boolean; exist(path: string): boolean; stat(path: string, recursive?: boolean): IFileStats; createFile(path: string, content?: Uint8Array | undefined, opt?: ICreateOpt): boolean; createDir(path: string, opt?: ICreateOpt): boolean; createLink(path: string, target: string, opt?: ICreateOpt): boolean; _create(path: string, content?: Uint8Array | undefined, { overwrite, ensure }?: ICreateOpt, isDir?: boolean, onCreateAsync?: (v: () => Promise) => void): boolean; ensureParentPath(path: string): Promise; _ensureParentPath(path: string): void; } declare enum ChangType { Create = 0, Remove = 1, Change = 2 } declare class UpdateManager { tempChange: Record; timer: any; lastOprateId: string; disk: Disk; private offWatch; constructor(disk: Disk); init(): void; get sync(): SyncMiddleware; checkUpdate(): Promise; private writeFile; private useChanges; checkWriteChange(): Promise; clear(): void; } export interface ICreateOpt { ensure?: boolean; overwrite?: boolean; } export type IDisk = Omit & { createDir: (path: string, opt?: ICreateOpt) => Promise; createLink: (path: string, target: string, opt?: ICreateOpt) => Promise; createFile: (path: string, content: Uint8Array, overwrite?: boolean) => Promise; }; export interface IDiskOption { enableSync?: boolean; } export interface IClipboard { paths: string[]; isCut: boolean; active: boolean; } export declare class Disk implements IDisk { current: string; backend: IDiskBankEnd; ready: Promise; clipboard: IClipboard; _link: Link; _zip: Zip; _watch: Watch; _sync: SyncProxy; get sync(): SyncProxy; _update: UpdateManager; static instance: Disk; enableSync: boolean; constructor({ enableSync, }?: IDiskOption); initSync(): Promise; static initSync(): Promise; _initSyncAlone(enableSync: boolean): Promise; private init; fmtPath(path: string): string; size(path?: string): Promise; cd(path: string): Promise; isDir(path: string): Promise; getType(path: string): Promise; pwd(): string; copy(files: string | string[]): Promise; cut(files: string | string[]): Promise; _addToClipboard(files: string | string[], isCut?: boolean): boolean; move(source: string, target: string, onFinalName?: (v: string) => void): Promise; rename(path: string, name: string, onFinalName?: (v: string) => void): Promise; paste(targetDir: string, renameMap?: Record, onFinalName?: (map: Record) => void): Promise; pasteBase(targetDir: string, clipboard: IClipboard, renameMap?: Record, onFinalName?: (map: Record) => void): Promise; copySingle(source: string, target: string): Promise; traverseContent(path: string, callback: (path: string, content: Promise, name: string) => IPromiseMaybe): Promise; traverse(path: string, callback: (data: { path: string; parent: string; name: string; }) => void): Promise; readText(path: string): Promise; read(path: string): Promise; write(path: string, data: Uint8Array): Promise; append(path: string, data: Uint8Array): Promise; remove(path: string): Promise; stat(path: string, recursive?: boolean): Promise; _transStat({ size, type }: Pick): IFileStats; exist(path: string): Promise; ls(path?: string): Promise; createFile(path: string, content?: Uint8Array | undefined, opt?: ICreateOpt): Promise; createDir(path: string, opt?: ICreateOpt): Promise; _create(path: string, content?: Uint8Array | undefined, { overwrite, ensure }?: ICreateOpt, isDir?: boolean): Promise; createLink(path: string, target: string, opt?: ICreateOpt): Promise; zip(...args: Parameters): Promise<{ success: boolean; info: string; }>; unzip(...args: Parameters): Promise<{ path: string; isDir: boolean; }[]>; isZip(...args: Parameters): Promise; watch(...args: Parameters): FSWatcher; watchFile(...args: Parameters): void; unwatchFile(...args: Parameters): void; clear(): Promise; ensureParentPath(path: string): Promise; _ensureParentPath(path: string): Promise; createFileContent(content: string, type?: IFileType): Uint8Array; } export declare function initDisk(opt?: IDiskOption): Promise; export declare const pt: NodePath; export declare function splitPath(path: string): [ string[], string ]; export declare function clearPath(path: string, tail?: boolean): string; export declare function getParentPath(path: any): string; export declare function getFileName(path: string): string; export declare function getFileExt(path: string): string; export declare function handlePasteFileNames(source: string[], // 复制的完整路径 targetDir: string, // 粘贴目标目录的完整路径 current: string[], // 当前文件夹所有文件名 renameMap?: Record): Record; export declare function renameWhenConflict(name: string, set: Set): string; /** * input: /a/b, /a/b/c/d.js * output: /a/b/c */ export declare function extractSubDir(target: string, filePath: string): string; export declare class CMD { static instance: CMD; disk: Disk; ready: Promise; constructor(enableSync?: boolean); ls(path?: string): Promise; cd(path: string): Promise; pwd(): string; touch(path: string): Promise; mkdir(path: string): Promise; rmdir(path: string): Promise; cp(src: string, dest: string): Promise; mv(src: string, dest: string): Promise; rm(path: string): Promise; cat(path: string): Promise; more(path: string): Promise; less(path: string): Promise; head(path: string, line: number): Promise; tail(path: string, line: number): Promise; grep(path: string, reg: string | RegExp): Promise; find(path: string, { name, type }?: { name?: string | RegExp; type?: IFileType; }): Promise; zip(files: string[], target?: string): Promise<{ success: boolean; info: string; }>; unzip(path: string, target?: string): Promise<{ path: string; isDir: boolean; }[]>; tar(files: string[], target?: string): Promise<{ success: boolean; info: string; }>; du(path: string): Promise; } export declare const createDirContent: () => { data: Uint8Array; length: number; }; export declare const createLinkContent: () => { data: Uint8Array; length: number; }; export declare function getTypeWithData(data: Uint8Array | null): IFileType; export declare function createFileContent(type: IFileType, data?: Uint8Array | string): Uint8Array; // 这样写才会正确的生成dts export const localforage: typeof _localforage = _localforage; interface ICommand$1 extends ICommand { } export interface ICommandDisk extends ICommand$1 { } export declare class CommandProvider implements ICommandProvider { methods: Parameters[1]; cmd: CMD; name: string; thirdCommands: Record; private installCommand; constructor(enableSync: boolean, methods: Parameters[1]); getPwd(): string; get disk(): Disk; onCommand(content: string | ICommandInfo[]): Promise; runSingleCommand(cur: ICommandInfo, prev: string, commands: ICommandInfo[]): Promise; private handleEchoCmd; onTab(range: string, before: string): Promise<{ line: string; result: string; }>; registerCommand(command: ICommand): IOprateResult; removeCommand(name: string): IOprateResult; private _loadCommands; } export declare const OpenUrlCommand: ICommand$1; export declare const InnerCommands: ICommand[]; export declare function findInnerCommand(name: string): ICommand | null; export { ICommandInfo, WebTerm, parseCommand, pt as path, }; export {};