handleKeyboard :: Vty.Key -> Int -> Int -> [String] -> Vty.Vty -> IO (Vty.Vty,Maybe Int)
handleKeyboard key position offset items vt = case key of
-- handles keyboard input
    KChar 'q' -> return (vt,Nothing)
    KEsc -> return (vt,Nothing)
    KEnter -> return (vt,Just position)
    KChar 'j' -> work (position + 1) offset items vt
    KDown -> work (position + 1) offset items vt
    KChar 'k' -> work (position - 1) offset items vt
    KUp -> work (position - 1) offset items vt
    KPageUp -> do
        bounds <- Vty.displayBounds $ Vty.outputIface vt
        work (position - (Vty.regionHeight bounds)) offset items vt
    KPageDown -> do
        bounds <- Vty.displayBounds $ Vty.outputIface vt
        work (position + (Vty.regionHeight bounds)) offset items vt
    KHome -> work 0 offset items vt
    KEnd -> work (length items - 1) offset items vt
    _ -> work position offset items vt
handleKeyboard :: Vty.Key -> Int -> Int -> [String] -> Vty.Vty -> IO (Vty.Vty,Maybe Int)
handleKeyboard key position offset items vt = case key of
-- handles keyboard input
    KChar 'q' -> return (vt,Nothing)
    KEsc -> return (vt,Nothing)
    KEnter -> return (vt,Just position)
    KChar 'j' -> work (position + 1) offset items vt
    KDown -> work (position + 1) offset items vt
    KChar 'k' -> work (position - 1) offset items vt
    KUp -> work (position - 1) offset items vt
    KPageUp -> do
        bounds <- Vty.displayBounds $ Vty.outputIface vt
        work (position - (Vty.regionHeight bounds)) offset items vt
    KPageDown -> do
        bounds <- Vty.displayBounds $ Vty.outputIface vt
        work (position + (Vty.regionHeight bounds)) offset items vt
    KHome -> work 0 offset items vt
    KEnd -> work (length items - 1) offset items vt
    _ -> work position offset items vt
handleKeyboard key position offset items vt = case key of
-- handles keyboard input
    KChar 'q' -> return (vt,Nothing)
    KEsc -> return (vt,Nothing)
    KEnter -> return (vt,Just position)
    KChar 'j' -> work (position + 1) offset items vt
    KDown -> work (position + 1) offset items vt
    KChar 'k' -> work (position - 1) offset items vt
    KUp -> work (position - 1) offset items vt
    KPageUp -> do
        bounds <- Vty.displayBounds $ Vty.outputIface vt
        work (position - (Vty.regionHeight bounds)) offset items vt
    KPageDown -> do
        bounds <- Vty.displayBounds $ Vty.outputIface vt
        work (position + (Vty.regionHeight bounds)) offset items vt
    KHome -> work 0 offset items vt
    KEnd -> work (length items - 1) offset items vt
    _ -> work position offset items vt