From 72db0fdc0eac62f86a771859877c8d7765e80a16 Mon Sep 17 00:00:00 2001 From: "Matthew R. Wilson" Date: Fri, 23 May 2025 14:01:20 -0700 Subject: [PATCH] Add optional callback function to ScreenOpts --- screen.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/screen.go b/screen.go index b07b828..c0065f3 100644 --- a/screen.go +++ b/screen.go @@ -114,6 +114,19 @@ type ScreenOpts struct { // CursorCol sets the column (0-indexed) to position the cursor after // sending the screen, when NoClear is false. Maximum value is 79. CursorCol int + + // PostSendCallback is a function that, if non-nil, will be called after + // go3270 sends the datastream to the client, but before it blocks to + // read the response (if NoResponse is true, the callback will still be + // called before returning). If the function returns an error, then + // the ShowScreenOpts() function will return the error instead of a + // response. The value of CallbackData will be passed as the argument to + // the function. + PostSendCallback func(any) error + + // CallbackData is passed as the argument to the PostSendCallback + // function. + CallbackData any } // fieldmap is a map of field buffer addresses and the corresponding field @@ -157,6 +170,13 @@ func ShowScreenOpts(screen Screen, values map[string]string, conn net.Conn, return resp, err } + // Call the optional callback function after sending the screen. + if opts.PostSendCallback != nil { + if err := opts.PostSendCallback(opts.CallbackData); err != nil { + return resp, err + } + } + if !opts.NoResponse { resp, err = readResponse(conn, fm) if err != nil {