Add ShowScreenNoResponse() function
This commit is contained in:
1 parent
21f273b327
commit
276144f363
3 files changed
+53
-21
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 Matthew R. Wilson
|
Copyright (c) 2020, 2025 Matthew R. Wilson
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/racingmars/go3270"
|
"github.com/racingmars/go3270"
|
||||||
)
|
)
|
||||||
@@ -63,6 +64,11 @@ var screen2 = go3270.Screen{
|
|||||||
{Row: 22, Col: 0, Content: "PF3 Exit"},
|
{Row: 22, Col: 0, Content: "PF3 Exit"},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var goodbyeScreen = go3270.Screen{
|
||||||
|
{Row: 0, Col: 27, Intense: true, Content: "3270 Example Application"},
|
||||||
|
{Row: 2, Col: 0, Content: "Thank you using this application. Goodbye."},
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
ln, err := net.Listen("tcp", ":3270")
|
ln, err := net.Listen("tcp", ":3270")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -111,6 +117,8 @@ mainLoop:
|
|||||||
|
|
||||||
// If the user pressed PF3, exit
|
// If the user pressed PF3, exit
|
||||||
if response.AID == go3270.AIDPF3 {
|
if response.AID == go3270.AIDPF3 {
|
||||||
|
go3270.ShowScreenNoResponse(goodbyeScreen, nil, 0, 0, conn)
|
||||||
|
time.Sleep(2 * time.Second)
|
||||||
break mainLoop
|
break mainLoop
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,6 +167,8 @@ mainLoop:
|
|||||||
|
|
||||||
// If the user pressed PF3, exit
|
// If the user pressed PF3, exit
|
||||||
if response.AID == go3270.AIDPF3 {
|
if response.AID == go3270.AIDPF3 {
|
||||||
|
go3270.ShowScreenNoResponse(goodbyeScreen, nil, 0, 0, conn)
|
||||||
|
time.Sleep(2 * time.Second)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// This file is part of https://github.com/racingmars/go3270/
|
// This file is part of https://github.com/racingmars/go3270/
|
||||||
// Copyright 2020 by Matthew R. Wilson, licensed under the MIT license. See
|
// Copyright 2020, 2025 by Matthew R. Wilson, licensed under the MIT license.
|
||||||
// LICENSE in the project root for license information.
|
// See LICENSE in the project root for license information.
|
||||||
|
|
||||||
package go3270
|
package go3270
|
||||||
|
|
||||||
@@ -106,10 +106,47 @@ type fieldmap map[int]string
|
|||||||
// field. The values map may be nil if no overrides are needed. After writing
|
// field. The values map may be nil if no overrides are needed. After writing
|
||||||
// the fields, the cursor is set to crow, ccol, which are 0-based positions:
|
// the fields, the cursor is set to crow, ccol, which are 0-based positions:
|
||||||
// row 0-23 and col 0-79. Errors from conn.Write() are returned if
|
// row 0-23 and col 0-79. Errors from conn.Write() are returned if
|
||||||
// encountered.
|
// encountered. ShowScreen will wait for the client to provide data before
|
||||||
|
// returning, and the data from the client will be returned as a Response.
|
||||||
func ShowScreen(screen Screen, values map[string]string, crow, ccol int,
|
func ShowScreen(screen Screen, values map[string]string, crow, ccol int,
|
||||||
conn net.Conn) (Response, error) {
|
conn net.Conn) (Response, error) {
|
||||||
|
|
||||||
|
fm, err := showScreenInternal(screen, values, crow, ccol, conn)
|
||||||
|
if err != nil {
|
||||||
|
return Response{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
response, err := readResponse(conn, fm)
|
||||||
|
if err != nil {
|
||||||
|
return response, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strip leading+trailing spaces from field values
|
||||||
|
for _, fld := range screen {
|
||||||
|
if !fld.KeepSpaces {
|
||||||
|
if _, ok := response.Values[fld.Name]; ok {
|
||||||
|
response.Values[fld.Name] =
|
||||||
|
strings.TrimSpace(response.Values[fld.Name])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return response, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShowScreenNoResponse writes the screen to the connection, just like
|
||||||
|
// ShowScreen(), but immediately returns instead of waiting for data
|
||||||
|
// from the client.
|
||||||
|
func ShowScreenNoResponse(screen Screen, values map[string]string,
|
||||||
|
crow, ccol int, conn net.Conn) error {
|
||||||
|
|
||||||
|
_, err := showScreenInternal(screen, values, crow, ccol, conn)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func showScreenInternal(screen Screen, values map[string]string,
|
||||||
|
crow, ccol int, conn net.Conn) (fieldmap, error) {
|
||||||
|
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
var fm = make(fieldmap) // field buffer positions -> name
|
var fm = make(fieldmap) // field buffer positions -> name
|
||||||
|
|
||||||
@@ -162,25 +199,10 @@ func ShowScreen(screen Screen, values map[string]string, crow, ccol int,
|
|||||||
// Now write the datastream to the writer, returning any potential error.
|
// Now write the datastream to the writer, returning any potential error.
|
||||||
debugf("sending datastream: %x\n", b.Bytes())
|
debugf("sending datastream: %x\n", b.Bytes())
|
||||||
if _, err := conn.Write(b.Bytes()); err != nil {
|
if _, err := conn.Write(b.Bytes()); err != nil {
|
||||||
return Response{}, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := readResponse(conn, fm)
|
return fm, nil
|
||||||
if err != nil {
|
|
||||||
return response, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Strip leading+trailing spaces from field values
|
|
||||||
for _, fld := range screen {
|
|
||||||
if !fld.KeepSpaces {
|
|
||||||
if _, ok := response.Values[fld.Name]; ok {
|
|
||||||
response.Values[fld.Name] =
|
|
||||||
strings.TrimSpace(response.Values[fld.Name])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return response, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// sba is the "set buffer address" 3270 command.
|
// sba is the "set buffer address" 3270 command.
|
||||||
|
|||||||
Reference in new issue
Block a user