mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 12:21:13 -05:00
Format large numbers to use k or m
This commit is contained in:
@@ -6,6 +6,7 @@ import { useExtensionState } from "../../context/ExtensionStateContext"
|
|||||||
import { vscode } from "../../utils/vscode"
|
import { vscode } from "../../utils/vscode"
|
||||||
import Thumbnails from "../common/Thumbnails"
|
import Thumbnails from "../common/Thumbnails"
|
||||||
import { mentionRegexGlobal } from "../../../../src/shared/context-mentions"
|
import { mentionRegexGlobal } from "../../../../src/shared/context-mentions"
|
||||||
|
import { formatLargeNumber } from "../../utils/format"
|
||||||
|
|
||||||
interface TaskHeaderProps {
|
interface TaskHeaderProps {
|
||||||
task: ClaudeMessage
|
task: ClaudeMessage
|
||||||
@@ -257,14 +258,14 @@ const TaskHeader: React.FC<TaskHeaderProps> = ({
|
|||||||
className="codicon codicon-arrow-up"
|
className="codicon codicon-arrow-up"
|
||||||
style={{ fontSize: "12px", fontWeight: "bold", marginBottom: "-2px" }}
|
style={{ fontSize: "12px", fontWeight: "bold", marginBottom: "-2px" }}
|
||||||
/>
|
/>
|
||||||
{tokensIn?.toLocaleString()}
|
{formatLargeNumber(tokensIn || 0)}
|
||||||
</span>
|
</span>
|
||||||
<span style={{ display: "flex", alignItems: "center", gap: "3px" }}>
|
<span style={{ display: "flex", alignItems: "center", gap: "3px" }}>
|
||||||
<i
|
<i
|
||||||
className="codicon codicon-arrow-down"
|
className="codicon codicon-arrow-down"
|
||||||
style={{ fontSize: "12px", fontWeight: "bold", marginBottom: "-2px" }}
|
style={{ fontSize: "12px", fontWeight: "bold", marginBottom: "-2px" }}
|
||||||
/>
|
/>
|
||||||
{tokensOut?.toLocaleString()}
|
{formatLargeNumber(tokensOut || 0)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{!isCostAvailable && <ExportButton />}
|
{!isCostAvailable && <ExportButton />}
|
||||||
@@ -278,14 +279,14 @@ const TaskHeader: React.FC<TaskHeaderProps> = ({
|
|||||||
className="codicon codicon-database"
|
className="codicon codicon-database"
|
||||||
style={{ fontSize: "12px", fontWeight: "bold", marginBottom: "-1px" }}
|
style={{ fontSize: "12px", fontWeight: "bold", marginBottom: "-1px" }}
|
||||||
/>
|
/>
|
||||||
+{(cacheWrites || 0)?.toLocaleString()}
|
+{formatLargeNumber(cacheWrites || 0)}
|
||||||
</span>
|
</span>
|
||||||
<span style={{ display: "flex", alignItems: "center", gap: "3px" }}>
|
<span style={{ display: "flex", alignItems: "center", gap: "3px" }}>
|
||||||
<i
|
<i
|
||||||
className="codicon codicon-arrow-right"
|
className="codicon codicon-arrow-right"
|
||||||
style={{ fontSize: "12px", fontWeight: "bold", marginBottom: 0 }}
|
style={{ fontSize: "12px", fontWeight: "bold", marginBottom: 0 }}
|
||||||
/>
|
/>
|
||||||
{(cacheReads || 0)?.toLocaleString()}
|
{formatLargeNumber(cacheReads || 0)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { VSCodeButton } from "@vscode/webview-ui-toolkit/react"
|
|||||||
import { useExtensionState } from "../../context/ExtensionStateContext"
|
import { useExtensionState } from "../../context/ExtensionStateContext"
|
||||||
import { vscode } from "../../utils/vscode"
|
import { vscode } from "../../utils/vscode"
|
||||||
import { memo } from "react"
|
import { memo } from "react"
|
||||||
|
import { formatLargeNumber } from "../../utils/format"
|
||||||
|
|
||||||
type HistoryPreviewProps = {
|
type HistoryPreviewProps = {
|
||||||
showHistoryView: () => void
|
showHistoryView: () => void
|
||||||
@@ -107,14 +108,15 @@ const HistoryPreview = ({ showHistoryView }: HistoryPreviewProps) => {
|
|||||||
</div>
|
</div>
|
||||||
<div style={{ fontSize: "0.85em", color: "var(--vscode-descriptionForeground)" }}>
|
<div style={{ fontSize: "0.85em", color: "var(--vscode-descriptionForeground)" }}>
|
||||||
<span>
|
<span>
|
||||||
Tokens: ↑{item.tokensIn?.toLocaleString()} ↓{item.tokensOut?.toLocaleString()}
|
Tokens: ↑{formatLargeNumber(item.tokensIn || 0)} ↓
|
||||||
|
{formatLargeNumber(item.tokensOut || 0)}
|
||||||
</span>
|
</span>
|
||||||
{!!item.cacheWrites && (
|
{!!item.cacheWrites && (
|
||||||
<>
|
<>
|
||||||
{" • "}
|
{" • "}
|
||||||
<span>
|
<span>
|
||||||
Cache: +{item.cacheWrites?.toLocaleString()} →{" "}
|
Cache: +{formatLargeNumber(item.cacheWrites || 0)} →{" "}
|
||||||
{(item.cacheReads || 0).toLocaleString()}
|
{formatLargeNumber(item.cacheReads || 0)}
|
||||||
</span>
|
</span>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { vscode } from "../../utils/vscode"
|
|||||||
import { Virtuoso } from "react-virtuoso"
|
import { Virtuoso } from "react-virtuoso"
|
||||||
import { memo, useMemo, useState, useEffect } from "react"
|
import { memo, useMemo, useState, useEffect } from "react"
|
||||||
import Fuse, { FuseResult } from "fuse.js"
|
import Fuse, { FuseResult } from "fuse.js"
|
||||||
|
import { formatLargeNumber } from "../../utils/format"
|
||||||
|
|
||||||
type HistoryViewProps = {
|
type HistoryViewProps = {
|
||||||
onDone: () => void
|
onDone: () => void
|
||||||
@@ -305,7 +306,7 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
|
|||||||
marginBottom: "-2px",
|
marginBottom: "-2px",
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{item.tokensIn?.toLocaleString()}
|
{formatLargeNumber(item.tokensIn || 0)}
|
||||||
</span>
|
</span>
|
||||||
<span
|
<span
|
||||||
style={{
|
style={{
|
||||||
@@ -322,7 +323,7 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
|
|||||||
marginBottom: "-2px",
|
marginBottom: "-2px",
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{item.tokensOut?.toLocaleString()}
|
{formatLargeNumber(item.tokensOut || 0)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{!item.totalCost && <ExportButton itemId={item.id} />}
|
{!item.totalCost && <ExportButton itemId={item.id} />}
|
||||||
@@ -358,7 +359,7 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
|
|||||||
marginBottom: "-1px",
|
marginBottom: "-1px",
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
+{item.cacheWrites?.toLocaleString()}
|
+{formatLargeNumber(item.cacheWrites || 0)}
|
||||||
</span>
|
</span>
|
||||||
<span
|
<span
|
||||||
style={{
|
style={{
|
||||||
@@ -375,7 +376,7 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
|
|||||||
marginBottom: 0,
|
marginBottom: 0,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{(item.cacheReads || 0).toLocaleString()}
|
{formatLargeNumber(item.cacheReads || 0)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
12
webview-ui/src/utils/format.ts
Normal file
12
webview-ui/src/utils/format.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
export function formatLargeNumber(num: number): string {
|
||||||
|
if (num >= 1e9) {
|
||||||
|
return (num / 1e9).toFixed(1) + "b"
|
||||||
|
}
|
||||||
|
if (num >= 1e6) {
|
||||||
|
return (num / 1e6).toFixed(1) + "m"
|
||||||
|
}
|
||||||
|
if (num >= 1e3) {
|
||||||
|
return (num / 1e3).toFixed(1) + "k"
|
||||||
|
}
|
||||||
|
return num.toString()
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user