module Cursor.Brick.List.NonEmpty where

import Brick.Types as B
import Brick.Widgets.Core as B
import Cursor.List.NonEmpty
import Data.List

verticalNonEmptyCursorTableWithHeader ::
  (b -> [Widget n]) -> (a -> [Widget n]) -> (b -> [Widget n]) -> [Widget n] -> NonEmptyCursor a b -> Widget n
verticalNonEmptyCursorTableWithHeader :: (b -> [Widget n])
-> (a -> [Widget n])
-> (b -> [Widget n])
-> [Widget n]
-> NonEmptyCursor a b
-> Widget n
verticalNonEmptyCursorTableWithHeader b -> [Widget n]
prevFunc a -> [Widget n]
curFunc b -> [Widget n]
nextFunc [Widget n]
header =
  ([b] -> a -> [b] -> Widget n) -> NonEmptyCursor a b -> Widget n
forall b a n.
([b] -> a -> [b] -> Widget n) -> NonEmptyCursor a b -> Widget n
nonEmptyCursorWidget (\[b]
ps a
c [b]
ns -> [[Widget n]] -> Widget n
forall n. [[Widget n]] -> Widget n
tableWidget ([[Widget n]] -> Widget n) -> [[Widget n]] -> Widget n
forall a b. (a -> b) -> a -> b
$ [Widget n]
header [Widget n] -> [[Widget n]] -> [[Widget n]]
forall a. a -> [a] -> [a]
: ((b -> [Widget n]) -> [b] -> [[Widget n]]
forall a b. (a -> b) -> [a] -> [b]
map b -> [Widget n]
prevFunc [b]
ps [[Widget n]] -> [[Widget n]] -> [[Widget n]]
forall a. [a] -> [a] -> [a]
++ [a -> [Widget n]
curFunc a
c] [[Widget n]] -> [[Widget n]] -> [[Widget n]]
forall a. [a] -> [a] -> [a]
++ (b -> [Widget n]) -> [b] -> [[Widget n]]
forall a b. (a -> b) -> [a] -> [b]
map b -> [Widget n]
nextFunc [b]
ns))

verticalNonEmptyCursorTableWithHeaderM ::
  Applicative f =>
  (b -> f [Widget n]) ->
  (a -> f [Widget n]) ->
  (b -> f [Widget n]) ->
  [Widget n] ->
  NonEmptyCursor a b ->
  f (Widget n)
verticalNonEmptyCursorTableWithHeaderM :: (b -> f [Widget n])
-> (a -> f [Widget n])
-> (b -> f [Widget n])
-> [Widget n]
-> NonEmptyCursor a b
-> f (Widget n)
verticalNonEmptyCursorTableWithHeaderM b -> f [Widget n]
prevFunc a -> f [Widget n]
curFunc b -> f [Widget n]
nextFunc [Widget n]
header =
  ([b] -> a -> [b] -> f (Widget n))
-> NonEmptyCursor a b -> f (Widget n)
forall b a (m :: * -> *) n.
([b] -> a -> [b] -> m (Widget n))
-> NonEmptyCursor a b -> m (Widget n)
nonEmptyCursorWidgetM (\[b]
ps a
c [b]
ns -> [[Widget n]] -> Widget n
forall n. [[Widget n]] -> Widget n
tableWidget ([[Widget n]] -> Widget n) -> f [[Widget n]] -> f (Widget n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [f [Widget n]] -> f [[Widget n]]
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA ([Widget n] -> f [Widget n]
forall (f :: * -> *) a. Applicative f => a -> f a
pure [Widget n]
header f [Widget n] -> [f [Widget n]] -> [f [Widget n]]
forall a. a -> [a] -> [a]
: ((b -> f [Widget n]) -> [b] -> [f [Widget n]]
forall a b. (a -> b) -> [a] -> [b]
map b -> f [Widget n]
prevFunc [b]
ps [f [Widget n]] -> [f [Widget n]] -> [f [Widget n]]
forall a. [a] -> [a] -> [a]
++ [a -> f [Widget n]
curFunc a
c] [f [Widget n]] -> [f [Widget n]] -> [f [Widget n]]
forall a. [a] -> [a] -> [a]
++ (b -> f [Widget n]) -> [b] -> [f [Widget n]]
forall a b. (a -> b) -> [a] -> [b]
map b -> f [Widget n]
nextFunc [b]
ns)))

verticalNonEmptyCursorTable ::
  (b -> [Widget n]) -> (a -> [Widget n]) -> (b -> [Widget n]) -> NonEmptyCursor a b -> Widget n
verticalNonEmptyCursorTable :: (b -> [Widget n])
-> (a -> [Widget n])
-> (b -> [Widget n])
-> NonEmptyCursor a b
-> Widget n
verticalNonEmptyCursorTable b -> [Widget n]
prevFunc a -> [Widget n]
curFunc b -> [Widget n]
nextFunc =
  ([b] -> a -> [b] -> Widget n) -> NonEmptyCursor a b -> Widget n
forall b a n.
([b] -> a -> [b] -> Widget n) -> NonEmptyCursor a b -> Widget n
nonEmptyCursorWidget
    ( \[b]
ps a
c [b]
ns ->
        [[Widget n]] -> Widget n
forall n. [[Widget n]] -> Widget n
tableWidget ([[Widget n]] -> Widget n) -> [[Widget n]] -> Widget n
forall a b. (a -> b) -> a -> b
$ (b -> [Widget n]) -> [b] -> [[Widget n]]
forall a b. (a -> b) -> [a] -> [b]
map b -> [Widget n]
prevFunc [b]
ps [[Widget n]] -> [[Widget n]] -> [[Widget n]]
forall a. [a] -> [a] -> [a]
++ [a -> [Widget n]
curFunc a
c] [[Widget n]] -> [[Widget n]] -> [[Widget n]]
forall a. [a] -> [a] -> [a]
++ (b -> [Widget n]) -> [b] -> [[Widget n]]
forall a b. (a -> b) -> [a] -> [b]
map b -> [Widget n]
nextFunc [b]
ns
    )

verticalNonEmptyCursorTableM ::
  Applicative f =>
  (b -> f [Widget n]) ->
  (a -> f [Widget n]) ->
  (b -> f [Widget n]) ->
  NonEmptyCursor a b ->
  f (Widget n)
verticalNonEmptyCursorTableM :: (b -> f [Widget n])
-> (a -> f [Widget n])
-> (b -> f [Widget n])
-> NonEmptyCursor a b
-> f (Widget n)
verticalNonEmptyCursorTableM b -> f [Widget n]
prevFunc a -> f [Widget n]
curFunc b -> f [Widget n]
nextFunc =
  ([b] -> a -> [b] -> f (Widget n))
-> NonEmptyCursor a b -> f (Widget n)
forall b a (m :: * -> *) n.
([b] -> a -> [b] -> m (Widget n))
-> NonEmptyCursor a b -> m (Widget n)
nonEmptyCursorWidgetM (\[b]
ps a
c [b]
ns -> [[Widget n]] -> Widget n
forall n. [[Widget n]] -> Widget n
tableWidget ([[Widget n]] -> Widget n) -> f [[Widget n]] -> f (Widget n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [f [Widget n]] -> f [[Widget n]]
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA ((b -> f [Widget n]) -> [b] -> [f [Widget n]]
forall a b. (a -> b) -> [a] -> [b]
map b -> f [Widget n]
prevFunc [b]
ps [f [Widget n]] -> [f [Widget n]] -> [f [Widget n]]
forall a. [a] -> [a] -> [a]
++ [a -> f [Widget n]
curFunc a
c] [f [Widget n]] -> [f [Widget n]] -> [f [Widget n]]
forall a. [a] -> [a] -> [a]
++ (b -> f [Widget n]) -> [b] -> [f [Widget n]]
forall a b. (a -> b) -> [a] -> [b]
map b -> f [Widget n]
nextFunc [b]
ns))

tableWidget :: [[Widget n]] -> Widget n
tableWidget :: [[Widget n]] -> Widget n
tableWidget = [Widget n] -> Widget n
forall n. [Widget n] -> Widget n
hBox ([Widget n] -> Widget n)
-> ([[Widget n]] -> [Widget n]) -> [[Widget n]] -> Widget n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Widget n -> [Widget n] -> [Widget n]
forall a. a -> [a] -> [a]
intersperse (String -> Widget n
forall n. String -> Widget n
str String
" ") ([Widget n] -> [Widget n])
-> ([[Widget n]] -> [Widget n]) -> [[Widget n]] -> [Widget n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Widget n] -> Widget n) -> [[Widget n]] -> [Widget n]
forall a b. (a -> b) -> [a] -> [b]
map [Widget n] -> Widget n
forall n. [Widget n] -> Widget n
vBox ([[Widget n]] -> [Widget n])
-> ([[Widget n]] -> [[Widget n]]) -> [[Widget n]] -> [Widget n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[Widget n]] -> [[Widget n]]
forall a. [[a]] -> [[a]]
transpose

horizontalNonEmptyCursorWidgetM ::
  Applicative f =>
  (b -> f (Widget n)) ->
  (a -> f (Widget n)) ->
  (b -> f (Widget n)) ->
  NonEmptyCursor a b ->
  f (Widget n)
horizontalNonEmptyCursorWidgetM :: (b -> f (Widget n))
-> (a -> f (Widget n))
-> (b -> f (Widget n))
-> NonEmptyCursor a b
-> f (Widget n)
horizontalNonEmptyCursorWidgetM b -> f (Widget n)
beforeFunc a -> f (Widget n)
curFunc b -> f (Widget n)
afterFunc =
  ([b] -> a -> [b] -> f (Widget n))
-> NonEmptyCursor a b -> f (Widget n)
forall b a (m :: * -> *) n.
([b] -> a -> [b] -> m (Widget n))
-> NonEmptyCursor a b -> m (Widget n)
nonEmptyCursorWidgetM (([b] -> a -> [b] -> f (Widget n))
 -> NonEmptyCursor a b -> f (Widget n))
-> ([b] -> a -> [b] -> f (Widget n))
-> NonEmptyCursor a b
-> f (Widget n)
forall a b. (a -> b) -> a -> b
$ \[b]
befores a
current [b]
afters ->
    [Widget n] -> Widget n
forall n. [Widget n] -> Widget n
hBox
      ([Widget n] -> Widget n) -> f [Widget n] -> f (Widget n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [f (Widget n)] -> f [Widget n]
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA
        ([[f (Widget n)]] -> [f (Widget n)]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [(b -> f (Widget n)) -> [b] -> [f (Widget n)]
forall a b. (a -> b) -> [a] -> [b]
map b -> f (Widget n)
beforeFunc [b]
befores, [a -> f (Widget n)
curFunc a
current], (b -> f (Widget n)) -> [b] -> [f (Widget n)]
forall a b. (a -> b) -> [a] -> [b]
map b -> f (Widget n)
afterFunc [b]
afters])

horizontalNonEmptyCursorWidget ::
  (b -> Widget n) ->
  (a -> Widget n) ->
  (b -> Widget n) ->
  NonEmptyCursor a b ->
  Widget n
horizontalNonEmptyCursorWidget :: (b -> Widget n)
-> (a -> Widget n)
-> (b -> Widget n)
-> NonEmptyCursor a b
-> Widget n
horizontalNonEmptyCursorWidget b -> Widget n
beforeFunc a -> Widget n
curFunc b -> Widget n
afterFunc =
  ([b] -> a -> [b] -> Widget n) -> NonEmptyCursor a b -> Widget n
forall b a n.
([b] -> a -> [b] -> Widget n) -> NonEmptyCursor a b -> Widget n
nonEmptyCursorWidget (([b] -> a -> [b] -> Widget n) -> NonEmptyCursor a b -> Widget n)
-> ([b] -> a -> [b] -> Widget n) -> NonEmptyCursor a b -> Widget n
forall a b. (a -> b) -> a -> b
$ \[b]
befores a
current [b]
afters ->
    [Widget n] -> Widget n
forall n. [Widget n] -> Widget n
hBox ([Widget n] -> Widget n) -> [Widget n] -> Widget n
forall a b. (a -> b) -> a -> b
$
      [[Widget n]] -> [Widget n]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [(b -> Widget n) -> [b] -> [Widget n]
forall a b. (a -> b) -> [a] -> [b]
map b -> Widget n
beforeFunc [b]
befores, [a -> Widget n
curFunc a
current], (b -> Widget n) -> [b] -> [Widget n]
forall a b. (a -> b) -> [a] -> [b]
map b -> Widget n
afterFunc [b]
afters]

verticalNonEmptyCursorWidgetM ::
  Applicative f =>
  (b -> f (Widget n)) ->
  (a -> f (Widget n)) ->
  (b -> f (Widget n)) ->
  NonEmptyCursor a b ->
  f (Widget n)
verticalNonEmptyCursorWidgetM :: (b -> f (Widget n))
-> (a -> f (Widget n))
-> (b -> f (Widget n))
-> NonEmptyCursor a b
-> f (Widget n)
verticalNonEmptyCursorWidgetM b -> f (Widget n)
beforeFunc a -> f (Widget n)
curFunc b -> f (Widget n)
afterFunc =
  ([b] -> a -> [b] -> f (Widget n))
-> NonEmptyCursor a b -> f (Widget n)
forall b a (m :: * -> *) n.
([b] -> a -> [b] -> m (Widget n))
-> NonEmptyCursor a b -> m (Widget n)
nonEmptyCursorWidgetM (([b] -> a -> [b] -> f (Widget n))
 -> NonEmptyCursor a b -> f (Widget n))
-> ([b] -> a -> [b] -> f (Widget n))
-> NonEmptyCursor a b
-> f (Widget n)
forall a b. (a -> b) -> a -> b
$ \[b]
befores a
current [b]
afters ->
    [Widget n] -> Widget n
forall n. [Widget n] -> Widget n
vBox
      ([Widget n] -> Widget n) -> f [Widget n] -> f (Widget n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [f (Widget n)] -> f [Widget n]
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA
        ([[f (Widget n)]] -> [f (Widget n)]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [(b -> f (Widget n)) -> [b] -> [f (Widget n)]
forall a b. (a -> b) -> [a] -> [b]
map b -> f (Widget n)
beforeFunc [b]
befores, [a -> f (Widget n)
curFunc a
current], (b -> f (Widget n)) -> [b] -> [f (Widget n)]
forall a b. (a -> b) -> [a] -> [b]
map b -> f (Widget n)
afterFunc [b]
afters])

verticalNonEmptyCursorWidget ::
  (b -> Widget n) ->
  (a -> Widget n) ->
  (b -> Widget n) ->
  NonEmptyCursor a b ->
  Widget n
verticalNonEmptyCursorWidget :: (b -> Widget n)
-> (a -> Widget n)
-> (b -> Widget n)
-> NonEmptyCursor a b
-> Widget n
verticalNonEmptyCursorWidget b -> Widget n
beforeFunc a -> Widget n
curFunc b -> Widget n
afterFunc =
  ([b] -> a -> [b] -> Widget n) -> NonEmptyCursor a b -> Widget n
forall b a n.
([b] -> a -> [b] -> Widget n) -> NonEmptyCursor a b -> Widget n
nonEmptyCursorWidget (([b] -> a -> [b] -> Widget n) -> NonEmptyCursor a b -> Widget n)
-> ([b] -> a -> [b] -> Widget n) -> NonEmptyCursor a b -> Widget n
forall a b. (a -> b) -> a -> b
$ \[b]
befores a
current [b]
afters ->
    [Widget n] -> Widget n
forall n. [Widget n] -> Widget n
vBox ([Widget n] -> Widget n) -> [Widget n] -> Widget n
forall a b. (a -> b) -> a -> b
$
      [[Widget n]] -> [Widget n]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [(b -> Widget n) -> [b] -> [Widget n]
forall a b. (a -> b) -> [a] -> [b]
map b -> Widget n
beforeFunc [b]
befores, [a -> Widget n
curFunc a
current], (b -> Widget n) -> [b] -> [Widget n]
forall a b. (a -> b) -> [a] -> [b]
map b -> Widget n
afterFunc [b]
afters]

nonEmptyCursorWidgetM ::
  ([b] -> a -> [b] -> m (Widget n)) -> NonEmptyCursor a b -> m (Widget n)
nonEmptyCursorWidgetM :: ([b] -> a -> [b] -> m (Widget n))
-> NonEmptyCursor a b -> m (Widget n)
nonEmptyCursorWidgetM = ([b] -> a -> [b] -> m (Widget n))
-> NonEmptyCursor a b -> m (Widget n)
forall b a c. ([b] -> a -> [b] -> c) -> NonEmptyCursor a b -> c
foldNonEmptyCursor

nonEmptyCursorWidget ::
  ([b] -> a -> [b] -> Widget n) -> NonEmptyCursor a b -> Widget n
nonEmptyCursorWidget :: ([b] -> a -> [b] -> Widget n) -> NonEmptyCursor a b -> Widget n
nonEmptyCursorWidget = ([b] -> a -> [b] -> Widget n) -> NonEmptyCursor a b -> Widget n
forall b a c. ([b] -> a -> [b] -> c) -> NonEmptyCursor a b -> c
foldNonEmptyCursor