API reference¶
The exported API of package tn3270, from its doc comments (the same text that go doc -all and pkg.go.dev show).
import "github.com/D-Modem/go-ibmterm/tn3270"
Constants¶
const (
DDMSavePIF = "PCXFD001" // save the picture as a GDDM PIF file
DDMPrint = "PCXFD002" // print the picture
)
The names of the DDM files that tell the client what to do with the data that Transfer sends.
The planes of a triple-plane symbol set, for LoadPS.Plane.
AdvancedDOID is the Destination/Origin ID that the Advanced session uses unless the caller sets another. It is the display port (0003) of the Port query reply (B3) that PCOMM sends. This value is an estimate.
AdvancedMaxMessage is the most bytes of one Advanced message: the 10 13 header and every field after it. The WSF command and the Destination/Origin field are not counted. PCOMM reads a message into a buffer of this size.
AdvancedMaxSegment is the most bytes of drawing orders in one graphics segment in Advanced mode. Give it as PictureOptions.MaxSegment.
Variables¶
var (
// ErrAdvancedRejected is the error when the client refuses a message
// with an Exception/Status field (0F22).
ErrAdvancedRejected = errors.New("tn3270: the client rejected the Advanced graphics message")
// ErrAdvancedProtocol is the error when a reply is not as the
// Advanced protocol says.
ErrAdvancedProtocol = errors.New("tn3270: Advanced graphics protocol error")
// ErrAdvancedInterrupted is the error when the client sends an AID
// that is not a structured field (for example, the user pressed a key)
// while the server waits for a reply.
ErrAdvancedInterrupted = errors.New("tn3270: a key came while waiting for the Advanced graphics reply")
// ErrAdvancedTimeout is the error when no reply comes in time. The
// client is possibly not in Advanced mode.
ErrAdvancedTimeout = errors.New("tn3270: no Advanced graphics reply")
)
var (
ErrNoDFT = errors.New("the terminal does not do DFT file transfer")
ErrDFTProtocol = errors.New("DFT file transfer: unexpected reply")
ErrDFTAborted = errors.New("the transfer was cancelled at the terminal")
)
Errors of DFT transfers.
ErrNo3270 indicates that the telnet client did not respond properly to the options negotiation that are expected for a tn3270 client.
ErrTelnetError indicates an unexpected response was encountered in the telnet protocol.
ErrUnknownTerminal indicates the client did not identify itself as an IBM-3277, 3278, 3279, or IBM-DYNAMIC model. All modern tn3270 clients should report as IBM-3278 models or IBM-DYNAMIC.
Functions¶
ClearField¶
ClearField is an Object Control structured field (0F11) that clears the graphics (control 0A), from its ID on. Put it in front of a picture's fields to draw on a clear window.
DFTBufferSize¶
DFTBufferSize is the most the client takes in one DFT transmission, from its Distributed Data Management query reply; 0 if it has no DFT.
DFTMessage¶
DFTMessage ends a transfer with IND$FILE's message to the user: "TRANS03 File transfer complete" for success (the emulator shows its own), or e.g. "TRANS13 Error writing file to host: file transfer canceled". The message goes as ASCII, up to 80 characters.
ImagePicture¶
ImagePicture is an Object Picture structured field (GA23-0059 5.38), for WriteStructuredFields, that draws bitmaps with their top left corner at x, y: graphics coordinates, 0, 0 the middle of the screen, y upwards. Planes are combined by exclusive or, so a blue and a red plane make pink where both are on.
The orders inside (Begin Segment, Set Mix, Set Current Position, Set Color, Begin/Image Data/End Image) are 3270 native vector graphics as GDDM sends them; experimental: check DevInfo.SupportsVectorGraphics, and try it on your emulator.
ImagePictures¶
ImagePictures is Object Picture structured fields, for WriteStructuredFields, that draw bitmaps with their top left corner at x, y (graphics coordinates, 0, 0 the middle of the screen, y upwards), and the number of the next segment, for pictures sent with these.
Unlike ImagePicture, each bitmap is cropped to its pels that are on, and a picture too large for one segment (64K) is split into several, each in its own structured field, a bitmap into bands of rows if need be.
ModelOf¶
ModelOf returns the model number (1 to 5) in the terminal type ttype, for example 4 for "IBM-3278-4-E". It returns 0 if ttype has no model number from 1 to 5, for example for "IBM-DYNAMIC".
ReadRecord¶
ReadRecord reads one inbound 3270 record: the bytes up to IAC EOR, IAC IAC undone, other telnet commands dropped, waiting up to timeout.
ReceiveFileDFT¶
func ReceiveFileDFT(conn net.Conn, dev DevInfo, w io.Writer, maxBytes int64, timeout time.Duration) (int64, error)
ReceiveFileDFT receives the client's file (an IND$FILE PUT) into w, taking at most max bytes. It returns the bytes taken; the transfer is closed, but its closing message (DFTMessage) is the caller's to send.
SendFileDFT¶
SendFileDFT sends r to the client (an IND$FILE GET). It returns the bytes sent; the closing message (DFTMessage) is the caller's to send.
SplitPictureFields¶
SplitPictureFields cuts each Object Picture field (0F10, from its ID on) that holds a whole element and is too long for one message into pieces: first (flags 80), middle (00) and last (40). Each piece fits in a message with the header. It returns the other fields as they are.
UnNegotiateTelnet¶
UnNegotiateTelnet will naively (e.g. not checking client responses) attempt to restore the telnet options state to what it was before NegotiateTelnet() was called.
WriteStructuredFields¶
WriteStructuredFields sends a Write Structured Field command with the given structured fields. Each field is given from its SFID on; its length is put in front of it.
Types¶
Advanced¶
type Advanced struct {
// DOID is the Destination/Origin ID (AdvancedDOID if 0).
DOID uint16
// Extended sets the extended mode bit (byte 6, 0x08) in each header.
Extended bool
// NoAck asks the client not to acknowledge each message of a
// picture. With NoAck false, the server waits for an acknowledgement
// after each message but the last.
NoAck bool
// Timeout is how long to wait for a reply (10 seconds if 0).
Timeout time.Duration
// contains filtered or unexported fields
}
Advanced is an Advanced graphics session on a TN3270 connection. Make it with NewAdvanced. Do not use it from two goroutines at the same time.
NewAdvanced¶
NewAdvanced returns an Advanced graphics session on conn, a connection that NegotiateTelnet set up. It sends nothing.
Advanced.GraphicColors¶
GraphicColors is the client's graphics colors from its Advanced Graphic Color query reply (B4), or the 8 base colors if it sent none.
Advanced.Ports¶
Ports is the port IDs in the client's Port query replies (B3), in the order received. The display is usually port 0003. Use one as DOID.
Advanced.Query¶
Query asks the client for its Advanced query replies (Read Partition, Query, in the envelope) and keeps them. It returns ErrAdvancedTimeout if no reply comes: the client is possibly not set to Advanced mode.
Advanced.QueryReplies¶
QueryReplies is every Advanced query reply with QCODE q (the client sends some, such as Port, more than once), each from the QCODE on.
Advanced.QueryReply¶
QueryReply is the client's first Advanced query reply with QCODE q, from the QCODE on; nil if it sent none or Query was not called.
Advanced.Reset¶
Reset sends Erase/Reset (03): each graphics instance of the session starts again.
Advanced.SendPicture¶
SendPicture sends structured fields (from their ID on: Object Picture fields from ImagePictures, Object Control, Object Data) in as few messages as it can. It cuts long pictures with SplitPictureFields. The last message asks the client to repaint. Unless NoAck is true, it waits for an acknowledgement of each message before the last.
Advanced.Status¶
Status is the status word of the last reply of the client: 0 if all was correct, 0x0100 if the client found a bad sequence number and started again with the number that the server sent.
Advanced.Transfer¶
Transfer sends data to the client as the DDM file name: DDMSavePIF to save it as a GDDM PIF file, DDMPrint to print it. It opens the file, sends the data in as many inserts as it needs, and closes the file. Data is the bytes that a GDDM host sends for a picture; which form the client expects is not known for certain.
Bitmap¶
type Bitmap struct {
Color ibmterm.Color // Blue, Red, Pink, Green, Turquoise, Yellow or White
Rows []string
}
Bitmap is one plane of an image for ImagePicture: Rows of '#' (on) and anything else (off), all of the same length, drawn in Color.
DitherBitmaps¶
DitherBitmaps is img in the palette's colors (Floyd-Steinberg error diffusion), a Bitmap a color, each pel in one at most, black pels in none (the background shows): for ImagePictures with MixOverpaint, which draws them a pel for a pixel.
DDMError¶
type DDMError struct {
Verb byte // 0x00 Open, 0x47 Insert, 0x41 Close
Code uint16 // the client's error code
}
DDMError is the error when the client refuses a DDM request (the save or print of a picture). Code is the client's error code: 0x0100 unknown name, 0x0200 already open or not open, 0x4000 cancelled, 0x4700 write not complete, 0x6000 not supported.
DDMError.Error¶
Error gives the DDM verb and the error code in words.
DevInfo¶
type DevInfo interface {
ibmterm.Terminal
// DefaultSize is the number of rows and columns of the default
// screen: from the Implicit Partition query reply, else 24x80 (12x40
// or 12x80 on a model 1). It is never larger than Size.
DefaultSize() (rows, cols int)
// Model is the model number (1 to 5) in the terminal type, for
// example 4 for IBM-3278-4-E. It is 0 for IBM-DYNAMIC and for a
// terminal type with no model number.
Model() int
// SupportsGE returns true if the client indicated it supports graphic
// escape to code page 310.
SupportsGE() bool
// QueryReply returns the client's query reply with the given QCODE
// (0x81 Usable Area, 0x85 Character Sets, 0xB0 Segment, ...), from the
// QCODE byte on, or nil if the client sent none. The slice is a copy.
QueryReply(qcode byte) []byte
// QueryCodes lists the QCODEs of the query replies the client sent, in
// ascending order.
QueryCodes() []byte
// CellSize is the size of the default character cell in pels, from the
// Usable Area query reply (0, 0 if the client did not say).
CellSize() (width, height int)
// SymbolSets describes the client's character sets and its support for
// loading programmed symbols (see LoadPS), from the Character Sets query
// reply; nil if the client sent none.
SymbolSets() *SymbolSets
// SupportsVectorGraphics reports whether the client answered the query
// with the Segment query reply (0xB0), or lists it in its Summary
// reply, which means it takes graphics segments: vector graphics in
// Object Picture structured fields.
SupportsVectorGraphics() bool
}
DevInfo is a connected 3270. It is an ibmterm.Terminal, with the features that only a 3270 has.
A 3270 has a default screen (24x80 on models 2 to 5) and an alternate screen that can be larger (see ModelSizes). Terminal.Size is the alternate screen size, and DefaultSize is the default screen size. WriteScreen writes to the alternate screen with Erase/Write Alternate, or to the default screen with Erase/Write when ibmterm.ScreenOpts.DefaultScreen is true.
NegotiateTelnet¶
NegotiateTelnet will negotiate the options necessary for tn3270 on a new telnet connection, conn.
NewDevInfo¶
NewDevInfo makes a DevInfo for the terminal type ttype with no telnet negotiation, for tests and for a connection that was negotiated before. The screen sizes come from the model number in ttype (24x80 if it has none). The DevInfo has no query replies and no code page.
IndFile¶
type IndFile struct {
Get bool // GET: the host sends the file; PUT: the host receives it
Name string // the host file name, as typed
ASCII bool // ASCII (text) rather than binary
CRLF bool // CR LF line ends
Append bool // PUT appends to the host file
Options []string // all the options, upper case
}
IndFile is an IND$FILE command.
ParseIndFile¶
ParseIndFile parses "IND$FILE GET|PUT name [(] options" (TSO puts the options after the name; VM/CMS after a "("), case aside. A "(" within a name (a TSO member, 'USER.DATA(MEM)') stays in it.
LoadPS¶
type LoadPS struct {
RWS byte // the store: a loadable SymbolSet's RWS
LCID byte // the local ID to give it, 0x40 to 0xEF
First byte // the first symbol's code point, 0x41 to 0xFE
Clear bool // clear the store's other symbols
// Format is the data format: 1 (a 9 by 16 cell: 2 bytes of the left
// column, then 16 bytes of the other 8 columns, a byte a row) or 3
// (rows of Width pels, top to bottom). Check SymbolSets.SupportsFormat.
Format int
// Width and Height of a format 3 cell: the client's slot size, unless
// Extended.
Width, Height int
// Extended sends the extended form of Load PS, which tells the client
// Width and Height (SymbolSets.Extended must be true).
Extended bool
// Plane is the plane of a triple-plane (color) set the symbols are
// loaded into: PlaneBlue, PlaneRed or PlaneGreen; 0, all three (or a
// single-plane set). A plane needs the extended form, which it implies.
// A cell shows its planes' colors, added (blue and red make pink...),
// where its color attribute is White (neutral, X'F7'), GA23-0059 4.5.
Plane byte
Symbols []Symbol
}
LoadPS is the Load Programmed Symbols structured field (GA23-0059 5.13): Symbols loaded into the client's symbol store RWS, from code point First on, to be shown through the character set ID LCID.
LoadPS.StructuredField¶
StructuredField is the Load PS structured field, from its SFID on, for WriteStructuredFields.
Mix¶
Mix is how a picture's pels combine with what is already drawn.
const (
MixOverpaint Mix = 2 // the color drawn replaces what was there
MixXor Mix = 4 // exclusive or: a blue and a red plane make pink
)
Palette¶
Palette is a terminal's graphics colors: the color of each index (1 blue, 2 red, ... 7 white, and on some 8 to 15), 0 being the background.
GraphicColors¶
GraphicColors is the terminal's graphics colors: from its Graphic Color query reply (0xB4) if it sent one (IBM Personal Communications has 16: orange, purple, dark blue, green and turquoise, mustard and grey besides the 8), else the 8 base colors.
PictureOptions¶
type PictureOptions struct {
// Mix is how pels combine with what is drawn: MixOverpaint for an
// image with a bitmap a color, each pel in one (exclusive or does not
// combine blue with the other colors on IBM Personal Communications);
// MixXor if 0.
Mix Mix
// Segment is the number of the first graphics segment (named "B001"
// on): pictures sent together need segments of their own. 1 if 0.
Segment int
// MaxSegment is the most bytes of drawing orders in one segment. Use
// AdvancedMaxSegment for Advanced mode. 0xFFBF (the most a two-byte
// length holds here) if 0.
MaxSegment int
}
PictureOptions are ImagePictures' options.
ScreenSize¶
ScreenSize is the number of rows and columns of a 3270 screen.
ModelSizes¶
ModelSizes returns the default and the alternate screen sizes of the terminal type ttype, from its model number. ok is false if ttype has no model number from 1 to 5.
Symbol¶
Symbol is the picture of one programmed symbol: a row of text for each row of pels, top to bottom, '#' (or 'X', '1', '*') for a pel that is on, anything else for one that is off.
SymbolSet¶
type SymbolSet struct {
RWS byte // device specific ID: LoadPS.RWS for a loadable set
LCID byte // the local ID it has now (0xFF: none)
Loadable bool
Triple bool // triple plane (color) set
DBCS bool
// slot size, if the client gives one per set (0: SlotWidth/Height)
SlotWidth, SlotHeight int
CGCSGID uint32 // character set and code page
}
SymbolSet is one character set of a client.
SymbolSets¶
type SymbolSets struct {
// GraphicEscape: the alternate character set is reachable by GE.
GraphicEscape bool
// Loadable: the client takes the Load Programmed Symbols structured
// field. It can only be used if Sets has a Loadable set, too.
Loadable bool
// Extended: the extended form of Load PS (with the cell size) is
// supported.
Extended bool
// SizeMatch: a Load PS cell size must match the slot size exactly.
SizeMatch bool
// SlotWidth, SlotHeight: the default character slot, in pels.
SlotWidth, SlotHeight int
// Formats: bit i (counting from the most significant bit) set when Load
// PS format type i is supported. See SupportsFormat.
Formats uint32
// Sets are the character sets the client has, in the order it gave.
Sets []SymbolSet
}
SymbolSets is what a client's Character Sets query reply says about its character sets.
SymbolSets.LoadableSets¶
LoadableSets lists the sets that programmed symbols can be loaded into.
SymbolSets.SupportsFormat¶
SupportsFormat reports whether Load PS format type t is supported.