@@ -28,6 +28,7 @@ import {
2828} from "@opentui/core"
2929import { Prompt , type PromptRef } from "@tui/component/prompt"
3030import type { AssistantMessage , Part , ToolPart , UserMessage , TextPart , ReasoningPart } from "@opencode-ai/sdk/v2"
31+ import { parseDiffStats , formatDiffStats } from "@/cli/cmd/tui/util/diff"
3132import { useLocal } from "@tui/context/local"
3233import { Locale } from "@/util/locale"
3334import type { Tool } from "@/tool/tool"
@@ -1600,12 +1601,27 @@ function Bash(props: ToolProps<typeof BashTool>) {
16001601}
16011602
16021603function Write ( props : ToolProps < typeof WriteTool > ) {
1604+ const ctx = use ( )
16031605 const { theme, syntax } = useTheme ( )
1606+ const sync = useSync ( )
1607+
16041608 const code = createMemo ( ( ) => {
16051609 if ( ! props . input . content ) return ""
16061610 return props . input . content
16071611 } )
16081612
1613+ // Check if minimal mode is enabled
1614+ const diffDisplay = createMemo ( ( ) => sync . data . config . tui ?. diff_display ?? "full" )
1615+
1616+ // Calculate line count
1617+ const lineCount = createMemo ( ( ) => code ( ) . split ( "\n" ) . length )
1618+
1619+ // Expanded/collapsed state
1620+ const [ expanded , setExpanded ] = createSignal ( false )
1621+
1622+ // Should show collapsed view
1623+ const showCollapsed = createMemo ( ( ) => diffDisplay ( ) === "minimal" && ! expanded ( ) )
1624+
16091625 const diagnostics = createMemo ( ( ) => {
16101626 const filePath = Filesystem . normalizePath ( props . input . filePath ?? "" )
16111627 return props . metadata . diagnostics ?. [ filePath ] ?? [ ]
@@ -1614,24 +1630,56 @@ function Write(props: ToolProps<typeof WriteTool>) {
16141630 return (
16151631 < Switch >
16161632 < Match when = { props . metadata . diagnostics !== undefined } >
1617- < BlockTool title = { "# Wrote " + normalizePath ( props . input . filePath ! ) } part = { props . part } >
1618- < line_number fg = { theme . textMuted } minWidth = { 3 } paddingRight = { 1 } >
1619- < code
1620- conceal = { false }
1621- fg = { theme . text }
1622- filetype = { filetype ( props . input . filePath ! ) }
1623- syntaxStyle = { syntax ( ) }
1624- content = { code ( ) }
1625- />
1626- </ line_number >
1627- < Show when = { diagnostics ( ) . length } >
1628- < For each = { diagnostics ( ) } >
1629- { ( diagnostic ) => (
1630- < text fg = { theme . error } >
1631- Error [{ diagnostic . range . start . line } :{ diagnostic . range . start . character } ]: { diagnostic . message }
1632- </ text >
1633- ) }
1634- </ For >
1633+ < BlockTool
1634+ title = { "# Wrote " + normalizePath ( props . input . filePath ! ) }
1635+ part = { props . part }
1636+ onClick = { ( ) => {
1637+ if ( diffDisplay ( ) === "minimal" ) {
1638+ setExpanded ( ! expanded ( ) )
1639+ }
1640+ } }
1641+ >
1642+ < Show
1643+ when = { showCollapsed ( ) }
1644+ fallback = {
1645+ // Full content display (when expanded or full mode)
1646+ < >
1647+ < line_number fg = { theme . textMuted } minWidth = { 3 } paddingRight = { 1 } >
1648+ < code
1649+ conceal = { false }
1650+ fg = { theme . text }
1651+ filetype = { filetype ( props . input . filePath ! ) }
1652+ syntaxStyle = { syntax ( ) }
1653+ content = { code ( ) }
1654+ />
1655+ </ line_number >
1656+ < Show when = { diagnostics ( ) . length } >
1657+ < For each = { diagnostics ( ) } >
1658+ { ( diagnostic ) => (
1659+ < text fg = { theme . error } >
1660+ Error [{ diagnostic . range . start . line } :{ diagnostic . range . start . character } ]: { diagnostic . message }
1661+ </ text >
1662+ ) }
1663+ </ For >
1664+ </ Show >
1665+ </ >
1666+ }
1667+ >
1668+ { /* Collapsed view */ }
1669+ < box paddingLeft = { 3 } paddingTop = { 1 } paddingBottom = { 1 } >
1670+ < text fg = { theme . textMuted } >
1671+ { lineCount ( ) } lines [press Enter to expand]
1672+ </ text >
1673+ </ box >
1674+ < Show when = { diagnostics ( ) . length } >
1675+ < For each = { diagnostics ( ) } >
1676+ { ( diagnostic ) => (
1677+ < text fg = { theme . error } paddingLeft = { 1 } >
1678+ Error [{ diagnostic . range . start . line } :{ diagnostic . range . start . character } ]: { diagnostic . message }
1679+ </ text >
1680+ ) }
1681+ </ For >
1682+ </ Show >
16351683 </ Show >
16361684 </ BlockTool >
16371685 </ Match >
@@ -1781,6 +1829,21 @@ function Edit(props: ToolProps<typeof EditTool>) {
17811829
17821830 const diffContent = createMemo ( ( ) => props . metadata . diff )
17831831
1832+ // Check if minimal mode is enabled
1833+ const diffDisplay = createMemo ( ( ) => ctx . sync . data . config . tui ?. diff_display ?? "full" )
1834+
1835+ // Parse diff statistics
1836+ const diffStats = createMemo ( ( ) => {
1837+ if ( ! props . metadata . diff ) return null
1838+ return parseDiffStats ( props . metadata . diff )
1839+ } )
1840+
1841+ // Expanded/collapsed state
1842+ const [ expanded , setExpanded ] = createSignal ( false )
1843+
1844+ // Should show collapsed view
1845+ const showCollapsed = createMemo ( ( ) => diffDisplay ( ) === "minimal" && ! expanded ( ) )
1846+
17841847 const diagnostics = createMemo ( ( ) => {
17851848 const filePath = Filesystem . normalizePath ( props . input . filePath ?? "" )
17861849 const arr = props . metadata . diagnostics ?. [ filePath ] ?? [ ]
@@ -1790,39 +1853,74 @@ function Edit(props: ToolProps<typeof EditTool>) {
17901853 return (
17911854 < Switch >
17921855 < Match when = { props . metadata . diff !== undefined } >
1793- < BlockTool title = { "← Edit " + normalizePath ( props . input . filePath ! ) } part = { props . part } >
1794- < box paddingLeft = { 1 } >
1795- < diff
1796- diff = { diffContent ( ) }
1797- view = { view ( ) }
1798- filetype = { ft ( ) }
1799- syntaxStyle = { syntax ( ) }
1800- showLineNumbers = { true }
1801- width = "100%"
1802- wrapMode = { ctx . diffWrapMode ( ) }
1803- fg = { theme . text }
1804- addedBg = { theme . diffAddedBg }
1805- removedBg = { theme . diffRemovedBg }
1806- contextBg = { theme . diffContextBg }
1807- addedSignColor = { theme . diffHighlightAdded }
1808- removedSignColor = { theme . diffHighlightRemoved }
1809- lineNumberFg = { theme . diffLineNumber }
1810- lineNumberBg = { theme . diffContextBg }
1811- addedLineNumberBg = { theme . diffAddedLineNumberBg }
1812- removedLineNumberBg = { theme . diffRemovedLineNumberBg }
1813- />
1814- </ box >
1815- < Show when = { diagnostics ( ) . length } >
1816- < box >
1817- < For each = { diagnostics ( ) } >
1818- { ( diagnostic ) => (
1819- < text fg = { theme . error } >
1820- Error [{ diagnostic . range . start . line + 1 } :{ diagnostic . range . start . character + 1 } ]{ " " }
1821- { diagnostic . message }
1822- </ text >
1823- ) }
1824- </ For >
1856+ < BlockTool
1857+ title = { "← Edit " + normalizePath ( props . input . filePath ! ) }
1858+ part = { props . part }
1859+ onClick = { ( ) => {
1860+ if ( diffDisplay ( ) === "minimal" ) {
1861+ setExpanded ( ! expanded ( ) )
1862+ }
1863+ } }
1864+ >
1865+ < Show
1866+ when = { showCollapsed ( ) }
1867+ fallback = {
1868+ // Full diff display (when expanded or full mode)
1869+ < >
1870+ < box paddingLeft = { 1 } >
1871+ < diff
1872+ diff = { diffContent ( ) }
1873+ view = { view ( ) }
1874+ filetype = { ft ( ) }
1875+ syntaxStyle = { syntax ( ) }
1876+ showLineNumbers = { true }
1877+ width = "100%"
1878+ wrapMode = { ctx . diffWrapMode ( ) }
1879+ fg = { theme . text }
1880+ addedBg = { theme . diffAddedBg }
1881+ removedBg = { theme . diffRemovedBg }
1882+ contextBg = { theme . diffContextBg }
1883+ addedSignColor = { theme . diffHighlightAdded }
1884+ removedSignColor = { theme . diffHighlightRemoved }
1885+ lineNumberFg = { theme . diffLineNumber }
1886+ lineNumberBg = { theme . diffContextBg }
1887+ addedLineNumberBg = { theme . diffAddedLineNumberBg }
1888+ removedLineNumberBg = { theme . diffRemovedLineNumberBg }
1889+ />
1890+ </ box >
1891+ < Show when = { diagnostics ( ) . length } >
1892+ < box >
1893+ < For each = { diagnostics ( ) } >
1894+ { ( diagnostic ) => (
1895+ < text fg = { theme . error } >
1896+ Error [{ diagnostic . range . start . line + 1 } :{ diagnostic . range . start . character + 1 } ]{ " " }
1897+ { diagnostic . message }
1898+ </ text >
1899+ ) }
1900+ </ For >
1901+ </ box >
1902+ </ Show >
1903+ </ >
1904+ }
1905+ >
1906+ { /* Collapsed view */ }
1907+ < box paddingLeft = { 3 } paddingTop = { 1 } paddingBottom = { 1 } >
1908+ < text fg = { theme . textMuted } >
1909+ { formatDiffStats ( diffStats ( ) ! ) } [press Enter to expand]
1910+ </ text >
18251911 </ box >
1912+ < Show when = { diagnostics ( ) . length } >
1913+ < box paddingLeft = { 1 } >
1914+ < For each = { diagnostics ( ) } >
1915+ { ( diagnostic ) => (
1916+ < text fg = { theme . error } >
1917+ Error [{ diagnostic . range . start . line + 1 } :{ diagnostic . range . start . character + 1 } ]{ " " }
1918+ { diagnostic . message }
1919+ </ text >
1920+ ) }
1921+ </ For >
1922+ </ box >
1923+ </ Show >
18261924 </ Show >
18271925 </ BlockTool >
18281926 </ Match >
0 commit comments