···1616 // Bell counter, captured by the bell handler closure.
1717 bellCount := 0
18181919- // We declare term here so the title_changed closure can capture it.
2020- var term *ghostty.Terminal
2121-2222- var err error
2323- term, err = ghostty.NewTerminal(
1919+ term, err := ghostty.NewTerminal(
2420 ghostty.WithSize(80, 24),
25212622 // write_pty: called when the terminal writes data back (e.g. query responses).
2727- ghostty.WithWritePty(func(data []byte) {
2323+ ghostty.WithWritePty(func(_ *ghostty.Terminal, data []byte) {
2824 fmt.Printf("write_pty: %d bytes: %q\n", len(data), data)
2925 }),
30263127 // bell: called on BEL (0x07).
3232- ghostty.WithBell(func() {
2828+ ghostty.WithBell(func(_ *ghostty.Terminal) {
3329 bellCount++
3430 fmt.Printf("bell: count=%d\n", bellCount)
3531 }),
36323733 // title_changed: called when the terminal title changes via OSC 0/2.
3838- ghostty.WithTitleChanged(func() {
3939- x, err := term.CursorX()
3434+ // The terminal is passed directly as a parameter.
3535+ ghostty.WithTitleChanged(func(t *ghostty.Terminal) {
3636+ x, err := t.CursorX()
4037 if err != nil {
4138 log.Fatal(err)
4239 }
+1-1
kitty_graphics_test.go
···4545 WithSize(80, 24),
4646 // Install a WritePty handler so the terminal can send
4747 // protocol responses (required for kitty graphics).
4848- WithWritePty(func(data []byte) {}),
4848+ WithWritePty(func(_ *Terminal, _ []byte) {}),
4949 )
5050 if err != nil {
5151 t.Fatal(err)
+18-10
terminal.go
···6868}
69697070// WritePtyFn is called when the terminal writes data back to the pty
7171-// (e.g. query responses). The data is only valid for the call duration.
7171+// (e.g. query responses). The first parameter is the terminal that
7272+// triggered the effect. The data is only valid for the call duration.
7273// C: GhosttyTerminalWritePtyFn
7373-type WritePtyFn func(data []byte)
7474+type WritePtyFn func(t *Terminal, data []byte)
74757576// BellFn is called when the terminal receives a BEL character (0x07).
7777+// The parameter is the terminal that triggered the effect.
7678// C: GhosttyTerminalBellFn
7777-type BellFn func()
7979+type BellFn func(t *Terminal)
78807981// TitleChangedFn is called when the terminal title changes via OSC 0/2.
8282+// The parameter is the terminal that triggered the effect.
8083// C: GhosttyTerminalTitleChangedFn
8181-type TitleChangedFn func()
8484+type TitleChangedFn func(t *Terminal)
82858386// EnquiryFn is called when the terminal receives ENQ (0x05).
8787+// The first parameter is the terminal that triggered the effect.
8488// Return the response bytes; nil or empty means no response.
8589// C: GhosttyTerminalEnquiryFn
8686-type EnquiryFn func() []byte
9090+type EnquiryFn func(t *Terminal) []byte
87918892// XtversionFn is called for XTVERSION queries (CSI > q).
9393+// The first parameter is the terminal that triggered the effect.
8994// Return the version string; empty uses the default "libghostty".
9095// C: GhosttyTerminalXtversionFn
9191-type XtversionFn func() string
9696+type XtversionFn func(t *Terminal) string
92979398// SizeFn is called for XTWINOPS size queries (CSI 14/16/18 t).
9999+// The first parameter is the terminal that triggered the effect.
94100// Return the size and true, or zero value and false to ignore the query.
95101// C: GhosttyTerminalSizeFn
9696-type SizeFn func() (SizeReportSize, bool)
102102+type SizeFn func(t *Terminal) (SizeReportSize, bool)
9710398104// ColorSchemeFn is called for color scheme queries (CSI ? 996 n).
105105+// The first parameter is the terminal that triggered the effect.
99106// Return the scheme and true, or zero value and false to ignore the query.
100107// C: GhosttyTerminalColorSchemeFn
101101-type ColorSchemeFn func() (ColorScheme, bool)
108108+type ColorSchemeFn func(t *Terminal) (ColorScheme, bool)
102109103110// DeviceAttributesFn is called for device attributes queries
104104-// (CSI c / CSI > c / CSI = c). Return the attributes and true,
111111+// (CSI c / CSI > c / CSI = c). The first parameter is the terminal
112112+// that triggered the effect. Return the attributes and true,
105113// or zero value and false to ignore the query.
106114// C: GhosttyTerminalDeviceAttributesFn
107107-type DeviceAttributesFn func() (DeviceAttributes, bool)
115115+type DeviceAttributesFn func(t *Terminal) (DeviceAttributes, bool)
108116109117// WithSize sets the terminal dimensions in cells.
110118// Both cols and rows must be greater than zero.
+8-8
terminal_effect.go
···115115func goWritePtyTrampoline(_ C.GhosttyTerminal, userdata unsafe.Pointer, data *C.uint8_t, length C.size_t) {
116116 t := terminalFromUserdata(userdata)
117117 if t.onWritePty != nil {
118118- t.onWritePty(C.GoBytes(unsafe.Pointer(data), C.int(length)))
118118+ t.onWritePty(t, C.GoBytes(unsafe.Pointer(data), C.int(length)))
119119 }
120120}
121121···123123func goBellTrampoline(_ C.GhosttyTerminal, userdata unsafe.Pointer) {
124124 t := terminalFromUserdata(userdata)
125125 if t.onBell != nil {
126126- t.onBell()
126126+ t.onBell(t)
127127 }
128128}
129129···131131func goTitleChangedTrampoline(_ C.GhosttyTerminal, userdata unsafe.Pointer) {
132132 t := terminalFromUserdata(userdata)
133133 if t.onTitleChanged != nil {
134134- t.onTitleChanged()
134134+ t.onTitleChanged(t)
135135 }
136136}
137137···141141 if t.onEnquiry == nil {
142142 return C.GhosttyString{}
143143 }
144144- return t.effectString(t.onEnquiry())
144144+ return t.effectString(t.onEnquiry(t))
145145}
146146147147//export goXtversionTrampoline
···150150 if t.onXtversion == nil {
151151 return C.GhosttyString{}
152152 }
153153- return t.effectString([]byte(t.onXtversion()))
153153+ return t.effectString([]byte(t.onXtversion(t)))
154154}
155155156156//export goSizeTrampoline
···159159 if t.onSize == nil {
160160 return C.bool(false)
161161 }
162162- size, ok := t.onSize()
162162+ size, ok := t.onSize(t)
163163 if !ok {
164164 return C.bool(false)
165165 }
···176176 if t.onColorScheme == nil {
177177 return C.bool(false)
178178 }
179179- scheme, ok := t.onColorScheme()
179179+ scheme, ok := t.onColorScheme(t)
180180 if !ok {
181181 return C.bool(false)
182182 }
···190190 if t.onDeviceAttributes == nil {
191191 return C.bool(false)
192192 }
193193- attrs, ok := t.onDeviceAttributes()
193193+ attrs, ok := t.onDeviceAttributes(t)
194194 if !ok {
195195 return C.bool(false)
196196 }