fix(tui): show shell working directory in prompt
This commit is contained in:
parent
c7871e14d4
commit
2ddc91a0e8
3 changed files with 61 additions and 5 deletions
|
|
@ -644,17 +644,17 @@ function snapQuestion(p: ToolProps): ToolSnapshot {
|
|||
function scrollBashStart(p: ToolProps): string {
|
||||
const cmd = p.input.command ?? ""
|
||||
const wd = p.input.workdir ?? ""
|
||||
const formatted = wd && wd !== "." ? displayPath(p, wd) : ""
|
||||
const formatted = wd && wd !== "." ? displayPath(p, wd, { home: true }) : ""
|
||||
const dir = formatted === "." ? "" : formatted
|
||||
if (cmd && !dir) {
|
||||
return `$ ${cmd}`
|
||||
}
|
||||
|
||||
if (!cmd) {
|
||||
return dir ? `# Running in ${dir}` : ""
|
||||
return dir ? `${dir}$` : ""
|
||||
}
|
||||
|
||||
return `# Running in ${dir}\n$ ${cmd}`
|
||||
return `${dir}$ ${cmd}`
|
||||
}
|
||||
|
||||
function scrollBashProgress(p: ToolProps): string {
|
||||
|
|
@ -670,7 +670,7 @@ function scrollBashProgress(p: ToolProps): string {
|
|||
}
|
||||
|
||||
const wdRaw = (p.input.workdir ?? "").trim()
|
||||
const wd = wdRaw ? displayPath(p, wdRaw) : ""
|
||||
const wd = wdRaw ? displayPath(p, wdRaw, { home: true }) : ""
|
||||
const lines = out.split("\n")
|
||||
const first = (lines[0] || "").trim()
|
||||
const second = (lines[1] || "").trim()
|
||||
|
|
|
|||
|
|
@ -2562,6 +2562,7 @@ function Shell(props: ToolProps) {
|
|||
const ctx = use()
|
||||
const client = useClient()
|
||||
const data = useData()
|
||||
const pathFormatter = usePathFormatter()
|
||||
const permission = createMemo(() => {
|
||||
const request = data.session.permission.list(ctx.sessionID)?.[0]
|
||||
return request?.source?.type === "tool" && request.source.callID === props.part.id
|
||||
|
|
@ -2575,6 +2576,7 @@ function Shell(props: ToolProps) {
|
|||
})
|
||||
const isRunning = createMemo(() => props.part.state.status === "running" || backgroundRunning())
|
||||
const command = createMemo(() => stringValue(props.input.command))
|
||||
const workdir = createMemo(() => pathFormatter.format(stringValue(props.input.workdir)))
|
||||
const [expanded, setExpanded] = createSignal(false)
|
||||
const [backgroundOutput, setBackgroundOutput] = createSignal("")
|
||||
const [outputTruncated, setOutputTruncated] = createSignal(false)
|
||||
|
|
@ -2648,7 +2650,11 @@ function Shell(props: ToolProps) {
|
|||
})
|
||||
const maxLines = 10
|
||||
const maxChars = createMemo(() => maxLines * Math.max(20, ctx.width - 6))
|
||||
const input = createMemo(() => (command() ? `${isRunning() ? "" : "$ "}${command()}` : ""))
|
||||
const input = createMemo(() => {
|
||||
if (!command()) return ""
|
||||
const prompt = workdir() && workdir() !== "." ? `${workdir()}$ ` : isRunning() ? "" : "$ "
|
||||
return `${prompt}${command()}`
|
||||
})
|
||||
const content = createMemo(() => [input(), output()].filter(Boolean).join("\n\n"))
|
||||
const collapsed = createMemo(() => collapseToolOutput(content(), maxLines, maxChars()))
|
||||
const limited = createMemo(() => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue