Alternate screen size support.
This is a relatively big new feature, which introduces small breaking changes to the API: * NegotiateTelnet() now returns (DevInfo, error) instead of just error. The function signature for the Tx type now has one additional DevInfo parameter. * RunTransactions() requires one additional parameter, the DevInfo (which is allowed to be nil). Otherwise, existing behavior continues to work as-is and everything still defaults to operating on the default 24x80 terminal size. See example5 for a larger-terminal-aware application. Pending some time to make sure no new bugs cropped up in this release and that the alternate screen size support works in the wild, I anticipate this will become the v1.0.0 release of go3270.
This commit is contained in:
1 parent
3a38ce6e4a
commit
b6fa48f37f
19 files changed
+820
-126
No files matched your search
+23
-10
@@ -7,30 +7,43 @@ package go3270
|
||||
import "net"
|
||||
|
||||
// Tx is a function that serves as one transaction in a go3270 application.
|
||||
// The Tx function is called with the network connection to the client, and a
|
||||
// "data" value provided by the previous transaction. Tx functions return the
|
||||
// next transaction to run (or nil to indicate the RunTransactions() function
|
||||
// should terminate), the data to pass into the next transaction, and any
|
||||
// error. If the error is non-nil, the RunTransactions() function will
|
||||
// terminate and return the err. A non-nil error is _not_ passed between
|
||||
// transactions, it terminates transaction processing.
|
||||
type Tx func(conn net.Conn, data any) (next Tx, newdata any, err error)
|
||||
// The Tx function is called with the network connection to the client, the
|
||||
// DevInfo for use with alternate screen writes, and a "data" value provided
|
||||
// by the previous transaction. Tx functions return the next transaction to
|
||||
// run (or nil to indicate the RunTransactions() function should terminate),
|
||||
// the data to pass into the next transaction, and any error. If the error is
|
||||
// non-nil, the RunTransactions() function will terminate and return the err.
|
||||
// A non-nil error is _not_ passed between transactions, it terminates
|
||||
// transaction processing.
|
||||
type Tx func(conn net.Conn, dev DevInfo, data any) (
|
||||
next Tx, newdata any, err error)
|
||||
|
||||
// RunTransactions begins running transaction functions, starting with the
|
||||
// initial transaction, until a transaction eventually returns nil for the
|
||||
// next transaction, or until a transaction function returns a non-nil error
|
||||
// value. data (which may be nil, if the initial transaction does not require
|
||||
// data) is passed in as the data to the initial transaction.
|
||||
func RunTransactions(conn net.Conn, initial Tx, data any) error {
|
||||
//
|
||||
// dev is the DevInfo of the connected client, as obtained from
|
||||
// NegotiateTelnet(). It is safe to pass a nil DevInfo, in which case all
|
||||
// transactions will only be able to operate with the default 24x80 screen
|
||||
// size.
|
||||
func RunTransactions(conn net.Conn, dev DevInfo, initial Tx,
|
||||
data any) error {
|
||||
|
||||
var next Tx
|
||||
var err error
|
||||
|
||||
next = initial
|
||||
|
||||
if dev == nil {
|
||||
dev = &deviceInfo{rows: 24, cols: 80, termtype: "DEFAULT"}
|
||||
}
|
||||
|
||||
// We run transactions until there isn't a next transaction to run, or
|
||||
// an error.
|
||||
for {
|
||||
next, data, err = next(conn, data)
|
||||
next, data, err = next(conn, dev, data)
|
||||
if err != nil {
|
||||
// Error means we bail out and return the error to the caller.
|
||||
return err
|
||||
|
||||
Reference in new issue
Block a user