Have /clear clear <Static> content by remounting (#250)
This commit is contained in:
parent
74f8f5eaa9
commit
a0bed3e716
|
@ -4,7 +4,7 @@
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React, { useState, useMemo, useCallback } from 'react';
|
import React, { useCallback, useMemo, useRef, useState } from 'react';
|
||||||
import { Box, Static, Text, useStdout } from 'ink';
|
import { Box, Static, Text, useStdout } from 'ink';
|
||||||
import { StreamingState, type HistoryItem } from './types.js';
|
import { StreamingState, type HistoryItem } from './types.js';
|
||||||
import { useGeminiStream } from './hooks/useGeminiStream.js';
|
import { useGeminiStream } from './hooks/useGeminiStream.js';
|
||||||
|
@ -44,13 +44,18 @@ export const App = ({ config, settings, cliVersion }: AppProps) => {
|
||||||
handleThemeHighlight,
|
handleThemeHighlight,
|
||||||
} = useThemeCommand(settings);
|
} = useThemeCommand(settings);
|
||||||
|
|
||||||
|
const [staticKey, setStaticKey] = useState(0);
|
||||||
|
const refreshStatic = useCallback(() => {
|
||||||
|
setStaticKey((prev) => prev + 1);
|
||||||
|
}, [setStaticKey]);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
streamingState,
|
streamingState,
|
||||||
submitQuery,
|
submitQuery,
|
||||||
initError,
|
initError,
|
||||||
debugMessage,
|
debugMessage,
|
||||||
slashCommands,
|
slashCommands,
|
||||||
} = useGeminiStream(setHistory, config, openThemeDialog);
|
} = useGeminiStream(setHistory, refreshStatic, config, openThemeDialog);
|
||||||
const { elapsedTime, currentLoadingPhrase } =
|
const { elapsedTime, currentLoadingPhrase } =
|
||||||
useLoadingIndicator(streamingState);
|
useLoadingIndicator(streamingState);
|
||||||
|
|
||||||
|
@ -124,7 +129,10 @@ export const App = ({ config, settings, cliVersion }: AppProps) => {
|
||||||
* content is set it'll flush content to the terminal and move the area which it's "clearing"
|
* content is set it'll flush content to the terminal and move the area which it's "clearing"
|
||||||
* down a notch. Without Static the area which gets erased and redrawn continuously grows.
|
* down a notch. Without Static the area which gets erased and redrawn continuously grows.
|
||||||
*/}
|
*/}
|
||||||
<Static items={['header', ...staticallyRenderedHistoryItems]}>
|
<Static
|
||||||
|
key={'static-key-' + staticKey}
|
||||||
|
items={['header', ...staticallyRenderedHistoryItems]}
|
||||||
|
>
|
||||||
{(item, index) => {
|
{(item, index) => {
|
||||||
if (item === 'header') {
|
if (item === 'header') {
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -28,6 +28,7 @@ const addHistoryItem = (
|
||||||
|
|
||||||
export const useSlashCommandProcessor = (
|
export const useSlashCommandProcessor = (
|
||||||
setHistory: React.Dispatch<React.SetStateAction<HistoryItem[]>>,
|
setHistory: React.Dispatch<React.SetStateAction<HistoryItem[]>>,
|
||||||
|
refreshStatic: () => void,
|
||||||
setDebugMessage: React.Dispatch<React.SetStateAction<string>>,
|
setDebugMessage: React.Dispatch<React.SetStateAction<string>>,
|
||||||
getNextMessageId: (baseTimestamp: number) => number,
|
getNextMessageId: (baseTimestamp: number) => number,
|
||||||
openThemeDialog: () => void,
|
openThemeDialog: () => void,
|
||||||
|
@ -55,6 +56,7 @@ export const useSlashCommandProcessor = (
|
||||||
// This just clears the *UI* history, not the model history.
|
// This just clears the *UI* history, not the model history.
|
||||||
setDebugMessage('Clearing terminal.');
|
setDebugMessage('Clearing terminal.');
|
||||||
setHistory((_) => []);
|
setHistory((_) => []);
|
||||||
|
refreshStatic();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -48,6 +48,7 @@ const addHistoryItem = (
|
||||||
// Hook now accepts apiKey and model
|
// Hook now accepts apiKey and model
|
||||||
export const useGeminiStream = (
|
export const useGeminiStream = (
|
||||||
setHistory: React.Dispatch<React.SetStateAction<HistoryItem[]>>,
|
setHistory: React.Dispatch<React.SetStateAction<HistoryItem[]>>,
|
||||||
|
refreshStatic: () => void,
|
||||||
config: Config,
|
config: Config,
|
||||||
openThemeDialog: () => void,
|
openThemeDialog: () => void,
|
||||||
) => {
|
) => {
|
||||||
|
@ -73,6 +74,7 @@ export const useGeminiStream = (
|
||||||
// Instantiate command processors
|
// Instantiate command processors
|
||||||
const { handleSlashCommand, slashCommands } = useSlashCommandProcessor(
|
const { handleSlashCommand, slashCommands } = useSlashCommandProcessor(
|
||||||
setHistory,
|
setHistory,
|
||||||
|
refreshStatic,
|
||||||
setDebugMessage,
|
setDebugMessage,
|
||||||
getNextMessageId,
|
getNextMessageId,
|
||||||
openThemeDialog,
|
openThemeDialog,
|
||||||
|
|
Loading…
Reference in New Issue