Implement dup and field mark

This commit is contained in:
Andrew Kay
2020-01-05 14:37:45 -06:00
parent c373457dff
commit 274b1a18a2
3 changed files with 31 additions and 3 deletions

View File

@@ -6,9 +6,10 @@ oec.tn3270
import logging
from tn3270 import Telnet, Emulator, AttributeCell, CharacterCell, AID, OperatorError, \
ProtectedCellOperatorError, FieldOverflowOperatorError
from tn3270.ebcdic import DUP, FM
from .session import Session, SessionDisconnectedError
from .display import encode_ebcdic_character, encode_string
from .display import encode_ascii_character, encode_ebcdic_character, encode_string
from .keyboard import Key, get_ebcdic_character_for_key
AID_KEY_MAP = {
@@ -126,6 +127,10 @@ class TN3270Session(Session):
self._handle_insert_key()
elif key == Key.DELETE:
self.emulator.delete()
elif key == Key.DUP:
self.emulator.dup()
elif key == Key.FIELD_MARK:
self.emulator.field_mark()
else:
byte = get_ebcdic_character_for_key(key)
@@ -163,7 +168,7 @@ class TN3270Session(Session):
if isinstance(cell, AttributeCell):
byte = self._map_attribute(cell.attribute)
elif isinstance(cell, CharacterCell):
byte = encode_ebcdic_character(cell.byte)
byte = self._map_character(cell.byte)
self.terminal.display.buffered_write(byte, index=address)
@@ -204,6 +209,15 @@ class TN3270Session(Session):
return 0xc0
def _map_character(self, byte):
if byte == DUP:
return encode_ascii_character(ord('*'))
if byte == FM:
return encode_ascii_character(ord(';'))
return encode_ebcdic_character(byte)
def _format_message_area(self):
message_area = b''

View File

@@ -2,7 +2,7 @@ ptyprocess==0.6.0
pycoax==0.2.0
pyserial==3.4
pyte==0.8.0
pytn3270==0.4.0
pytn3270==0.5.0
sliplib==0.3.0
sortedcontainers==2.1.0
wcwidth==0.1.7

View File

@@ -183,6 +183,20 @@ class SessionHandleKeyTestCase(unittest.TestCase):
# Assert
self.session.emulator.delete.assert_called()
def test_dup(self):
# Act
self.session.handle_key(Key.DUP, KeyboardModifiers.NONE, None)
# Assert
self.session.emulator.dup.assert_called()
def test_field_mark(self):
# Act
self.session.handle_key(Key.FIELD_MARK, KeyboardModifiers.NONE, None)
# Assert
self.session.emulator.field_mark.assert_called()
def test_input(self):
# Act
self.session.handle_key(Key.LOWER_A, KeyboardModifiers.NONE, None)