Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

1.1 KB
Raw Blame
import { useEffect, useRef, type RefObject } from 'react'
import { terminalCopyTrimsGutterRead } from '../transport/settings-read-operations'
import type { RpcClient } from '../transport/rpc-client'
import type { ConnectionState } from '../transport/types'

// Mirror desktop copy-gutter policy once per connection; mobile has no settings stream and defaults trimming on.
export function useTerminalCopyTrimsGutter(
  client: RpcClient | null,
  connState: ConnectionState
): RefObject<boolean> {
  const trimsGutterRef = useRef(true)

  useEffect(() => {
    if (!client || connState !== 'connected') {
      return
    }
    let stale = false
    void terminalCopyTrimsGutterRead
      .request(client)
      .then((response) => {
        if (stale) {
          return
        }
        const preference = terminalCopyTrimsGutterRead.interpret(response)
        if (preference.accepted) {
          trimsGutterRef.current = preference.value
        }
      })
      .catch(() => {
        // Keep default trimming when the host is unreachable.
      })
    return () => {
      stale = true
    }
  }, [client, connState])

  return trimsGutterRef
}