diff --git a/example1/example1.go b/example1/example1.go index 61e32b5..8774449 100644 --- a/example1/example1.go +++ b/example1/example1.go @@ -40,9 +40,19 @@ var screen1 = go3270.Screen{ {Row: 8, Col: 6, Intense: true, Content: "enter"}, {Row: 8, Col: 12, Content: "to submit your name."}, {Row: 10, Col: 0, Intense: true, Color: go3270.Red, Name: "errormsg"}, // a blank field for error messages - {Row: 14, Col: 0, Content: "Detected code page:"}, - {Row: 14, Col: 20, Name: "codepage"}, - {Row: 15, Col: 0, Content: "The following should be left and right square brackets: [ ]"}, + + // Demonstrate the AttributeOnly property: + {Row: 12, Col: 0, Content: "Demonstration of AttributeOnly to change format without a new field:"}, + {Row: 13, Col: 1, AttributeOnly: true, Color: go3270.Green, Content: "████"}, + {Row: 13, Col: 5, AttributeOnly: true, Color: go3270.Yellow, Content: "████"}, + {Row: 13, Col: 9, AttributeOnly: true, Color: go3270.Red, Content: "████"}, + {Row: 13, Col: 13, AttributeOnly: true, Color: go3270.Red, Highlighting: go3270.Blink, Content: "████"}, + // When using extended attributes, need to explicitly reset to defaults, the next field won't necessarily clear the attributes out. + {Row: 13, Col: 17, AttributeOnly: true, Color: go3270.DefaultColor, Highlighting: go3270.DefaultHighlight}, + + {Row: 15, Col: 0, Content: "Detected code page:"}, + {Row: 15, Col: 20, Name: "codepage"}, + {Row: 16, Col: 0, Content: "The following should be left and right square brackets: [ ]"}, {Row: 22, Col: 0, Content: "PF3 Exit"}, } diff --git a/screen.go b/screen.go index cc71387..57bb82e 100644 --- a/screen.go +++ b/screen.go @@ -54,6 +54,24 @@ type Field struct { // 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.) + 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 @@ -355,9 +373,21 @@ func sba(row, col, cols int) []byte { } // buildField will return either an sf or sfe command depending for the -// field. +// field, or an sa if only setting attributes. func buildField(f Field) []byte { var buf bytes.Buffer + + if f.AttributeOnly { + buf.WriteByte(0x28) // sa - "set attribute" + // We will always set both highlighting and color bytes + buf.WriteByte(0x41) + buf.WriteByte(byte(f.Highlighting)) + buf.WriteByte(0x28) // sa - "set attribute" + buf.WriteByte(0x42) + buf.WriteByte(byte(f.Color)) + return buf.Bytes() + } + if f.Color == DefaultColor && f.Highlighting == DefaultHighlight { // this is a traditional field, issue a normal sf command buf.WriteByte(0x1d) // sf - "start field"