From 513d9f73d51ede2b3cda822be9ee5eceb59db10e Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 10:33:27 +0000 Subject: [PATCH] docs: rewrite README, usage, code pages, graphics, references and API intro in Simplified Technical English Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01B82eRRRR4BV2CBsQMqfrT6 Signed-off-by: Claude --- README.md | 30 ++++++----- docs/README.md | 7 +-- docs/api.md | 2 +- docs/codepages.md | 20 ++++---- docs/graphics.md | 118 +++++++++++++++++++++++-------------------- docs/references.md | 7 ++- docs/usage.md | 14 ++--- tools/apiref/main.go | 4 +- 8 files changed, 110 insertions(+), 92 deletions(-) diff --git a/README.md b/README.md index 018d43c..1b653fa 100644 --- a/README.md +++ b/README.md @@ -2,19 +2,20 @@ # go3270 -A Go library for writing TN3270 servers: build 3270 data streams from -fields and read back the attention key and the values the user typed. +A Go library to write TN3270 servers. It builds 3270 data streams from +fields. It reads back the attention key and the values that the user typed. -This is the D-Modem suite's fork of [racingmars/go3270](https://github.com/racingmars/go3270) -by Matthew R. Wilson, kept API-compatible with it. [bbs](https://github.com/D-Modem/bbs) -uses it for its TN3270 callers. +This is the fork of [racingmars/go3270](https://github.com/racingmars/go3270) +by Matthew R. Wilson for the D-Modem suite. Its API stays compatible with the +API of racingmars/go3270. [bbs](https://github.com/D-Modem/bbs) uses it for +its TN3270 callers. - Screens from fields, with `ShowScreenOpts()`, `HandleScreen()` and `RunTransactions()` -- Telnet negotiation, terminal size detection and larger-than-24x80 screens -- 31 EBCDIC code pages, detected from the client, plus graphic escape (code page 310) -- In this fork: every query reply kept, programmed symbols, native 3270 vector graphics and images -- In this fork: IND$FILE file transfer (DFT), the host's side -- `cmd/gfxtest`, a TN3270 server for trying graphics on an emulator +- Telnet negotiation, detection of the terminal size, and screens larger than 24x80 +- 31 EBCDIC code pages, detected from the client, and graphic escape (code page 310) +- In this fork: the library keeps all query replies. Programmed symbols, native 3270 vector graphics and images +- In this fork: IND$FILE file transfer (DFT), the side of the host +- `cmd/gfxtest`, a TN3270 server to try graphics on an emulator ## Quick start @@ -24,9 +25,9 @@ uses it for its TN3270 callers. import "github.com/D-Modem/go3270" ``` -then see `example1` to `example5`; `example4` shows the recommended -`RunTransactions()` structure. Code that imported -`github.com/racingmars/go3270` changes only its import path. +Then refer to `example1` to `example5`. `example4` shows the recommended +`RunTransactions()` structure. If your code imported +`github.com/racingmars/go3270`, change only its import path. ## Documentation @@ -34,6 +35,7 @@ The documentation is also a website, [d-modem.github.io/go3270](https://d-modem. - [docs/](docs/README.md): usage, code pages, graphics and IND$FILE, references - [API reference](https://pkg.go.dev/github.com/D-Modem/go3270) +- [Documentation style](docs/STYLE.md): the rules for ASD-STE100 Simplified Technical English ## The D-Modem suite @@ -49,4 +51,4 @@ The documentation is also a website, [d-modem.github.io/go3270](https://d-modem. ## Licence -AGPL-3.0-only ([LICENSE](LICENSE)), or a commercial licence from the D-Modem Authors ([COMMERCIAL-LICENSE.md](COMMERCIAL-LICENSE.md)). The code from upstream stays under its MIT licence ([LICENSE-MIT](LICENSE-MIT)) as well; each file's `SPDX-License-Identifier` line says which it holds. Contributions come with a contributor agreement ([CONTRIBUTING.md](CONTRIBUTING.md)). +AGPL-3.0-only ([LICENSE](LICENSE)), or a commercial licence from the D-Modem Authors ([COMMERCIAL-LICENSE.md](COMMERCIAL-LICENSE.md)). The code from upstream stays under its MIT licence ([LICENSE-MIT](LICENSE-MIT)) as well. The `SPDX-License-Identifier` line of each file tells which licence applies to it. Contributions come with a contributor agreement ([CONTRIBUTING.md](CONTRIBUTING.md)). diff --git a/docs/README.md b/docs/README.md index 65431b0..880908c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,7 +1,8 @@ # go3270 documentation -- [Using go3270](usage.md): the examples and the recommended `RunTransactions()` approach +- [Using go3270](usage.md): the examples and the recommended `RunTransactions()` method - [Code page support](codepages.md): code page detection, the supported code pages, graphic escape - [Graphics, query replies and IND$FILE](graphics.md): what this fork adds, and `cmd/gfxtest` -- [3270 references](references.md): the tutorials, RFCs and IBM references the library is built from -- [API reference](api.md): every exported name and its doc comment, made from the code (`tools/apiref`); also `go doc github.com/D-Modem/go3270` and [pkg.go.dev](https://pkg.go.dev/github.com/D-Modem/go3270) +- [3270 references](references.md): the tutorials, RFCs and IBM references that the library is built from +- [API reference](api.md): each exported name and its doc comment, made from the code (`tools/apiref`). Also refer to `go doc github.com/D-Modem/go3270` and [pkg.go.dev](https://pkg.go.dev/github.com/D-Modem/go3270) +- [Documentation style](STYLE.md): the rules for ASD-STE100 Simplified Technical English diff --git a/docs/api.md b/docs/api.md index c99b9d8..65beb67 100644 --- a/docs/api.md +++ b/docs/api.md @@ -2,7 +2,7 @@ # API reference -Package `go3270`'s exported API, from its doc comments (what `go doc -all` and [pkg.go.dev](https://pkg.go.dev/github.com/D-Modem/go3270) show). +The exported API of package `go3270`, from its doc comments (the same text that `go doc -all` and [pkg.go.dev](https://pkg.go.dev/github.com/D-Modem/go3270) show). import "github.com/D-Modem/go3270" diff --git a/docs/codepages.md b/docs/codepages.md index cfb5286..304c3ce 100644 --- a/docs/codepages.md +++ b/docs/codepages.md @@ -1,12 +1,14 @@ # Code page support -When clients connect, the `NegotiateTelnet()` function returns an implementation of the `DevInfo` interface. That interface has a `DevInfo.Codepage()` method, which returns an implementation of the `Codepage` interface for the detected client code page if known and supported (`nil` otherwise). The `ScreenOpts` structure you provide to the `ShowScreenOpts()` function has a `Codepage` field, which is where you provide `DevInfo.Codepage()` to ensure the UTF-8–EBCDIC translation is correct for the particular client. If `ScreenOpts.Codepage` is `nil` (either because you don't set it, or if `DevInfo.Codepage()` returns `nil`), then go3270 will use its global default code page for that interaction with the client. The global default is the CP1047 code page. +When a client connects, the `NegotiateTelnet()` function returns an implementation of the `DevInfo` interface. That interface has a `DevInfo.Codepage()` method. This method returns an implementation of the `Codepage` interface for the detected code page of the client, if the code page is known and supported (`nil` if not). The `ScreenOpts` structure that you give to the `ShowScreenOpts()` function has a `Codepage` field. Put `DevInfo.Codepage()` in this field, to make sure that the UTF-8–EBCDIC translation is correct for that client. -All of the examples under this repository demonstrate the correct handling of code pages -- the `DevInfo` is remembered from the telnet negotiation, and `DevInfo.Codepage()` is passed to all screen send and receive calls. +If `ScreenOpts.Codepage` is `nil` (because you do not set it, or because `DevInfo.Codepage()` returns `nil`), go3270 uses its global default code page for that interaction with the client. The global default is the CP1047 code page. -You may change the global code page default by calling the SetCodepage() function during your application initialization (this should be set before you use the library for handling any client connections; this is a global setting, not a per-connection setting). SetCodepage() accepts a Codepage interface, which provides methods to encode Go UTF-8 strings to EBCDIC, and decode EBCDIC byte slices to Go UTF-8 strings. +All the examples in this repository show the correct handling of code pages. They keep the `DevInfo` from the telnet negotiation, and give `DevInfo.Codepage()` to all screen send and receive calls. -go3270 currently provides the following codepage functions, covering all single-byte code pages supported by x3270 v4.3ga10: +To change the global default code page, call the SetCodepage() function when your application initializes. Call it before you use the library for client connections. This is a global setting, not a setting for each connection. SetCodepage() accepts a Codepage interface. This interface has methods that encode Go UTF-8 strings to EBCDIC, and decode EBCDIC byte slices to Go UTF-8 strings. + +go3270 now has these codepage functions. They cover all the single-byte code pages that x3270 v4.3ga10 supports: * `Codepage037()` * `Codepage273()` @@ -39,11 +41,11 @@ go3270 currently provides the following codepage functions, covering all single- * `Codepage1149()` * `Codepage1160()` -Additionally, the default x3270 family code page (closest to CP 1047, with with `^` and `¬` swapped back to where they are in CP 37), `CodepageBracket()`. (Note that x3270 does not report a different code page ID between CP37 and "bracket". Since "bracket" is the default code page for x3270, go3270 will assume that if the client is in the x3270 family and the codepage is 37, "bracket" is the correct code page to use.) +There is also `CodepageBracket()`, the default code page of the x3270 family. It is almost the same as CP 1047, but `^` and `¬` are at their positions in CP 37. (x3270 reports the same code page ID for CP37 and "bracket". "bracket" is the default code page for x3270. Thus, if the client is in the x3270 family and the codepage is 37, go3270 uses "bracket".) -If there are other standard EBCDIC code pages that you would like support for, let me know. +If you need support for other standard EBCDIC code pages, tell the maintainers. -To configure go3270 to use one of the codepages by default, you may do something like: +To configure go3270 to use one of the codepages by default, use code similar to this example: ``` import ( @@ -55,6 +57,6 @@ func init() { } ``` -With the new codepage detection support, you shouldn't typically rely on the default codepage: you should always pass the `DevInfo.Codepage()` value to the `ShowScreenOpts()` function or as the last optional argument to the `HandleScreen()` or `HandleScreenAlt()` functions. The global default should only be a fallback if the client code page isn't detected correctly. +The library detects the codepage of the client. Thus, do not use the default codepage as your usual method. Always give the `DevInfo.Codepage()` value to the `ShowScreenOpts()` function, or as the last optional argument to the `HandleScreen()` or `HandleScreenAlt()` functions. Use the global default only as a fallback, if the library does not detect the code page of the client correctly. -Additionally, most characters from the "graphic escape" code page 310 are supported in all of the go3270-provided codepage implementations. Correct display on the client will depend on its support of graphic escape and correct characters being available in its font. The `DevInfo.SupportsGE()` function returns a boolean indicating that the client supports the graphic escape alternate code page. Use the corresponding Unicode characters in your Go UTF-8 strings and they will be sent as the EBCDIC two-byte sequence of 0x08 followed by the position in code page 310. GE sequences are also processed on incoming field values. +All the codepage implementations of go3270 also support most characters from the "graphic escape" code page 310. For a correct display, the client must support graphic escape, and its font must have the correct characters. The `DevInfo.SupportsGE()` function returns a boolean that tells if the client supports the graphic escape alternate code page. Use the related Unicode characters in your Go UTF-8 strings. The library sends them as the EBCDIC two-byte sequence of 0x08, followed by the position in code page 310. The library also processes GE sequences in incoming field values. diff --git a/docs/graphics.md b/docs/graphics.md index 9bc61a5..3f105d2 100644 --- a/docs/graphics.md +++ b/docs/graphics.md @@ -1,81 +1,89 @@ # Graphics, query replies and IND$FILE -What this fork adds over [racingmars/go3270](https://github.com/racingmars/go3270). +This page tells what this fork adds to [racingmars/go3270](https://github.com/racingmars/go3270). -This fork keeps every query reply the client sends during -`NegotiateTelnet()` and adds 3270 graphics: +This fork keeps each query reply that the client sends during +`NegotiateTelnet()`. It also adds 3270 graphics: * `DevInfo.QueryReply(qcode)` and `DevInfo.QueryCodes()` return the raw - query replies; `DevInfo.CellSize()` is the character cell in pels; - `DevInfo.SymbolSets()` describes the client's character sets and - programmed symbol support; `DevInfo.SupportsVectorGraphics()` reports - the Segment query reply (0xB0), sent or listed in the Summary. Replies - the Summary lists that did not come with the Query are asked for with - a Query List: IBM Personal Communications sends its graphics replies - (Segment, Graphic Color and the rest) only then. + query replies. `DevInfo.CellSize()` is the character cell in pels. + `DevInfo.SymbolSets()` describes the character sets of the client and + its support for programmed symbols. `DevInfo.SupportsVectorGraphics()` + reports the Segment query reply (0xB0), if the client sent it or listed + it in the Summary. If the Summary lists replies that did not come with + the Query, the library asks for them with a Query List. IBM Personal + Communications sends its graphics replies (Segment, Graphic Color and + the other replies) only after a Query List. * `LoadPS` builds the Load Programmed Symbols structured field (formats 1 - and 3) from `Symbol` bitmaps, and `WriteStructuredFields()` sends it. - A `Field` with `CharSet` set to the symbol set's LCID and `Raw` set to - the symbols' code points shows them. + and 3) from `Symbol` bitmaps. `WriteStructuredFields()` sends it. To + show the symbols, use a `Field` with `CharSet` set to the LCID of the + symbol set and `Raw` set to the code points of the symbols. * `ImagePicture()` builds an Object Picture structured field that draws bitmaps with native 3270 vector graphics (experimental). - `ImagePictures()` crops each bitmap to what it draws, splits a picture - over 64K into several segments, and takes the mix: `MixOverpaint` for - an image as a bitmap a colour, which is what works on PCOMM (its - exclusive or does not combine blue with the other colours). - `GraphicColors()` is the terminal's graphics palette (its Graphic Color - reply, or the 8 base colours), and `DitherBitmaps()` turns an image - into a bitmap per colour of it, error-diffused, for `MixOverpaint`. + `ImagePictures()` crops each bitmap to the area that it draws. It splits + a picture larger than 64K into many segments. It also accepts the mix. + Use `MixOverpaint` to send an image as one bitmap for each colour. This + mix operates correctly on PCOMM (the exclusive or of PCOMM does not + combine blue with the other colours). + `GraphicColors()` is the graphics palette of the terminal (its Graphic + Color reply, or the 8 base colours). `DitherBitmaps()` changes an image + into one bitmap for each of its colours, error-diffused, for + `MixOverpaint`. -The x3270 family supports none of these; IBM Personal Communications, -HostExplorer and Quick3270 do. The formats are from +The x3270 family does not support these functions. IBM Personal +Communications, HostExplorer and Quick3270 support them. The formats are from [GA23-0059-07][ga23-07] (5.13, 5.38, 6.12, 6.51) and Greg Price's [3270 Graphics][grfx]. -`cmd/gfxtest` is a TN3270 server for trying the graphics on an emulator: +`cmd/gfxtest` is a TN3270 server to try the graphics on an emulator: go run ./cmd/gfxtest -addr :3270 -image photo.png -log gfxtest.log -It shows what the terminal reported (its size, cell size, GE, the Segment -reply, programmed symbols, every query reply in hex). It draws test -pictures as Object Pictures: +It shows the data that the terminal reported (its size, cell size, GE, the +Segment reply, programmed symbols, each query reply in hex). It draws these +test pictures as Object Pictures: - * a one-plane test pattern; - * colour bars as three XOR planes, or as seven bitmaps; - * corner markers, to check the origin; - * the `-image` file, dithered to 8 colours. + * A one-plane test pattern. + * Colour bars as three XOR planes, or as seven bitmaps. + * Corner markers, to check the origin. + * The `-image` file, dithered to 8 colours. -The origin, position, size, mix, Erase/Reset, and whether the graphics come -before or after the screen are all settings on the menu. It also sends -structured fields typed in hex. +The menu has these settings: the origin, position, size, mix, Erase/Reset, +and the order of the graphics and the screen (before or after). The server +also sends structured fields that you type in hex. -With `-preview DIR`, each picture is also written to DIR as a PNG of what -the terminal should show, for comparison with what it does show. With mix -O the image goes as a bitmap per colour, overpainted, with no exclusive or, -diffused (Floyd-Steinberg) to the terminal's own palette from its Graphic -Color query reply: PCOMM's has 15 colours besides black (orange, purple, +With `-preview DIR`, the server also writes each picture to DIR as a PNG. +The PNG shows the expected result on the terminal. Compare it with the +result that the terminal shows. With mix O, the image goes as one bitmap +for each colour, overpainted, without exclusive or. It is diffused +(Floyd-Steinberg) to the palette of the terminal, from its Graphic Color +query reply. The palette of PCOMM has 15 colours and black (orange, purple, the dark shades, grey). A terminal without the reply gets the 8 base colours. -Test 9 sends a Query List for any replies the Summary lists but the -terminal didn't send (PCOMM lists its graphics replies but doesn't send -them for a plain Query). The -image test reports the file's size and format as decoded. +Test 9 sends a Query List for each reply that the Summary lists but the +terminal did not send. (PCOMM lists its graphics replies, but does not send +them for a plain Query.) The +image test reports the size and format of the file, as decoded. -Every record each way goes to the log, with the graphics orders and the -terminal's inbound structured fields decoded. A trace from an emulator -that draws nothing is the place to start. +Each record in each direction goes to the log, with the graphics orders and +the inbound structured fields of the terminal decoded. If an emulator draws +nothing, start with a trace from it. - * IND$FILE file transfer, the host's side, in DFT mode: `ParseIndFile()` - reads the `IND$FILE GET|PUT name options` command an emulator types, - `SendFileDFT()` and `ReceiveFileDFT()` move the file, `DFTMessage()` - ends with IND$FILE's message (`TRANS03 File transfer complete`), and - `DFTBufferSize()` tells whether the terminal does DFT at all. - `ReadRecord()` reads one inbound record, structured fields and all. - The layouts are a real TSO IND$FILE's, from x3270's test traces. + * IND$FILE file transfer, the side of the host, in DFT mode: `ParseIndFile()` + reads the `IND$FILE GET|PUT name options` command that an emulator + types. `SendFileDFT()` and `ReceiveFileDFT()` move the file. + `DFTMessage()` ends with the message of IND$FILE + (`TRANS03 File transfer complete`). `DFTBufferSize()` tells if the + terminal supports DFT. `ReadRecord()` reads one inbound record, with its + structured fields. The layouts are the layouts of a real TSO IND$FILE, + from the test traces of x3270. -Fixes: a query reply too short to be one (length 0 to 3) no longer panics -`NegotiateTelnet()`, the query replies a client may send are limited to -16 KB, and encoded field text is telnet-escaped. +Fixes: + + * A query reply that is too short (length 0 to 3) does not cause a panic + in `NegotiateTelnet()` now. + * The query replies that a client can send are limited to 16 KB. + * The library telnet-escapes encoded field text. [ga23-07]: https://bitsavers.org/pdf/ibm/3174/GA23-0059-07_3270_Data_Stream_Programmers_Reference_199206.pdf [grfx]: https://www.prycroft6.com.au/misc/3270grfx.html diff --git a/docs/references.md b/docs/references.md index 4ab50f7..f97ac50 100644 --- a/docs/references.md +++ b/docs/references.md @@ -1,6 +1,11 @@ # 3270 references -I started learning about 3270 data streams from [Tommy Sprinkle's tutorial][sprinkle]. The tn3270 telnet negotiation is gleaned from [RFC 1576: TN3270 Current Practices][rfc1576], [RFC 1041: Telnet 3270 Regime Option][rfc1041], and [RFC 854: Telnet Protocol Specification][rfc854]. The IANA maintains a [useful reference of telnet option numbers][telnetOptions]. The reference I use for 3270 data streams is [the 1981 version from IBM][ibmref]. +The library is built from these references: + +- The first source for 3270 data streams: [Tommy Sprinkle's tutorial][sprinkle]. +- The tn3270 telnet negotiation: [RFC 1576: TN3270 Current Practices][rfc1576], [RFC 1041: Telnet 3270 Regime Option][rfc1041], and [RFC 854: Telnet Protocol Specification][rfc854]. +- The telnet option numbers: a [useful reference of telnet option numbers][telnetOptions] from the IANA. +- The reference for 3270 data streams: [the 1981 version from IBM][ibmref]. [sprinkle]: http://www.tommysprinkle.com/mvs/P3270/ [rfc1576]: https://tools.ietf.org/html/rfc1576 diff --git a/docs/usage.md b/docs/usage.md index 8b2f47d..fc47e15 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -2,20 +2,20 @@ **Project status:** This library has been used by a small number of projects, and I believe the overall functionality is sound and relatively bug-free. Feedback is appreciated. At this point, I will try not to make breaking changes to the API, but I have not yet declared the library to be at v1.0, so I make no promises. (upstream's note) -See the example folders for quick demonstrations of using the library: +The example folders show quick demonstrations of the library: * example1 uses the lower-level function ShowScreenOpts(). * example2 uses a higher-level convenience function HandleScreen(). - * example3 demonstrates updating the client's 3270 display while waiting for a response by using an update thread and a waiting response thread. - * example4 demonstrates the RunTransactions() approach to handing control from one screen to the next. This is the recommended way to build applications using go3270. - * example5 demonstrates support for larger-than-default (24x80) terminal sizes. + * example3 shows how to update the 3270 display of the client while the server waits for a response. It uses an update thread and a thread that waits for the response. + * example4 shows the RunTransactions() method, which gives control from one screen to the next. This is the recommended method to build applications with go3270. + * example5 shows the support for terminal sizes that are larger than the default (24x80). -For larger applications, I recommend using the `RunTransactions()` function to serve as the driver for your application. You can implement transaction functions which pass control from one transaction to another. example4 demonstrates a "larger" application that uses this approach. +For larger applications, use the `RunTransactions()` function as the driver of your application. You can write transaction functions that give control from one transaction to another. example4 shows a "larger" application that uses this method. -For an example of a complete application that handles multiple user sessions, adapts to different screen sizes, and with a nice written explanation of how the application is built, Moshix has created a [Minesweeper game][moshix-minesweeper] using go3270 to serve as a resource for the community to learn from. +Moshix made a [Minesweeper game][moshix-minesweeper] with go3270, as a resource for the community. It is an example of a complete application. It controls many user sessions and adapts to different screen sizes. It also has a good written explanation of how the application is built. [moshix-minesweeper]: https://github.com/moshix/minesweeper -Here's [a video introducing the library][introVideo] as well. +There is also [a video that introduces the library][introVideo]. [introVideo]: https://www.youtube.com/watch?v=h9XTjup5W5U diff --git a/tools/apiref/main.go b/tools/apiref/main.go index e68e0b3..da3428e 100644 --- a/tools/apiref/main.go +++ b/tools/apiref/main.go @@ -66,8 +66,8 @@ func reference(dir string) ([]byte, error) { r := &writer{fset: fset, pkg: pkg} r.printf("\n\n") r.printf("# API reference\n\n") - r.printf("Package `%s`'s exported API, from its doc comments (what `go doc -all` "+ - "and [pkg.go.dev](https://pkg.go.dev/github.com/D-Modem/go3270) show).\n\n", name) + r.printf("The exported API of package `%s`, from its doc comments (the same text "+ + "that `go doc -all` and [pkg.go.dev](https://pkg.go.dev/github.com/D-Modem/go3270) show).\n\n", name) r.printf(" import \"%s\"\n\n", pkg.ImportPath) r.text(pkg.Doc)