Documentation
¶
Overview ¶
Package ibmterm is a library to write servers for IBM block-mode terminals: the 3270 (TN3270) and the 5250 (TN5250). A program builds a Screen from fields and shows it with ShowScreenOpts, HandleScreen or RunTransactions. The Terminal from tn3270.NegotiateTelnet or tn5250.NegotiateTelnet changes the Screen into the data stream of its terminal type, so the program does not need to know which type it serves.
Index ¶
- Variables
- func Debugf(format string, a ...any)
- func RunTransactions(conn net.Conn, term Terminal, initial Tx, data any) error
- func SetCodepage(cs Codepage)
- type Codepage
- func Codepage037() Codepage
- func Codepage273() Codepage
- func Codepage275() Codepage
- func Codepage277() Codepage
- func Codepage278() Codepage
- func Codepage280() Codepage
- func Codepage284() Codepage
- func Codepage285() Codepage
- func Codepage297() Codepage
- func Codepage424() Codepage
- func Codepage500() Codepage
- func Codepage803() Codepage
- func Codepage870() Codepage
- func Codepage871() Codepage
- func Codepage875() Codepage
- func Codepage880() Codepage
- func Codepage924() Codepage
- func Codepage1026() Codepage
- func Codepage1047() Codepage
- func Codepage1140() Codepage
- func Codepage1141() Codepage
- func Codepage1142() Codepage
- func Codepage1143() Codepage
- func Codepage1144() Codepage
- func Codepage1145() Codepage
- func Codepage1146() Codepage
- func Codepage1147() Codepage
- func Codepage1148() Codepage
- func Codepage1149() Codepage
- func Codepage1160() Codepage
- func CodepageBracket() Codepage
- func CodepageByID(id int) Codepage
- func CodepageFor(opts ScreenOpts) Codepage
- type Color
- type Field
- type FieldRules
- type Highlight
- type Key
- type Kind
- type ReadFunc
- type Response
- type Rules
- type Screen
- type ScreenOpts
- type Terminal
- type Tx
- type Validator
Constants ¶
This section is empty.
Variables ¶
var Debug io.Writer
Debug, if not nil, gets the debug output of the library and of the tn3270 and tn5250 packages.
var ErrNoTerminal = errors.New("ibmterm: no terminal")
ErrNoTerminal is the error when a function gets a nil Terminal.
Functions ¶
func RunTransactions ¶
RunTransactions runs the transactions, starting with initial, until a transaction returns a nil next transaction or a non-nil error. data is the data for the initial transaction (it can be nil). term is the Terminal from tn3270.NegotiateTelnet or tn5250.NegotiateTelnet. It must not be nil.
func SetCodepage ¶
func SetCodepage(cs Codepage)
SetCodepage sets the codepage/character set that the library uses. This is a global setting. Set it when the program starts, and do not change it after that. It is not a setting for each connection.
The code page of a Terminal, or ScreenOpts.Codepage, has priority over this setting.
Types ¶
type Codepage ¶
type Codepage interface {
// Decode converts a slice of EBCDIC bytes into a UTF-8 string.
Decode(e []byte) string
// Encode converts a UTF-8 string into a slice of EBCDIC bytes.
Encode(s string) []byte
// ID returns the name of this codepage. Usually a numeric string like
// "037" or "1047", but could also be a name such as "bracket" if IBM has
// not assigned a number to the particular codepage.
ID() string
}
Implementations of Codepage provide EBCDIC<->UTF-8 translation. By default, the library uses CP 1047. You may alternatively set a different codepage using the SetCodepage() function during your application initialization.
func Codepage037 ¶
func Codepage037() Codepage
Codepage037 returns the IBM CP 037 code page (United States/Canada).
func Codepage273 ¶
func Codepage273() Codepage
Codepage273 returns the IBM CP 273 code page (Germany/Austria).
func Codepage275 ¶
func Codepage275() Codepage
Codepage275 returns the IBM CP 275 code page (Brazil).
func Codepage277 ¶
func Codepage277() Codepage
Codepage277 returns the IBM CP 277 code page (Denmark/Norway).
func Codepage278 ¶
func Codepage278() Codepage
Codepage278 returns the IBM CP 278 code page (Finland/Sweden).
func Codepage280 ¶
func Codepage280() Codepage
Codepage280 returns the IBM CP 280 code page (Italy).
func Codepage284 ¶
func Codepage284() Codepage
Codepage284 returns the IBM CP 284 code page (Spain/Latin America).
func Codepage285 ¶
func Codepage285() Codepage
Codepage285 returns the IBM CP 285 code page (United Kingdom).
func Codepage297 ¶
func Codepage297() Codepage
Codepage297 returns the IBM CP 297 code page (France).
func Codepage424 ¶
func Codepage424() Codepage
Codepage424 returns the IBM CP 424 code page (Hebrew).
func Codepage500 ¶
func Codepage500() Codepage
Codepage500 returns the IBM CP 500 code page (International).
func Codepage803 ¶
func Codepage803() Codepage
Codepage803 returns the IBM CP 803 code page (Hebrew, old code).
func Codepage870 ¶
func Codepage870() Codepage
Codepage870 returns the IBM CP 870 code page (Latin-2 multilingual).
func Codepage871 ¶
func Codepage871() Codepage
Codepage871 returns the IBM CP 871 code page (Iceland).
func Codepage875 ¶
func Codepage875() Codepage
Codepage875 returns the IBM CP 875 code page (Greek).
func Codepage880 ¶
func Codepage880() Codepage
Codepage880 returns the IBM CP 880 code page (Cyrillic multilingual).
func Codepage924 ¶
func Codepage924() Codepage
Codepage924 returns the IBM CP 924 code page (Latin-9).
func Codepage1026 ¶
func Codepage1026() Codepage
Codepage1026 returns the IBM CP 1026 code page (Turkey).
func Codepage1047 ¶
func Codepage1047() Codepage
Codepage1047 returns the IBM CP 1047 code page (Latin-1/Open Systems), the default of the library.
func Codepage1140 ¶
func Codepage1140() Codepage
Codepage1140 returns the IBM CP 1140 code page: CP 037 (United States/Canada) with the euro sign.
func Codepage1141 ¶
func Codepage1141() Codepage
Codepage1141 returns the IBM CP 1141 code page: CP 273 (Germany/Austria) with the euro sign.
func Codepage1142 ¶
func Codepage1142() Codepage
Codepage1142 returns the IBM CP 1142 code page: CP 277 (Denmark/Norway) with the euro sign.
func Codepage1143 ¶
func Codepage1143() Codepage
Codepage1143 returns the IBM CP 1143 code page: CP 278 (Finland/Sweden) with the euro sign.
func Codepage1144 ¶
func Codepage1144() Codepage
Codepage1144 returns the IBM CP 1144 code page: CP 280 (Italy) with the euro sign.
func Codepage1145 ¶
func Codepage1145() Codepage
Codepage1145 returns the IBM CP 1145 code page: CP 284 (Spain/Latin America) with the euro sign.
func Codepage1146 ¶
func Codepage1146() Codepage
Codepage1146 returns the IBM CP 1146 code page: CP 285 (United Kingdom) with the euro sign.
func Codepage1147 ¶
func Codepage1147() Codepage
Codepage1147 returns the IBM CP 1147 code page: CP 297 (France) with the euro sign.
func Codepage1148 ¶
func Codepage1148() Codepage
Codepage1148 returns the IBM CP 1148 code page: CP 500 (International) with the euro sign.
func Codepage1149 ¶
func Codepage1149() Codepage
Codepage1149 returns the IBM CP 1149 code page: CP 871 (Iceland) with the euro sign.
func Codepage1160 ¶
func Codepage1160() Codepage
Codepage1160 returns the IBM CP 1160 code page (Thai, with the euro sign).
func CodepageBracket ¶
func CodepageBracket() Codepage
CodepageBracket returns the "bracket" code page, c/x3270's default: CP 037 with [, ], Ý and ¨ where CP 1047 has them.
func CodepageByID ¶
CodepageByID returns the code page with the IBM code page number id (for example 37 or 1047), or nil if the library does not have it.
func CodepageFor ¶
func CodepageFor(opts ScreenOpts) Codepage
CodepageFor returns the code page for text to and from the client: opts.Codepage, else the code page of the Terminal, else the default code page. The tn3270 and tn5250 packages use it.
type Color ¶
type Color byte
Color is the color of a field. On a 5250 the tn5250 package changes it to the nearest 5250 attribute.
type Field ¶
type Field struct {
// Row is the row, 0-based, that the field attribute character should
// begin at. When using the standard screen of 24 rows, Row must be 0-23.
// When writing to the alternate screen, Row may be up to 1 less than the
// number of rows on the screen.
Row int
// Col is the column, 0-based, that the field attribute character should
// begin at. When using the standard screen of 80 columns, Col must be
// 0-79. When writing to the alternate screen, Col may be up to 1 less
// than the number of columns on the screen.
Col int
// Text is the content of the field to display.
Content string
// PositionOnly will use a Set Buffer Address (SBA) command to move the
// cursor to the position, but not insert a new attribute byte. The only
// properties of the Field that will apply if PositionOnly is true are:
// Row, Col, Content, Name. Others will be silently ignored.
PositionOnly bool
// Write allows the user to edit the value of the field.
Write bool
// Autoskip causes protected (Write = false) fields to automatically be
// skipped and the cursor should move to the next field upon encountering
// this field. Autoskip is ignored on fields with Write = true.
Autoskip bool
// Intense indicates this field should be displayed with high intensity.
Intense bool
// Hidden indicates the field content should not be displayed (e.g. a
// password input field).
Hidden bool
// NumericOnly indicates that only numbers may be entered into the field.
// Few clients obey it, so always validate the input on the server too.
NumericOnly bool
// Color is the field color. The default value is the default color.
Color Color
// Highlighting is the highlight attribute for the field. The default value
// is the default (i.e. no) highlighting.
Highlighting Highlight
// AttributeOnly will cause this "field" (which won't really be a new
// field) to use the SA (Set Attribute) 3270 command to change the color
// and highlighting of the text WITHOUT starting a new field. You can
// create a field at Row 5, Column 10, with AttributeOnly true, and the
// text will start in Roe 5, Column 10 and not skip a space to column 11
// like a new field would when AttributeOnly is false.
//
// If AttributeOnly is true, the Write, Autoskip, Intense, Hidden, and
// NumericOnly properties will have no effect. Only Highlighting and Color
// will affect the output, and will both default to Default (e.g. default
// highlighting and default color) if not specificed in this field.
//
// After using AttributeOnly to change color and highlighting, you may
// need to explicitly use another AttributeOnly "field" to reset to
// defaults, a regular (AttributeOnly = false) field may not end the
// attributes. (See example1.)
//
// A 5250 has no Set Attribute order: the tn5250 package writes only the
// text of an AttributeOnly field, with no attribute.
AttributeOnly bool
// Name is the name of this field, which is used to get the user-entered
// data. All writeable fields on a screen must have a unique name.
// Protected fields may also have a name to populate them dynamically when
// the screen is sent.
Name string
// CharSet is the local ID of the character set the field is shown in:
// 0 for the default; a programmed symbol set's LCID (see LoadPS). It is
// sent as an extended field attribute (SFE type 0x43), so it ends with
// the field; with AttributeOnly, as a Set Attribute (SA type 0x43),
// which lasts until another changes it (see DefaultCharSet).
// A 5250 has no programmed symbols: the tn5250 package ignores CharSet.
CharSet byte
// DefaultCharSet, with AttributeOnly, sets the character set back to
// the default (SA type 0x43, 0) for the characters after it.
DefaultCharSet bool
// Raw, if not nil, is sent as the field's content as it is, instead of
// Content encoded in the code page: the code points of programmed
// symbols (0x41 to 0xFE) in a CharSet field. Values in the values map do
// not replace it. The tn5250 package does not write Raw content.
Raw []byte
// KeepSpaces will prevent the strings.TrimSpace() function from being
// called on the field value. Generally you want leading and trailing
// spaces trimmed from fields in 3270 before processing, but if you are
// building a whitespace-sensitive application, you can ask for the
// original, un-trimmed value for a field by setting this to true.
KeepSpaces bool
}
Field is a field on the screen. A field starts with an attribute character, which takes one position on the screen. The text of the field starts in the next position.
type FieldRules ¶
type FieldRules struct {
// MustChange, when true, indicates that the value of the field MUST be
// altered by the user -- if applied to a field with no starting value,
// this makes the field a required field. If true on a field with a
// starting value (either in the field's Content attribute, or with an
// override in the initial values map), then the user must change
// the value from the default.
MustChange bool
// ErrorText is the text displayed with the MustChange validation fails.
// If ErrorText is the empty string, but MustValidation fails, an error
// string will be constructed from the field name: "Please enter a valid
// value for <fieldName>."
ErrorText string
// Validator is a function to validate the value the user input into the
// field. It may be nil if no validation is required. The Validator
// function is called *after* the MustChange logic, so if you wish to
// fully handle validation, ensure MustChange is set to false.
Validator Validator
// Reset indicates that if the screen fails validation, this field should
// always be reset to its original/default value, regardless of what the
// user entered.
Reset bool
}
FieldRules provides the validation rules for a particular field.
type Highlight ¶
type Highlight byte
Highlight is the highlight of a field. A 5250 has ReverseVideo and Underscore, and Blink on red fields only.
type Key ¶
type Key int
Key is a key that sends the screen to the host: an attention identifier (AID). The tn3270 and tn5250 packages change the AID bytes of their data streams to these values. On a 3270, F1 to F24 are the PF1 to PF24 keys.
const ( KeyNone Key = iota // no key KeyEnter // Enter (3270), Enter or Field Exit (5250) KeyF1 KeyF2 KeyF3 KeyF4 KeyF5 KeyF6 KeyF7 KeyF8 KeyF9 KeyF10 KeyF11 KeyF12 KeyF13 KeyF14 KeyF15 KeyF16 KeyF17 KeyF18 KeyF19 KeyF20 KeyF21 KeyF22 KeyF23 KeyF24 KeyPA1 // PA1 (3270 only) KeyPA2 // PA2 (3270 only) KeyPA3 // PA3 (3270 only) KeyClear // Clear KeyPageUp // Roll Down, also Page Up (5250 only) KeyPageDown // Roll Up, also Page Down (5250 only) KeyHelp // Help (5250 only) KeyPrint // Print (5250 only) KeyAttn // Attention (5250 only) KeySysReq // System Request (5250 only) KeyRecordBackspace // Record Backspace (5250 only) )
The keys.
type Kind ¶
type Kind int
Kind is the type of block-mode terminal: a 3270 or a 5250.
The terminal kinds.
type ReadFunc ¶
ReadFunc reads the response of the client to a screen that Terminal.WriteScreen sent.
type Response ¶
type Response struct {
// Key is the key that the user pressed.
Key Key
// Row is the row of the cursor (0-based).
Row int
// Col is the column of the cursor (0-based).
Col int
// Values are the values of the input fields, by field name.
Values map[string]string
}
Response is the data that the client sent for a screen.
func HandleScreen ¶
func HandleScreen(screen Screen, rules Rules, values map[string]string, keys, exitkeys []Key, errorField string, crow, ccol int, conn net.Conn, term Terminal) (Response, error)
HandleScreen shows the screen and waits for a response, again and again, until the response obeys the rules. It returns when the user presses a key in keys and all the fields obey the rules, or when the user presses a key in exitkeys.
- screen is the Screen to show (see ShowScreenOpts).
- rules are the rules for the fields, by field name.
- values are the start values of fields (see ShowScreenOpts).
- keys are the keys that submit the screen. The fields must obey the rules for these keys.
- exitkeys are the keys that return at once, with no check.
- errorField is the name of the field that shows the error message when a response does not obey the rules.
- crow and ccol are the start position of the cursor.
- conn is the connection to the client.
- term is the Terminal from the telnet negotiation.
For other keys, HandleScreen shows the screen again with the message "<key>: unknown key" in errorField.
func ShowScreenOpts ¶
func ShowScreenOpts(screen Screen, values map[string]string, conn net.Conn, opts ScreenOpts) (Response, error)
ShowScreenOpts sends the screen to the client with opts, and (unless opts.NoResponse is true) waits for the response of the client.
The library ignores fields that are not in the screen. If a named field has an entry in values, the library shows that value and not the Content of the field. values can be nil.
If opts.NoClear is false, the library clears the screen first and puts the cursor at opts.CursorRow and opts.CursorCol. If opts.NoClear is true, the new screen goes on top of the screen that the client shows now.
The library removes the leading and trailing spaces from the values in the response, except for fields with KeepSpaces.
Do not change the input fields from a different goroutine while a call waits for a response: the response then does not agree with the fields.
type Rules ¶
type Rules map[string]FieldRules
Rules is a map of field names (strings) to FieldRules structs. Each field for which you wish validation to occur must appear in the map. Fields not in the map will not have any input validation performed.
type Screen ¶
type Screen []Field
Screen is the list of the Fields of a screen. No checking is performed for lack of overlapping fields, unique field names, fields out of bounds of the screen size (these will simply be omitted from the datastream), etc.
type ScreenOpts ¶
type ScreenOpts struct {
// Terminal is the terminal from the telnet negotiation. It sets the
// data stream, the screen size and the default code page. It must not
// be nil. Field positions must be in the screen of Terminal.Size().
Terminal Terminal
// Codepage is the code page for the text to and from the client. If
// it is nil, the code page of the Terminal applies. If that is also
// nil, the default code page (see SetCodepage) applies.
Codepage Codepage
// NoResponse will draw the screen and immediately return, without
// waiting for any input data from the remote client.
NoResponse bool
// NoClear will send the data stream to the remote client without
// clearing the screen first. Existing data will be overlayed with
// the current screen.
NoClear bool
// CursorRow is the row (0-based) of the cursor after the screen, when
// NoClear is false.
CursorRow int
// CursorCol is the column (0-based) of the cursor after the screen,
// when NoClear is false.
CursorCol int
// PostSendCallback is a function that, if non-nil, will be called after
// the library 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
}
ScreenOpts are the options that callers may set when sending a screen to the client.
type Terminal ¶
type Terminal interface {
// Kind tells if the terminal is a 3270 or a 5250.
Kind() Kind
// TerminalType is the terminal type that the client sent, for
// example "IBM-3278-2-E" or "IBM-3477-FC".
TerminalType() string
// Size is the number of rows and columns of the screen that
// ShowScreenOpts writes to. For a 3270 it is the alternate screen
// size, for a 5250 it is 24x80 or 27x132.
Size() (rows, cols int)
// Codepage is the EBCDIC code page of the client. It is nil if the
// client did not tell its code page. Then the default code page
// (see SetCodepage) applies.
Codepage() Codepage
// Color tells if the terminal shows colors. On a terminal without
// colors, Field.Color changes only the intensity.
Color() bool
// WriteScreen sends the screen to the client in the data stream of
// the terminal. When opts.NoResponse is false, the ReadFunc that it
// returns reads the response of the client. Most programs use
// ShowScreenOpts and not WriteScreen.
WriteScreen(conn net.Conn, screen Screen, values map[string]string,
opts ScreenOpts) (ReadFunc, error)
}
Terminal is a connected block-mode terminal. The tn3270 and tn5250 packages make the Terminal after the telnet negotiation.
type Tx ¶
Tx is one transaction of an application. RunTransactions calls it with the connection to the client, the Terminal that the telnet negotiation returned, and the data from the previous transaction. A Tx returns the next transaction (nil to stop), the data for the next transaction, and an error. A non-nil error stops RunTransactions, and RunTransactions returns it.
type Validator ¶
Validator is a type that represents a function which can perform field input validation. The function is passed a string, input, and returns true if the input is valid or false if the not.
var IsInteger Validator = func(input string) bool { input = strings.TrimSpace(input) return isIntegerRegexp.MatchString(input) }
IsInteger is a Validator that returns true if, after spaces are trimmed from the beginning and end if the string, the value is an integer (including negative numbers and 0).
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
gfxtest
command
Command gfxtest is a TN3270 server for debugging 3270 graphics on an emulator: it shows what the terminal reported (its query replies), draws vector bitmaps (Object Picture structured fields, GDDM-style image orders) in several ways, sends structured fields typed in hex, and logs every byte each way, the graphics orders and the terminal's structured field replies decoded.
|
Command gfxtest is a TN3270 server for debugging 3270 graphics on an emulator: it shows what the terminal reported (its query replies), draws vector bitmaps (Object Picture structured fields, GDDM-style image orders) in several ways, sends structured fields typed in hex, and logs every byte each way, the graphics orders and the terminal's structured field replies decoded. |
|
tn5250test
command
Command tn5250test is a small TN5250 server to try the tn5250 package on a 5250 emulator (tn5250, tn5250j, IBM i Access Client Solutions).
|
Command tn5250test is a small TN5250 server to try the tn5250 package on a 5250 emulator (tn5250, tn5250j, IBM i Access Client Solutions). |
|
internal
|
|
|
codepage/generate
command
|
|
|
Package tn5250 is the IBM 5250 data stream for the ibmterm library: a TN5250 server (RFC 1205, RFC 2877, RFC 4777).
|
Package tn5250 is the IBM 5250 data stream for the ibmterm library: a TN5250 server (RFC 1205, RFC 2877, RFC 4777). |