README + minor doc changes
    
    
      
        Getty Ritter
        8 years ago
      
    
    
  
  
  
  
    
      
      
      
        
          |  | 1 | # `brick-table` | 
|  | 2 |  | 
|  | 3 | This is a package for creating and manipulating simple spreadsheed-like table widgets in [`brick`](https://hackage.haskell.org/package/brick-0.17). These tables come equipped with a notion of selection/focus on a set of cells, as well as a handful of functions for accessing and manipulating that subset. | 
|  | 4 |  | 
|  | 5 | A `table` in this case wraps an underlying `array` value that's indexed with an `(Int, Int)` pair. We can create a new `table` with default values using the `table` function, and include it in our application's `state`. | 
|  | 6 |  | 
|  | 7 | ```.haskell | 
|  | 8 | app :: App (Table TableElement MyName) MyEvent MyName | 
|  | 9 | app = App | 
|  | 10 | { appDraw = \ s -> renderTable True s | 
|  | 11 | , appChooseCursor = \ _ _ -> Nothing | 
|  | 12 | , appHandleEvent = \ s e -> case e of | 
|  | 13 | VtyEvent (EvKey KEsc []) -> halt s | 
|  | 14 | _                        -> do | 
|  | 15 | s' <- handleTableEvenArrowKeys ev s | 
|  | 16 | continue s' | 
|  | 17 | , appStartEvent = \s -> return s | 
|  | 18 | , appAttrMap = \_ -> attrMap mempty [] | 
|  | 19 | } | 
|  | 20 |  | 
|  | 21 | main :: IO () | 
|  | 22 | main = do | 
|  | 23 | let myTable = table myName (width, height) myDrawFunction myTableElement | 
|  | 24 | _ <- Brick.defaultMain app myTable | 
|  | 25 | return () | 
|  | 26 | ``` | 
            
          
        
      
       
  
    
      
      
      
        
          | 41 | 41 | main :: IO () | 
| 42 | 42 | main = do | 
| 43 | 43 | let tb = table () (10, 10) drawElem 0 | 
| 44 |  | _ <- Brick. customMain (Vty.mkVty mempty) (Nothing)app tb | 
|  | 44 | _ <- Brick.defaultMain app tb | 
| 45 | 45 | return () | 
            
          
        
      
       
  
    
      
      
      
        
          | 30 | 30 | -- ^ The array which represents the contents of the | 
| 31 | 31 | -- table. This always begins at index @(0,0)@. | 
| 32 | 32 | , tableCurIndex :: ((Int, Int), (Int, Int)) | 
| 33 |  | -- ^ The currently focused index | 
|  | 33 | -- ^ The currently focused range of cells, of the form | 
|  | 34 | -- @((minX, minY), (maxX, maxY))@. Be aware that this module maintains | 
|  | 35 | -- the invariants that @minX <= minY && maxX <= maxY@, and that both | 
|  | 36 | -- the min and max indices are within the range of the table. If | 
|  | 37 | -- this value is modified without preserving that invariant, functions | 
|  | 38 | -- in this module may produce anomalous results or even crash. | 
| 34 | 39 | , tableDraw     :: e -> Bool -> Brick.Widget n | 
| 35 | 40 | -- ^ The function the table uses to draw its contents. The | 
| 36 | 41 | -- boolean parameter will be 'True' if the element is the |