<s> from __future__ import print_function <EOL> import sys <EOL> sys . path . insert ( <NUM_LIT:0> , '<STR_LIT>' ) <EOL> from charCodeMapping import CHAR_TO_CODE <EOL> ATTRIBUTE_SYMBOL_MAPPING = { <EOL> <NUM_LIT:0> : '<STR_LIT:U+0020>' , <EOL> <NUM_LIT:1> : '<STR_LIT:U+0020>' , <EOL> <NUM_LIT:2> : '<STR_LIT:B>' , <EOL> <NUM_LIT> : '<STR_LIT:_>' , <EOL> <NUM_LIT:3> : '<STR_LIT>' , <EOL> <NUM_LIT:4> : '<STR_LIT:R>' , <EOL> <NUM_LIT:5> : '<STR_LIT:?>' , <EOL> <NUM_LIT:6> : '<STR_LIT:!>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT:7> : '<STR_LIT:?>' , <EOL> } <EOL> class ScreenForTest ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , charInputs , maxX , maxY ) : <EOL> self . maxX = maxX <EOL> self . maxY = maxY <EOL> self . cursorX = <NUM_LIT:0> <EOL> self . cursorY = <NUM_LIT:0> <EOL> self . output = { } <EOL> self . pastScreens = [ ] <EOL> self . charInputs = charInputs <EOL> self . erase ( ) <EOL> self . currentAttribute = <NUM_LIT:0> <EOL> def getmaxyx ( self ) : <EOL> return ( self . maxY , self . maxX ) <EOL> def refresh ( self ) : <EOL> if self . containsContent ( self . output ) : <EOL> self . pastScreens . append ( dict ( self . output ) ) <EOL> def containsContent ( self , screen ) : <EOL> for coord , pair in screen . items ( ) : <EOL> ( char , attr ) = pair <EOL> if char : <EOL> return True <EOL> return False <EOL> def erase ( self ) : <EOL> self . output = { } <EOL> for x in range ( self . maxX ) : <EOL> for y in range ( self . maxY ) : <EOL> coord = ( x , y ) <EOL> self . output [ coord ] = ( '<STR_LIT>' , <NUM_LIT:1> ) <EOL> def move ( self , y , x ) : <EOL> self . cursorY = y <EOL> self . cursorX = x <EOL> def attrset ( self , attr ) : <EOL> self . currentAttribute = attr <EOL> def addstr ( self , y , x , string , attr = None ) : <EOL> if attr : <EOL> self . attrset ( attr ) <EOL> for deltaX in range ( len ( string ) ) : <EOL> coord = ( x + deltaX , y ) <EOL> self . output [ coord ] = ( string [ deltaX ] , self . currentAttribute ) <EOL> def delch ( self , y , x ) : <EOL> '''<STR_LIT>''' <EOL> self . output [ ( x , y ) ] = ( '<STR_LIT>' , <NUM_LIT:1> ) <EOL> def getch ( self ) : <EOL> return CHAR_TO_CODE [ self . charInputs . pop ( <NUM_LIT:0> ) ] <EOL> def getstr ( self , y , x , maxLen ) : <EOL> return '<STR_LIT>' <EOL> def printScreen ( self ) : <EOL> for index , row in enumerate ( self . getRows ( ) ) : <EOL> print ( "<STR_LIT>" % ( index , row ) ) <EOL> def printOldScreens ( self ) : <EOL> for oldScreen in range ( self . getNumPastScreens ( ) ) : <EOL> for index , row in enumerate ( self . getRowsForPastScreen ( oldScreen ) ) : <EOL> print ( "<STR_LIT>" % ( oldScreen , index , row ) ) <EOL> def getNumPastScreens ( self ) : <EOL> return len ( self . pastScreens ) <EOL> def getRowsForPastScreen ( self , pastScreen ) : <EOL> return self . getRows ( screen = self . pastScreens [ pastScreen ] ) <EOL> def getRowsWithAttributesForPastScreen ( self , pastScreen ) : <EOL> return self . getRowsWithAttributes ( screen = self . pastScreens [ pastScreen ] ) <EOL> def getRowsWithAttributesForPastScreens ( self , pastScreens ) : <EOL> '''<STR_LIT>''' <EOL> pages = map ( lambda screenIndex : self . getRowsWithAttributes ( <EOL> screen = self . pastScreens [ screenIndex ] ) , pastScreens ) <EOL> lines , attributes = zip ( * pages ) <EOL> return ( [ line for page in lines for line in page ] , <EOL> [ line for page in attributes for line in page ] ) <EOL> def getRowsWithAttributes ( self , screen = None ) : <EOL> if not screen : <EOL> screen = self . output <EOL> rows = [ ] <EOL> attributeRows = [ ] <EOL> for y in range ( self . maxY ) : <EOL> row = '<STR_LIT>' <EOL> attributeRow = '<STR_LIT>' <EOL> for x in range ( self . maxX ) : <EOL> coord = ( x , y ) <EOL> ( char , attr ) = screen [ coord ] <EOL> row += char <EOL> attributeRow += self . getAttributeSymbolForCode ( attr ) <EOL> rows . append ( row ) <EOL> attributeRows . append ( attributeRow ) <EOL> return ( rows , attributeRows ) <EOL> def getRows ( self , screen = None ) : <EOL> ( rows , _ ) = self . getRowsWithAttributes ( screen ) <EOL> return rows <EOL> def getAttributeSymbolForCode ( self , code ) : <EOL> symbol = ATTRIBUTE_SYMBOL_MAPPING . get ( code , None ) <EOL> if symbol is None : <EOL> raise ValueError ( '<STR_LIT>' % code ) <EOL> return symbol </s>
