drawInput :: Quake ()
drawInput = do
    keyDest <- use $ globals.gCls.csKeyDest
    state <- use $ globals.gCls.csState
                                            -- don't draw anything (always draw if not active)
    unless (keyDest == Constants.keyMenu || (keyDest /= Constants.keyConsole && state == Constants.caActive)) $ do
      editLine' <- use $ globals.gEditLine
      Just text <- preuse $ globals.gKeyLines.ix editLine'
      linePos <- use $ globals.gKeyLinePos
      lineWidth <- use $ globals.gCon.cLineWidth

      -- add the cursor frame and fill out remainder with spaces
      realTime <- use $ globals.gCls.csRealTime
      let cursorFrame :: Word8 = fromIntegral $ 10 + ((realTime `shiftR` 8) .&. 1)
          fullLine = text `B.append` B.unfoldr (\i -> if i == 0 
                                                        then Just (cursorFrame, 1) 
                                                        else if linePos + 1 + i < lineWidth 
                                                               then Just (32, i + 1)
                                                               else Nothing) 0

      -- prestep if horizontally scrolling
      let start = if linePos >= lineWidth
                    then 1 + linePos - lineWidth
                    else 0

      -- draw it
      visLines <- use $ globals.gCon.cVisLines
      Just renderer <- use $ globals.gRenderer
      let drawChar = renderer^.rRefExport.reDrawChar
      drawInputLine drawChar fullLine (visLines - 22) start lineWidth -- TODO: make sure start is here (jake2 bug with not using start?)

  where drawInputLine :: (Int -> Int -> Int -> Quake ()) -> B.ByteString -> Int -> Int -> Int -> Quake ()
        drawInputLine drawChar text y idx maxIdx
          | idx >= maxIdx = return ()
          | otherwise = do
              drawChar ((idx + 1) `shiftL` 3) y (ord $ BC.index text idx)
              drawInputLine drawChar text y (idx + 1) maxIdx

{-
- ================ Con_Print
- 
- Handles cursor positioning, line wrapping, etc All console printing must
- go through this in order to be logged to disk If no console is visible,
- the text will appear at the top of the game window ================
-}
drawInput :: Quake ()
drawInput = do
    keyDest <- use $ globals.gCls.csKeyDest
    state <- use $ globals.gCls.csState
                                            -- don't draw anything (always draw if not active)
    unless (keyDest == Constants.keyMenu || (keyDest /= Constants.keyConsole && state == Constants.caActive)) $ do
      editLine' <- use $ globals.gEditLine
      Just text <- preuse $ globals.gKeyLines.ix editLine'
      linePos <- use $ globals.gKeyLinePos
      lineWidth <- use $ globals.gCon.cLineWidth

      -- add the cursor frame and fill out remainder with spaces
      realTime <- use $ globals.gCls.csRealTime
      let cursorFrame :: Word8 = fromIntegral $ 10 + ((realTime `shiftR` 8) .&. 1)
          fullLine = text `B.append` B.unfoldr (\i -> if i == 0 
                                                        then Just (cursorFrame, 1) 
                                                        else if linePos + 1 + i < lineWidth 
                                                               then Just (32, i + 1)
                                                               else Nothing) 0

      -- prestep if horizontally scrolling
      let start = if linePos >= lineWidth
                    then 1 + linePos - lineWidth
                    else 0

      -- draw it
      visLines <- use $ globals.gCon.cVisLines
      Just renderer <- use $ globals.gRenderer
      let drawChar = renderer^.rRefExport.reDrawChar
      drawInputLine drawChar fullLine (visLines - 22) start lineWidth -- TODO: make sure start is here (jake2 bug with not using start?)

  where drawInputLine :: (Int -> Int -> Int -> Quake ()) -> B.ByteString -> Int -> Int -> Int -> Quake ()
        drawInputLine drawChar text y idx maxIdx
          | idx >= maxIdx = return ()
          | otherwise = do
              drawChar ((idx + 1) `shiftL` 3) y (ord $ BC.index text idx)
              drawInputLine drawChar text y (idx + 1) maxIdx

{-
- ================ Con_Print
- 
- Handles cursor positioning, line wrapping, etc All console printing must
- go through this in order to be logged to disk If no console is visible,
- the text will appear at the top of the game window ================
-}
drawInput = do
    keyDest <- use $ globals.gCls.csKeyDest
    state <- use $ globals.gCls.csState
                                            -- don't draw anything (always draw if not active)
    unless (keyDest == Constants.keyMenu || (keyDest /= Constants.keyConsole && state == Constants.caActive)) $ do
      editLine' <- use $ globals.gEditLine
      Just text <- preuse $ globals.gKeyLines.ix editLine'
      linePos <- use $ globals.gKeyLinePos
      lineWidth <- use $ globals.gCon.cLineWidth

      -- add the cursor frame and fill out remainder with spaces
      realTime <- use $ globals.gCls.csRealTime
      let cursorFrame :: Word8 = fromIntegral $ 10 + ((realTime `shiftR` 8) .&. 1)
          fullLine = text `B.append` B.unfoldr (\i -> if i == 0 
                                                        then Just (cursorFrame, 1) 
                                                        else if linePos + 1 + i < lineWidth 
                                                               then Just (32, i + 1)
                                                               else Nothing) 0

      -- prestep if horizontally scrolling
      let start = if linePos >= lineWidth
                    then 1 + linePos - lineWidth
                    else 0

      -- draw it
      visLines <- use $ globals.gCon.cVisLines
      Just renderer <- use $ globals.gRenderer
      let drawChar = renderer^.rRefExport.reDrawChar
      drawInputLine drawChar fullLine (visLines - 22) start lineWidth -- TODO: make sure start is here (jake2 bug with not using start?)

  where drawInputLine :: (Int -> Int -> Int -> Quake ()) -> B.ByteString -> Int -> Int -> Int -> Quake ()
        drawInputLine drawChar text y idx maxIdx
          | idx >= maxIdx = return ()
          | otherwise = do
              drawChar ((idx + 1) `shiftL` 3) y (ord $ BC.index text idx)
              drawInputLine drawChar text y (idx + 1) maxIdx

{-
- ================ Con_Print
- 
- Handles cursor positioning, line wrapping, etc All console printing must
- go through this in order to be logged to disk If no console is visible,
- the text will appear at the top of the game window ================
-}