Index: lsr/src/AEConstants/Output.py
===================================================================
--- lsr/src/AEConstants/Output.py	(revision 436)
+++ lsr/src/AEConstants/Output.py	(working copy)
@@ -29,6 +29,7 @@
 CMD_CARET = (BRAILLE_CMD | 0x0001)
 CMD_TRUNCATE = (BRAILLE_CMD | 0x0002)
 CMD_GET_ELLIPSIS_SIZE = (BRAILLE_CMD | 0x0003)
+CMD_GET_MISSINGCELL_COUNT = (BRAILLE_CMD | 0x0004)
 
 # commands for audio devices
 CMD_INDEX = 7
Index: lsr/src/Perks/BasicBraillePerk.py
===================================================================
--- lsr/src/Perks/BasicBraillePerk.py	(revision 436)
+++ lsr/src/Perks/BasicBraillePerk.py	(working copy)
@@ -90,7 +90,6 @@
   @type abscaretpos: integer
   @ivar current_text: String containing entire output from accessible
   @type current_text: string
-  
   '''
   # defines the class to use for state information in this Perk
   STATE = BasicBraillePerkState
@@ -147,6 +146,7 @@
                          [brlindev.KEY_CMD_LNBEG])
     self.registerCommand(brlindev, 'braille line end', True, 
                          [brlindev.KEY_CMD_LNEND])
+                         
     
   def close(self):
     try:
@@ -177,7 +177,7 @@
     else:
       self.abscaretpos = -1 
       
-  def getRelCaretPos(self, totalcells):
+  def getRelCaretPos(self):
     '''
     Get relative (to device display) caret position
     
@@ -185,11 +185,10 @@
     @rtype: Integer
     '''
     # -1 (0 on device) is special case where we don't show cursor
-    
     if self.abscaretpos == -1:
       return -1
     else:
-      return max(-1, self.abscaretpos - self.getLeftSlice(totalcells)) 
+      return max(-1, self.abscaretpos - self.getLeftSlice(40)) 
      
   # TODO:  move to Output text as private method
   def getLeftSlice(self, totalcells):
@@ -198,13 +197,16 @@
     
     @return: Left slice index
     @rtype: int
-    '''  
+    ''' 
     state = self.getState()
+    misscellcnt = self.send(CMD_GET_MISSINGCELL_COUNT, None, talk=False)
+    
     if self.task_por.char_offset-self.pre_left_slice < state.LeftPadding:
       retval = max(0,self.task_por.char_offset-state.LeftPadding)
     elif self.task_por.char_offset-self.pre_left_slice >= \
-                totalcells-state.RightPadding:
+                totalcells-state.RightPadding - misscellcnt:
       retval = self.task_por.char_offset-totalcells+state.RightPadding+1
+      retval += misscellcnt
     else:
       retval = self.pre_left_slice
     
@@ -517,8 +519,6 @@
     
     @param por: Point of regard where the caret event occurred
     @type por: L{POR}
-    #print "leftslice=", leftslice
-   # print "offset=", self.perk.scroll_offset
     @param text: The text delete
     @type text: string
     @param text_offset: The offset of the delete text
@@ -572,7 +572,7 @@
     state = self.perk.getState()
    
     # set caret position. 
-    caretpos = self.perk.getRelCaretPos(style.TotalCells)
+    caretpos = self.perk.getRelCaretPos()
   
     if caretpos < 0 or caretpos >= style.TotalCells:
       self.send(CMD_CARET, -1, talk=False)
@@ -584,8 +584,9 @@
     rightslice = leftslice+style.TotalCells
     
     # truncation indicators for ellipsis
-    self.send(CMD_TRUNCATE, \
-        (leftslice>0, rightslice<len(self.perk.current_text)), talk=False) 
+    misscellcnt = self.send(CMD_GET_MISSINGCELL_COUNT, None, talk=False)
+    self.send(CMD_TRUNCATE, (leftslice>0, \
+        rightslice<len(self.perk.current_text)+misscellcnt), talk=False) 
         
     # send text to device
     self.sayItem(text=self.perk.current_text[leftslice:rightslice])
Index: lsr/src/Devices/BrlAPIDevice.py
===================================================================
--- lsr/src/Devices/BrlAPIDevice.py	(revision 436)
+++ lsr/src/Devices/BrlAPIDevice.py	(working copy)
@@ -38,7 +38,7 @@
   @return: Name of the key
   @rtype: string
   '''
-  for name, value in BrlAPIDevice.__dict__.items():
+  for name, value in brlapi.__dict__.items():
       if code == value:
         return name
   return ''
@@ -154,8 +154,10 @@
     self._loadKeyCmdConstants()
     
     # tell brlapi to not send me any key_cmds.  Each task will register for key
-    self.brlconn.ignoreKeyRange(0, brlapi.KEY_MAX)
     
+    # TODO fix when brltty API settles down
+    #self.brlconn.ignoreKeyRange([0, brlapi.KEY_MAX])
+    
     # start input event manager
     self.inputmngr = BrlInputEventListener((self))
     self.inputmngr.start()
@@ -164,6 +166,17 @@
     self.default_style.DisplayColumns = self.brlconn.displaySize[0]
     self.default_style.DisplayRows = self.brlconn.displaySize[1]
     self.default_style.TotalCells = self.brlconn.displaySize[0] * self.brlconn.displaySize[1]
+    
+  def postInit(self):
+    '''
+    Called after the L{init} method and after either L{loadStyles} or 
+    L{createDistinctStyles}. missingcellcnt is the number of missing (broken)
+    cells defined by the user and stored in the L{Setting} string "CellMask".
+    
+    @raise Error.InitError: When a communication or state problem exists for 
+      the specific device
+    '''
+    self.default_style.missingcellcnt = self.default_style.CellMask.count('0')    
        
   def getBrlConnection(self):
     '''
@@ -181,7 +194,7 @@
     '''
     for name, value in brlapi.__dict__.items():
       if name.startswith('KEY_CMD'):
-        setattr(self.__class__, name, brlapi.KEY_TYPE_CMD|value)
+        setattr(self.__class__, name, value)
         
   def _onKeyClick(self, key):
     '''
@@ -196,11 +209,11 @@
     except brlapi.OperationError:
       log.warn('braille input failed')
       return
-    #print "Key %ld (%x %x %x %x) !" % (key, k["type"], k["command"], k["argument"], k["flags"])
-    #print "keycode=", _keyCodeToKeyName(k["type"]|k["command"])
+   # print "Key %ld (%x %x %x %x) !" % (key, k["type"], k["command"], k["argument"], k["flags"])
+   # print "keycode=", _keyCodeToKeyName(key)
     
     gesture = AEInput.Gesture(self)
-    gesture.addActionCode(k["type"]|k["command"])
+    gesture.addActionCode(k['command'])
     
     # use default arguments or create key_cmd specific ones
     if k['command'] == brlapi.KEY_CMD_ROUTE:
@@ -246,18 +259,22 @@
     @type codes: list
     @raise NotImplementedError: When this method is not overridden by a subclass
     '''
+    # TODO remove when brltty API settles down
+    if True:
+      return
+    
     for codelist in codes:
       for code in codelist:
         if self.registered_keys.has_key(code):
           self.registered_keys[code] += 1
         else:
           self.registered_keys[code] = 1
-          if code == self.KEY_CMD_ROUTE:
-            self.brlconn.acceptKeyRange(self.KEY_CMD_ROUTE, \
-                  self.KEY_CMD_ROUTE|brlapi.KEY_CMD_ARG_MASK)
+          if code == brlapi.KEY_CMD_ROUTE:
+            self.brlconn.acceptKeyRange([brlapi.KEY_CMD_ROUTE, \
+                            brlapi.KEY_CMD_ROUTE|brlapi.KEY_CMD_ARG_MASK])
           else:
             self.brlconn.acceptKeySet([code])
-    
+            
   def removeKeyCmd(self, codes):
     ''' 
     Unregisters each KEY_CMD within codes.
@@ -266,6 +283,10 @@
     @type codes: list
     @raise NotImplementedError: When this method is not overridden by a subclass
     '''
+    # TODO remove when brltty API settles down
+    if True:
+      return
+    
     for codelist in codes:
       for code in codelist:
         try:
@@ -273,8 +294,8 @@
           if self.registered_keys[code] == 0:
             del self.registered_keys[code]
             if code == brlapi.KEY_CMD_ROUTE:
-              self.brlconn.ignoreKeyRange(self.KEY_CMD_ROUTE, \
-                  self.KEY_CMD_ROUTE|brlapi.KEY_CMD_ARG_MASK)
+              self.brlconn.ignoreKeyRange([brlapi.KEY_CMD_ROUTE, \
+                            brlapi.KEY_CMD_ROUTE|brlapi.KEY_CMD_ARG_MASK])
             else:
               self.brlconn.ignoreKeySet([code])
         except KeyError:
@@ -448,42 +469,14 @@
     right = len(self.EllipsisStyles[self.default_style.EllipsisStyle][1])
     return (left, right)
     
-  def sendGetEllipsisSizes(self, style):
+  def sendGetMissingCellCount(self):
     '''
-    @param style: Style with which the ellipsis are defined
-    @type style: L{AEOutput.Style}
-    @return: tuple containing length of left and right ellipsis
-    @rtype: tuple
+    @return: integer containing missing cell count
+    @rtype: integer
     @raise NotImplementedError: When not overridden in a subclass
     '''
-    left = len(self.EllipsisStyles[self.default_style.EllipsisStyle][0])
-    right = len(self.EllipsisStyles[self.default_style.EllipsisStyle][1])
-    return (left, right)
-    
-  def sendGetEllipsisSizes(self, style):
-    '''
-    @param style: Style with which the ellipsis are defined
-    @type style: L{AEOutput.Style}
-    @return: tuple containing length of left and right ellipsis
-    @rtype: tuple
-    @raise NotImplementedError: When not overridden in a subclass
-    '''
-    left = len(self.EllipsisStyles[self.default_style.EllipsisStyle][0])
-    right = len(self.EllipsisStyles[self.default_style.EllipsisStyle][1])
-    return (left, right)
-    
-  def sendGetEllipsisSizes(self, style):
-    '''
-    @param style: Style with which the ellipsis are defined
-    @type style: L{AEOutput.Style}
-    @return: tuple containing length of left and right ellipsis
-    @rtype: tuple
-    @raise NotImplementedError: When not overridden in a subclass
-    '''
-    left = len(self.EllipsisStyles[self.default_style.EllipsisStyle][0])
-    right = len(self.EllipsisStyles[self.default_style.EllipsisStyle][1])
-    return (left, right)
-        
+    return self.default_style.missingcellcnt
+  
   def isActive(self):
     '''
     Indicates whether the device has text waiting to be output.
Index: lsr/src/AEOutput/Braille.py
===================================================================
--- lsr/src/AEOutput/Braille.py	(revision 436)
+++ lsr/src/AEOutput/Braille.py	(working copy)
@@ -88,6 +88,8 @@
       self.sendTruncate(value[0], value[1], style)
     elif name == AEConstants.CMD_GET_ELLIPSIS_SIZE:
       return self.sendGetEllipsisSizes(style)
+    elif name == AEConstants.CMD_GET_MISSINGCELL_COUNT:
+      return self.sendGetMissingCellCount()
 
       
   def sendCaret(self, pos, style):
@@ -150,6 +152,14 @@
     @raise NotImplementedError: When not overridden in a subclass
     '''
     raise NotImplementedError
+  
+  def sendGetMissingCellCount(self):
+    '''
+    @return: integer containing missing cell count
+    @rtype: integer
+    @raise NotImplementedError: When not overridden in a subclass
+    '''
+    raise NotImplementedError
 
   def sendString(self, text, style):
     '''
Index: lsr/src/AEOutput/Style.py
===================================================================
--- lsr/src/AEOutput/Style.py	(revision 436)
+++ lsr/src/AEOutput/Style.py	(working copy)
@@ -371,7 +371,12 @@
   EllipsisStyle (enum): Current ellipsis style
   
   CellMask (string): Missing cell string.  0=bad cell; 1=good cell.
+  
+  @ivar missingcellcnt: Count of missing cells in CellMask
+  @type missingcellcnt: integer
   '''
+  missingcellcnt = 0
+  
   def _initDefault(self):
     '''
     Called automatically by the L{Style} base class when this style is a 
@@ -380,7 +385,6 @@
     override in a subclass.
     '''
     # braille display properties
-    
     self.newNumeric('DisplayColumns', 40, _('Columns in display'), 0, 80, 0)
     self.newNumeric('DisplayRows', 1, _('Rows in display'), 0, 10, 0)
     self.newNumeric('TotalCells', 40, _('Total cells in display'), 0, 800, 0)
@@ -392,18 +396,23 @@
                 _('Defines the caret representation.'))
                 
     self.newBool('EllipsisRight', False, _('Ellipsis right?'), 
-                _('When set, ellipsis will appear when additional text is to the right of the viewport.'))
+                _('When set, ellipsis will appear when additional text is '
+                  'to the right of the viewport.'))
     self.newBool('EllipsisLeft', False, _('Ellipsis left?'), 
-              _('When set, ellipsis will appear when additional text is to the \
-  left of the viewport.'))
-    self.newEnum('EllipsisStyle', ELLIPSIS_ELLIPSIS, _('Ellipsis Display Style'), 
+              _('When set, ellipsis will appear when additional text is to the '
+              'left of the viewport.'))
+    self.newEnum('EllipsisStyle',ELLIPSIS_ELLIPSIS,_('Ellipsis Display Style'), 
                 {_('Pin 3 in 3 cells') : ELLIPSIS_ELLIPSIS,
                 _('Continuation symbol') : ELLIPSIS_CONTINUATION},
                 _('Defines the caret representation.'))
-                
-    self.newString('CellMask', '', _('Broken Cell String'), 
-                  _('String of zeros and ones indicating the functionality of\
- each cell'))
+    cm = self.newString('CellMask', '', _('Broken Cell String'), 
+                  _('String of zeros and ones indicating the functionality of'
+                  ' each cell'))
+    # add observer to count missing cells on cell mask           
+    cm.addObserver(self._setMissingCells)
+    
+  def _setMissingCells(self, style, setting):
+    self.missingcellcnt = self.CellMask.count('0')
   
   def _newBrailleGroup(self, root):
     
