@@ -1856,6 +1856,83 @@ func TestWindowOptionsReportTerminalLevel(t *testing.T) {
18561856 })
18571857}
18581858
1859+ // --- OnRequestSendFocus (DECSET 1004) tests ---
1860+
1861+ func TestOnRequestSendFocus (t * testing.T ) {
1862+ t .Parallel ()
1863+
1864+ t .Run ("fires_when_focus_reporting_enabled" , func (t * testing.T ) {
1865+ t .Parallel ()
1866+ h := newTestInputHandler (80 , 24 )
1867+ fired := 0
1868+ h .OnRequestSendFocusEmitter .Event (func (struct {}) {
1869+ fired ++
1870+ })
1871+
1872+ // Enable focus reporting (DECSET 1004).
1873+ h .ParseString ("\x1b [?1004h" )
1874+
1875+ if fired != 1 {
1876+ t .Errorf ("expected OnRequestSendFocus to fire once, got %d" , fired )
1877+ }
1878+ })
1879+
1880+ t .Run ("does_not_fire_when_focus_reporting_disabled" , func (t * testing.T ) {
1881+ t .Parallel ()
1882+ h := newTestInputHandler (80 , 24 )
1883+ fired := 0
1884+ h .OnRequestSendFocusEmitter .Event (func (struct {}) {
1885+ fired ++
1886+ })
1887+
1888+ // Disable focus reporting (DECRST 1004) without enabling first.
1889+ h .ParseString ("\x1b [?1004l" )
1890+
1891+ if fired != 0 {
1892+ t .Errorf ("expected OnRequestSendFocus not to fire, got %d" , fired )
1893+ }
1894+ })
1895+
1896+ t .Run ("fires_each_time_focus_reporting_enabled" , func (t * testing.T ) {
1897+ t .Parallel ()
1898+ h := newTestInputHandler (80 , 24 )
1899+ fired := 0
1900+ h .OnRequestSendFocusEmitter .Event (func (struct {}) {
1901+ fired ++
1902+ })
1903+
1904+ // Enable, disable, enable again.
1905+ h .ParseString ("\x1b [?1004h" )
1906+ h .ParseString ("\x1b [?1004l" )
1907+ h .ParseString ("\x1b [?1004h" )
1908+
1909+ if fired != 2 {
1910+ t .Errorf ("expected OnRequestSendFocus to fire twice, got %d" , fired )
1911+ }
1912+ })
1913+ }
1914+
1915+ func TestOnRequestSendFocusTerminalLevel (t * testing.T ) {
1916+ t .Parallel ()
1917+
1918+ t .Run ("DECSET_1004_forwarded_to_terminal" , func (t * testing.T ) {
1919+ t .Parallel ()
1920+ term := newTestTerminal (80 , 24 )
1921+ defer term .Dispose ()
1922+
1923+ fired := false
1924+ d := term .OnRequestSendFocus (func () {
1925+ fired = true
1926+ })
1927+ defer d .Dispose ()
1928+
1929+ term .WriteString ("\x1b [?1004h" )
1930+ if ! fired {
1931+ t .Fatal ("Terminal.OnRequestSendFocus not fired for DECSET 1004" )
1932+ }
1933+ })
1934+ }
1935+
18591936// --- VtExtensions gating tests ---
18601937
18611938func TestVtExtensions_Win32InputModeGating (t * testing.T ) {
0 commit comments