Skip to content

Commit

Permalink
Add horizontal scrolling on why-depends window
Browse files Browse the repository at this point in the history
The implementation is not ideal, since scrolling is boundless; but
at least it makes viewing long dependency chains somehow possible.

closes #18
  • Loading branch information
utdemir committed Mar 11, 2021
1 parent bb38851 commit dd0d11c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

* feat: Support non standard Nix store locations
* feat: Horizontal scrolling on why-depends window

## 0.1.5

Expand Down
18 changes: 16 additions & 2 deletions src/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ data Widgets
| WidgetNextPane
| WidgetWhyDepends
| WidgetSearch
| WidgetWhyDependsViewport
deriving (Show, Eq, Ord)

data Modal s
Expand Down Expand Up @@ -190,7 +191,8 @@ app =
B.halt s
(B.VtyEvent (V.EvKey (V.KChar '?') []), Nothing) ->
B.continue s {aeOpenModal = Just ModalHelp}
(B.VtyEvent (V.EvKey (V.KChar 'w') []), Nothing) ->
(B.VtyEvent (V.EvKey (V.KChar 'w') []), Nothing) -> do
B.hScrollToBeginning (B.viewportScroll WidgetWhyDependsViewport)
B.continue $ showWhyDepends s
(B.VtyEvent (V.EvKey (V.KChar '/') []), Nothing) ->
B.continue $ showAndUpdateSearch "" "" s
Expand Down Expand Up @@ -221,12 +223,20 @@ app =
(B.VtyEvent (V.EvKey k []), Just (ModalWhyDepends _))
| k `elem` [V.KChar 'q', V.KEsc] ->
B.continue s {aeOpenModal = Nothing}
(B.VtyEvent (V.EvKey k []), Just (ModalWhyDepends _))
| k `elem` [V.KChar 'h', V.KLeft] -> do
B.hScrollBy (B.viewportScroll WidgetWhyDependsViewport) (-1)
B.continue s
(B.VtyEvent (V.EvKey k []), Just (ModalWhyDepends l))
| k `elem` [V.KChar 'j', V.KDown, V.KChar '\t'] ->
B.continue s {aeOpenModal = Just $ ModalWhyDepends (B.listMoveDown l)}
(B.VtyEvent (V.EvKey k []), Just (ModalWhyDepends l))
| k `elem` [V.KChar 'k', V.KUp, V.KBackTab] ->
B.continue s {aeOpenModal = Just $ ModalWhyDepends (B.listMoveUp l)}
(B.VtyEvent (V.EvKey k []), Just (ModalWhyDepends _))
| k `elem` [V.KChar 'l', V.KRight] -> do
B.hScrollBy (B.viewportScroll WidgetWhyDependsViewport) 1
B.continue s
(B.VtyEvent (V.EvKey V.KPageUp []), Just (ModalWhyDepends l)) ->
B.listMovePageUp l >>= \l' ->
B.continue s {aeOpenModal = Just $ ModalWhyDepends l'}
Expand Down Expand Up @@ -377,7 +387,11 @@ renderWhyDependsModal ::
B.GenericList Widgets Seq (NonEmpty (Path s)) ->
B.Widget Widgets
renderWhyDependsModal l =
renderModal "why-depends" (B.renderList renderDepends True l)
B.renderList renderDepends True l
& B.hLimitPercent 100 -- This limit seems pointless, but otherwise render list takes infinite
-- amount of horizontal space and 'viewport' below complains.
& B.viewport WidgetWhyDependsViewport B.Horizontal
& renderModal "why-depends"
where
renderDepends _ =
B.txt . pathsToText
Expand Down

0 comments on commit dd0d11c

Please sign in to comment.