def display_bitmask(kind, bitmap, value):
 col1_width = max(map(len, (list(bitmap.keys()) + [kind])))
 col2_width = 7
 FMT = '{name:>{col1_width}} {value:>{col2_width}}   {description}'
 print(FMT.format(name=kind, value='Value', description='Description', col1_width=col1_width, col2_width=col2_width))
 print('{0} {1}   {2}'.format(('-' * col1_width), ('-' * col2_width), ('-' * max(map(len, bitmap.values())))))
 for (flag_name, description) in bitmap.items():
  try:
   bitmask = getattr(termios, flag_name)
   bit_val = ('on' if bool((value & bitmask)) else 'off')
  except AttributeError:
   bit_val = 'undef'
  print(FMT.format(name=flag_name, value=bit_val, description=description, col1_width=col1_width, col2_width=col2_width))
 print()

def display_bitmask ( kind , bitmap , value ) : col1_width = max ( map ( len , ( list ( bitmap . keys ( ) ) + [ kind ] ) ) ) col2_width = 7 FMT = '{name:>{col1_width}} {value:>{col2_width}}   {description}' print ( FMT . format ( name = kind , value = 'Value' , description = 'Description' , col1_width = col1_width , col2_width = col2_width ) ) print ( '{0} {1}   {2}' . format ( ( '-' * col1_width ) , ( '-' * col2_width ) , ( '-' * max ( map ( len , bitmap . values ( ) ) ) ) ) ) for ( flag_name , description ) in bitmap . items ( ) : try : bitmask = getattr ( termios , flag_name ) bit_val = ( 'on' if bool ( ( value & bitmask ) ) else 'off' ) except AttributeError : bit_val = 'undef' print ( FMT . format ( name = flag_name , value = bit_val , description = description , col1_width = col1_width , col2_width = col2_width ) ) print ( )
display all matching bitmask values for value given bitmap .