Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 11 additions & 40 deletions packages/opencode/src/cli/cmd/tui/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ import { render, useKeyboard, useRenderer, useTerminalDimensions } from "@opentu
import { Clipboard } from "@tui/util/clipboard"
import { TextAttributes } from "@opentui/core"
import { RouteProvider, useRoute, type Route } from "@tui/context/route"
import { Switch, Match, createEffect, untrack, ErrorBoundary, createSignal } from "solid-js"
import {
Switch,
Match,
createEffect,
untrack,
ErrorBoundary,
createSignal,
onCleanup,
} from "solid-js"
import { Installation } from "@/installation"
import { Global } from "@/global"
import { DialogProvider, useDialog } from "@tui/ui/dialog"
Expand All @@ -28,6 +36,7 @@ import type { SessionRoute } from "./context/route"
import { Session as SessionApi } from "@/session"
import { TuiEvent } from "./event"
import { KVProvider, useKV } from "./context/kv"
import { StatusBar } from "./component/status-bar"

async function getTerminalBackgroundColor(): Promise<"dark" | "light"> {
return new Promise((resolve) => {
Expand Down Expand Up @@ -392,45 +401,7 @@ function App() {
</Match>
</Switch>
</box>
<box
height={1}
backgroundColor={theme.backgroundPanel}
flexDirection="row"
justifyContent="space-between"
flexShrink={0}
>
<box flexDirection="row">
<box
flexDirection="row"
backgroundColor={theme.backgroundElement}
paddingLeft={1}
paddingRight={1}
>
<text fg={theme.textMuted}>open</text>
<text fg={theme.text} attributes={TextAttributes.BOLD}>
code{" "}
</text>
<text fg={theme.textMuted}>v{Installation.VERSION}</text>
</box>
<box paddingLeft={1} paddingRight={1}>
<text fg={theme.textMuted}>{process.cwd().replace(Global.Path.home, "~")}</text>
</box>
</box>
<box flexDirection="row" flexShrink={0}>
<text fg={theme.textMuted} paddingRight={1}>
tab
</text>
<text fg={local.agent.color(local.agent.current().name)}>{""}</text>
<text
bg={local.agent.color(local.agent.current().name)}
fg={theme.background}
wrapMode={undefined}
>
<span style={{ bold: true }}> {local.agent.current().name.toUpperCase()}</span>
<span> AGENT </span>
</text>
</box>
</box>
<StatusBar />
</box>
)
}
Expand Down
57 changes: 57 additions & 0 deletions packages/opencode/src/cli/cmd/tui/component/status-bar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { useTheme } from "@tui/context/theme"
import { useLocal } from "@tui/context/local"
import { Installation } from "@/installation"
import { Global } from "@/global"
import { TextAttributes } from "@opentui/core"
import { useGitBranch } from "./status-bar/git"

export function StatusBar() {
const theme = useTheme()
const local = useLocal()
const { branch } = useGitBranch()

return (
<box
height={1}
backgroundColor={theme.theme.backgroundPanel}
flexDirection="row"
justifyContent="space-between"
flexShrink={0}
>
<box flexDirection="row">
<box
flexDirection="row"
backgroundColor={theme.theme.backgroundElement}
paddingLeft={1}
paddingRight={1}
>
<text fg={theme.theme.textMuted}>open</text>
<text fg={theme.theme.text} attributes={TextAttributes.BOLD}>
code{" "}
</text>
<text fg={theme.theme.textMuted}>v{Installation.VERSION}</text>
</box>
<box paddingLeft={1} paddingRight={1}>
<text fg={theme.theme.textMuted}>
{process.cwd().replace(Global.Path.home, "~")}
{branch() ? `:${branch()}` : ""}
</text>
</box>
</box>
<box flexDirection="row" flexShrink={0}>
<text fg={theme.theme.textMuted} paddingRight={1}>
tab
</text>
<text fg={local.agent.color(local.agent.current().name)}>{""}</text>
<text
bg={local.agent.color(local.agent.current().name)}
fg={theme.theme.background}
wrapMode={undefined}
>
<span style={{ bold: true }}> {local.agent.current().name.toUpperCase()}</span>
<span> AGENT </span>
</text>
</box>
</box>
)
}
32 changes: 32 additions & 0 deletions packages/opencode/src/cli/cmd/tui/component/status-bar/git.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { createSignal, createEffect, onCleanup } from "solid-js"
import { $ } from "bun"
import { watch } from "fs"

export function useGitBranch() {
const [branch, setBranch] = createSignal<string>("")

createEffect(async () => {
const gitCheck = await $`git rev-parse --is-inside-work-tree`
.cwd(process.cwd())
.quiet()
.nothrow()
if (gitCheck.exitCode === 0) {
const b = await $`git branch --show-current`.cwd(process.cwd()).quiet().nothrow().text()
setBranch(b.trim())

// Set up watcher for .git/HEAD
const gitHeadPath = `${process.cwd()}/.git/HEAD`
const watcher = watch(gitHeadPath, { persistent: false }, async () => {
const newBranch = await $`git branch --show-current`
.cwd(process.cwd())
.quiet()
.nothrow()
.text()
setBranch(newBranch.trim())
})
onCleanup(() => watcher.close())
}
})

return { branch }
}