mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-18 22:35:51 +00:00
style: 完成所有文件的lint
This commit is contained in:
@@ -1,28 +1,24 @@
|
||||
import React, { useRef } from 'react'
|
||||
import stripAnsi from 'strip-ansi'
|
||||
import { Messages } from '../components/Messages.js'
|
||||
import { KeybindingProvider } from '../keybindings/KeybindingContext.js'
|
||||
import { loadKeybindingsSyncWithWarnings } from '../keybindings/loadUserBindings.js'
|
||||
import type { KeybindingContextName } from '../keybindings/types.js'
|
||||
import { AppStateProvider } from '../state/AppState.js'
|
||||
import type { Tools } from '../Tool.js'
|
||||
import type { Message } from '../types/message.js'
|
||||
import { renderToAnsiString } from './staticRender.js'
|
||||
import React, { useRef } from 'react';
|
||||
import stripAnsi from 'strip-ansi';
|
||||
import { Messages } from '../components/Messages.js';
|
||||
import { KeybindingProvider } from '../keybindings/KeybindingContext.js';
|
||||
import { loadKeybindingsSyncWithWarnings } from '../keybindings/loadUserBindings.js';
|
||||
import type { KeybindingContextName } from '../keybindings/types.js';
|
||||
import { AppStateProvider } from '../state/AppState.js';
|
||||
import type { Tools } from '../Tool.js';
|
||||
import type { Message } from '../types/message.js';
|
||||
import { renderToAnsiString } from './staticRender.js';
|
||||
|
||||
/**
|
||||
* Minimal keybinding provider for static/headless renders.
|
||||
* Provides keybinding context without the ChordInterceptor (which uses useInput
|
||||
* and would hang in headless renders with no stdin).
|
||||
*/
|
||||
function StaticKeybindingProvider({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode
|
||||
}): React.ReactNode {
|
||||
const { bindings } = loadKeybindingsSyncWithWarnings()
|
||||
const pendingChordRef = useRef(null)
|
||||
const handlerRegistryRef = useRef(new Map())
|
||||
const activeContexts = useRef(new Set<KeybindingContextName>()).current
|
||||
function StaticKeybindingProvider({ children }: { children: React.ReactNode }): React.ReactNode {
|
||||
const { bindings } = loadKeybindingsSyncWithWarnings();
|
||||
const pendingChordRef = useRef(null);
|
||||
const handlerRegistryRef = useRef(new Map());
|
||||
const activeContexts = useRef(new Set<KeybindingContextName>()).current;
|
||||
|
||||
return (
|
||||
<KeybindingProvider
|
||||
@@ -37,7 +33,7 @@ function StaticKeybindingProvider({
|
||||
>
|
||||
{children}
|
||||
</KeybindingProvider>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Upper-bound how many NormalizedMessages a Message can produce.
|
||||
@@ -45,9 +41,9 @@ function StaticKeybindingProvider({
|
||||
// NormalizedMessages — 1:1 with block count. String content = 1 block.
|
||||
// AttachmentMessage etc. have no .message and normalize to ≤1.
|
||||
function normalizedUpperBound(m: Message): number {
|
||||
if (!('message' in m)) return 1
|
||||
const c = m.message!.content
|
||||
return Array.isArray(c) ? c.length : 1
|
||||
if (!('message' in m)) return 1;
|
||||
const c = m.message!.content;
|
||||
return Array.isArray(c) ? c.length : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,10 +68,10 @@ export async function streamRenderedMessages(
|
||||
chunkSize = 40,
|
||||
onProgress,
|
||||
}: {
|
||||
columns?: number
|
||||
verbose?: boolean
|
||||
chunkSize?: number
|
||||
onProgress?: (rendered: number) => void
|
||||
columns?: number;
|
||||
verbose?: boolean;
|
||||
chunkSize?: number;
|
||||
onProgress?: (rendered: number) => void;
|
||||
} = {},
|
||||
): Promise<void> {
|
||||
const renderChunk = (range: readonly [number, number]) =>
|
||||
@@ -101,20 +97,20 @@ export async function streamRenderedMessages(
|
||||
</StaticKeybindingProvider>
|
||||
</AppStateProvider>,
|
||||
columns,
|
||||
)
|
||||
);
|
||||
|
||||
// renderRange indexes into the post-collapse array whose length we can't
|
||||
// see from here — normalize splits each Message into one NormalizedMessage
|
||||
// per content block (unbounded per message), collapse merges some back.
|
||||
// Ceiling is the exact normalize output count + chunkSize so the loop
|
||||
// always reaches the empty slice where break fires (collapse only shrinks).
|
||||
let ceiling = chunkSize
|
||||
for (const m of messages) ceiling += normalizedUpperBound(m)
|
||||
let ceiling = chunkSize;
|
||||
for (const m of messages) ceiling += normalizedUpperBound(m);
|
||||
for (let offset = 0; offset < ceiling; offset += chunkSize) {
|
||||
const ansi = await renderChunk([offset, offset + chunkSize])
|
||||
if (stripAnsi(ansi).trim() === '') break
|
||||
await sink(ansi)
|
||||
onProgress?.(offset + chunkSize)
|
||||
const ansi = await renderChunk([offset, offset + chunkSize]);
|
||||
if (stripAnsi(ansi).trim() === '') break;
|
||||
await sink(ansi);
|
||||
onProgress?.(offset + chunkSize);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,12 +123,7 @@ export async function renderMessagesToPlainText(
|
||||
tools: Tools = [],
|
||||
columns?: number,
|
||||
): Promise<string> {
|
||||
const parts: string[] = []
|
||||
await streamRenderedMessages(
|
||||
messages,
|
||||
tools,
|
||||
chunk => void parts.push(stripAnsi(chunk)),
|
||||
{ columns },
|
||||
)
|
||||
return parts.join('')
|
||||
const parts: string[] = [];
|
||||
await streamRenderedMessages(messages, tools, chunk => void parts.push(stripAnsi(chunk)), { columns });
|
||||
return parts.join('');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user