diff --git a/graphics_test.go b/graphics_test.go index 0637524..99010e7 100644 --- a/graphics_test.go +++ b/graphics_test.go @@ -399,3 +399,20 @@ func TestImagePictures(t *testing.T) { } } } + +// TestAttributeCharSet: an AttributeOnly field's character set is a Set +// Attribute (0x43), and DefaultCharSet sets it back; none otherwise. +func TestAttributeCharSet(t *testing.T) { + for _, c := range []struct { + f Field + want []byte + }{ + {Field{AttributeOnly: true, Color: Red, CharSet: 0xc2}, []byte{0x28, 0x41, 0, 0x28, 0x42, 0xf2, 0x28, 0x43, 0xc2}}, + {Field{AttributeOnly: true, DefaultCharSet: true}, []byte{0x28, 0x41, 0, 0x28, 0x42, 0, 0x28, 0x43, 0}}, + {Field{AttributeOnly: true, Color: Blue}, []byte{0x28, 0x41, 0, 0x28, 0x42, 0xf1}}, + } { + if got := buildField(c.f); !bytes.Equal(got, c.want) { + t.Errorf("%+v: % x, want % x", c.f, got, c.want) + } + } +} diff --git a/screen.go b/screen.go index 944ca2a..9770fea 100644 --- a/screen.go +++ b/screen.go @@ -87,9 +87,14 @@ type Field struct { // 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. + // the field; with AttributeOnly, as a Set Attribute (SA type 0x43), + // which lasts until another changes it (see DefaultCharSet). 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 @@ -410,6 +415,11 @@ func buildField(f Field) []byte { buf.WriteByte(0x28) // sa - "set attribute" buf.WriteByte(0x42) buf.WriteByte(byte(f.Color)) + if f.CharSet != 0 || f.DefaultCharSet { + buf.WriteByte(0x28) // sa - "set attribute" + buf.WriteByte(0x43) + buf.WriteByte(f.CharSet) + } return buf.Bytes() }