module Proteome.Buffers where

import Control.Lens (elemOf, view)
import qualified Data.List.NonEmpty as NonEmpty
import qualified Data.Text as Text
import Exon (exon)
import Ribosome (
  Handler,
  Report,
  Rpc,
  RpcError,
  ScratchId (ScratchId),
  SettingError,
  Settings,
  mapReport,
  pathText,
  resumeReport,
  )
import Ribosome.Api (
  bufferGetName,
  bufferGetNumber,
  bufferIsFile,
  buflisted,
  ensureMainWindow,
  nvimBufIsLoaded,
  nvimCommand,
  nvimCwd,
  setCurrentBuffer,
  vimGetCurrentBuffer,
  vimGetCurrentWindow,
  vimSetCurrentWindow,
  )
import Ribosome.Menu (
  Filter (Fuzzy),
  Mappings,
  MenuAction (Render),
  MenuItem (MenuItem),
  MenuWidget,
  ModalState,
  ModalWindowMenus,
  deleteSelected,
  menuState,
  modal,
  staticWindowMenu,
  unselected,
  use,
  withFocus,
  withSelection',
  )
import Ribosome.Scratch (ScratchOptions (..))
import qualified Ribosome.Settings as Settings

import Proteome.Buffers.Syntax (buffersSyntax)
import qualified Proteome.Data.Env as Env
import Proteome.Data.Env (Env)
import qualified Proteome.Data.ListedBuffer as ListedBuffer
import Proteome.Data.ListedBuffer (ListedBuffer (ListedBuffer))
import Proteome.Menu (handleResult)
import qualified Proteome.Settings as Settings

newtype BufferAction =
  Load ListedBuffer
  deriving stock (BufferAction -> BufferAction -> Bool
(BufferAction -> BufferAction -> Bool)
-> (BufferAction -> BufferAction -> Bool) -> Eq BufferAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BufferAction -> BufferAction -> Bool
$c/= :: BufferAction -> BufferAction -> Bool
== :: BufferAction -> BufferAction -> Bool
$c== :: BufferAction -> BufferAction -> Bool
Eq, Int -> BufferAction -> ShowS
[BufferAction] -> ShowS
BufferAction -> String
(Int -> BufferAction -> ShowS)
-> (BufferAction -> String)
-> ([BufferAction] -> ShowS)
-> Show BufferAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BufferAction] -> ShowS
$cshowList :: [BufferAction] -> ShowS
show :: BufferAction -> String
$cshow :: BufferAction -> String
showsPrec :: Int -> BufferAction -> ShowS
$cshowsPrec :: Int -> BufferAction -> ShowS
Show)

type BuffersState =
  ModalState ListedBuffer

loadListedBuffer ::
  Member Rpc r =>
  ListedBuffer ->
  Sem r ()
loadListedBuffer :: forall (r :: EffectRow). Member Rpc r => ListedBuffer -> Sem r ()
loadListedBuffer (ListedBuffer Buffer
buffer Int
number Text
_) =
  Sem r Bool -> Sem r () -> Sem r () -> Sem r ()
forall (m :: * -> *) a. Monad m => m Bool -> m a -> m a -> m a
ifM (Buffer -> Sem r Bool
forall (m :: * -> *). MonadRpc m => Buffer -> m Bool
nvimBufIsLoaded Buffer
buffer) (Buffer -> Sem r ()
forall (m :: * -> *). MonadRpc m => Buffer -> m ()
setCurrentBuffer Buffer
buffer) (Text -> Sem r ()
forall (m :: * -> *). MonadRpc m => Text -> m ()
nvimCommand [exon|buffer #{show number}|])

load ::
  MenuWidget BuffersState r BufferAction
load :: forall (r :: EffectRow). MenuWidget BuffersState r BufferAction
load =
  (Item BuffersState
 -> Sem (Menu BuffersState : Reader Prompt : r) BufferAction)
-> Sem
     (Menu BuffersState : Reader Prompt : r)
     (Maybe (MenuAction BufferAction))
forall s (r :: EffectRow) a.
(MenuState s, Member (Menu s) r) =>
(Item s -> Sem r a) -> Sem r (Maybe (MenuAction a))
withFocus (BufferAction
-> Sem (Menu BuffersState : Reader Prompt : r) BufferAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure (BufferAction
 -> Sem (Menu BuffersState : Reader Prompt : r) BufferAction)
-> (ListedBuffer -> BufferAction)
-> ListedBuffer
-> Sem (Menu BuffersState : Reader Prompt : r) BufferAction
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ListedBuffer -> BufferAction
Load)

compensateForMissingActiveBuffer ::
  Member Rpc r =>
  NonEmpty ListedBuffer ->
  [ListedBuffer] ->
  Sem r ()
compensateForMissingActiveBuffer :: forall (r :: EffectRow).
Member Rpc r =>
NonEmpty ListedBuffer -> [ListedBuffer] -> Sem r ()
compensateForMissingActiveBuffer NonEmpty ListedBuffer
_ [] =
  Text -> Sem r ()
forall (m :: * -> *). MonadRpc m => Text -> m ()
nvimCommand Text
"enew"
compensateForMissingActiveBuffer NonEmpty ListedBuffer
marked (ListedBuffer
next : [ListedBuffer]
_) = do
  Window
prev <- Sem r Window
forall (m :: * -> *). MonadRpc m => m Window
vimGetCurrentWindow
  Sem r Window -> Sem r ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Sem r Window
forall (r :: EffectRow). Member Rpc r => Sem r Window
ensureMainWindow
  Buffer
current <- Sem r Buffer
forall (m :: * -> *). MonadRpc m => m Buffer
vimGetCurrentBuffer
  Bool -> Sem r () -> Sem r ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Getting Any (NonEmpty ListedBuffer) Buffer
-> Buffer -> NonEmpty ListedBuffer -> Bool
forall a s. Eq a => Getting Any s a -> a -> s -> Bool
elemOf ((ListedBuffer -> Const Any ListedBuffer)
-> NonEmpty ListedBuffer -> Const Any (NonEmpty ListedBuffer)
forall s t a b. Each s t a b => Traversal s t a b
each ((ListedBuffer -> Const Any ListedBuffer)
 -> NonEmpty ListedBuffer -> Const Any (NonEmpty ListedBuffer))
-> ((Buffer -> Const Any Buffer)
    -> ListedBuffer -> Const Any ListedBuffer)
-> Getting Any (NonEmpty ListedBuffer) Buffer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IsLabel
  "buffer"
  ((Buffer -> Const Any Buffer)
   -> ListedBuffer -> Const Any ListedBuffer)
(Buffer -> Const Any Buffer)
-> ListedBuffer -> Const Any ListedBuffer
#buffer) Buffer
current NonEmpty ListedBuffer
marked) (ListedBuffer -> Sem r ()
forall (r :: EffectRow). Member Rpc r => ListedBuffer -> Sem r ()
loadListedBuffer ListedBuffer
next)
  Window -> Sem r ()
forall (m :: * -> *). MonadRpc m => Window -> m ()
vimSetCurrentWindow Window
prev

deleteListedBuffersWith ::
  Member Rpc r =>
  Text ->
  NonEmpty ListedBuffer ->
  Sem r ()
deleteListedBuffersWith :: forall (r :: EffectRow).
Member Rpc r =>
Text -> NonEmpty ListedBuffer -> Sem r ()
deleteListedBuffersWith Text
deleter NonEmpty ListedBuffer
bufs =
  Text -> Sem r ()
forall (m :: * -> *). MonadRpc m => Text -> m ()
nvimCommand [exon|#{deleter} #{numbers}|]
  where
    numbers :: Text
numbers =
      [Text] -> Text
forall t. IsText t "unwords" => [t] -> t
unwords (Int -> Text
forall b a. (Show a, IsString b) => a -> b
show (Int -> Text) -> (ListedBuffer -> Int) -> ListedBuffer -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ListedBuffer -> Int
ListedBuffer.number (ListedBuffer -> Text) -> [ListedBuffer] -> [Text]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NonEmpty ListedBuffer -> [ListedBuffer]
forall a. NonEmpty a -> [a]
NonEmpty.toList NonEmpty ListedBuffer
bufs)

deleteWith ::
  Member Rpc r =>
  Text ->
  MenuWidget BuffersState r a
deleteWith :: forall (r :: EffectRow) a.
Member Rpc r =>
Text -> MenuWidget BuffersState r a
deleteWith Text
deleter =
  Sem
  (State (WithCursor BuffersState)
     : Menu BuffersState : Reader Prompt : r)
  (Maybe (MenuAction a))
-> Sem
     (Menu BuffersState : Reader Prompt : r) (Maybe (MenuAction a))
forall s (r :: EffectRow).
Member (Menu s) r =>
InterpreterFor (State (WithCursor s)) r
menuState (Sem
   (State (WithCursor BuffersState)
      : Menu BuffersState : Reader Prompt : r)
   (Maybe (MenuAction a))
 -> Sem
      (Menu BuffersState : Reader Prompt : r) (Maybe (MenuAction a)))
-> Sem
     (State (WithCursor BuffersState)
        : Menu BuffersState : Reader Prompt : r)
     (Maybe (MenuAction a))
-> Sem
     (Menu BuffersState : Reader Prompt : r) (Maybe (MenuAction a))
forall a b. (a -> b) -> a -> b
$ (NonEmpty (Item BuffersState)
 -> Sem
      (State (WithCursor BuffersState)
         : Menu BuffersState : Reader Prompt : r)
      (MenuAction a))
-> Sem
     (State (WithCursor BuffersState)
        : Menu BuffersState : Reader Prompt : r)
     (Maybe (MenuAction a))
forall s (r :: EffectRow) a.
(MenuState s, Member (Menu s) r) =>
(NonEmpty (Item s) -> Sem r a) -> Sem r (Maybe a)
withSelection' \ NonEmpty (Item BuffersState)
delete -> do
    [ListedBuffer]
keep <- (MenuItem (Item BuffersState) -> ListedBuffer)
-> [MenuItem (Item BuffersState)] -> [ListedBuffer]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Getting ListedBuffer (MenuItem (Item BuffersState)) ListedBuffer
-> MenuItem (Item BuffersState) -> ListedBuffer
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view IsLabel
  "meta"
  (Getting ListedBuffer (MenuItem (Item BuffersState)) ListedBuffer)
Getting ListedBuffer (MenuItem (Item BuffersState)) ListedBuffer
#meta) ([MenuItem (Item BuffersState)] -> [ListedBuffer])
-> Sem
     (State (WithCursor BuffersState)
        : Menu BuffersState : Reader Prompt : r)
     [MenuItem (Item BuffersState)]
-> Sem
     (State (WithCursor BuffersState)
        : Menu BuffersState : Reader Prompt : r)
     [ListedBuffer]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Getting
  [MenuItem (Item BuffersState)]
  (WithCursor BuffersState)
  [MenuItem (Item BuffersState)]
-> Sem
     (State (WithCursor BuffersState)
        : Menu BuffersState : Reader Prompt : r)
     [MenuItem (Item BuffersState)]
forall s (r :: EffectRow) a.
Member (State s) r =>
Getting a s a -> Sem r a
use Getting
  [MenuItem (Item BuffersState)]
  (WithCursor BuffersState)
  [MenuItem (Item BuffersState)]
forall s.
MenuState s =>
SimpleGetter (WithCursor s) [MenuItem (Item s)]
unselected
    NonEmpty ListedBuffer
-> [ListedBuffer]
-> Sem
     (State (WithCursor BuffersState)
        : Menu BuffersState : Reader Prompt : r)
     ()
forall (r :: EffectRow).
Member Rpc r =>
NonEmpty ListedBuffer -> [ListedBuffer] -> Sem r ()
compensateForMissingActiveBuffer NonEmpty (Item BuffersState)
NonEmpty ListedBuffer
delete [ListedBuffer]
keep
    Text
-> NonEmpty ListedBuffer
-> Sem
     (State (WithCursor BuffersState)
        : Menu BuffersState : Reader Prompt : r)
     ()
forall (r :: EffectRow).
Member Rpc r =>
Text -> NonEmpty ListedBuffer -> Sem r ()
deleteListedBuffersWith Text
deleter NonEmpty (Item BuffersState)
NonEmpty ListedBuffer
delete
    Sem
  (State (WithCursor BuffersState)
     : Menu BuffersState : Reader Prompt : r)
  ()
forall s (r :: EffectRow).
(MenuState s, Member (State (WithCursor s)) r) =>
Sem r ()
deleteSelected
    pure MenuAction a
forall a. MenuAction a
Render

moveCurrentLast ::
  Member Rpc r =>
  [MenuItem ListedBuffer] ->
  Sem r [MenuItem ListedBuffer]
moveCurrentLast :: forall (r :: EffectRow).
Member Rpc r =>
[MenuItem ListedBuffer] -> Sem r [MenuItem ListedBuffer]
moveCurrentLast [MenuItem ListedBuffer]
items = do
  Buffer
current <- Sem r Buffer
forall (m :: * -> *). MonadRpc m => m Buffer
vimGetCurrentBuffer
  pure $ Buffer
-> [MenuItem ListedBuffer]
-> [MenuItem ListedBuffer]
-> [MenuItem ListedBuffer]
spin Buffer
current [MenuItem ListedBuffer]
items []
  where
    spin :: Buffer
-> [MenuItem ListedBuffer]
-> [MenuItem ListedBuffer]
-> [MenuItem ListedBuffer]
spin Buffer
current (MenuItem ListedBuffer
item : [MenuItem ListedBuffer]
rest) [MenuItem ListedBuffer]
result | MenuItem ListedBuffer
item MenuItem ListedBuffer
-> Getting Buffer (MenuItem ListedBuffer) Buffer -> Buffer
forall s a. s -> Getting a s a -> a
^. Getting Buffer (MenuItem ListedBuffer) Buffer
lens Buffer -> Buffer -> Bool
forall a. Eq a => a -> a -> Bool
== Buffer
current =
      [MenuItem ListedBuffer]
result [MenuItem ListedBuffer]
-> [MenuItem ListedBuffer] -> [MenuItem ListedBuffer]
forall a. [a] -> [a] -> [a]
++ [MenuItem ListedBuffer]
rest [MenuItem ListedBuffer]
-> [MenuItem ListedBuffer] -> [MenuItem ListedBuffer]
forall a. [a] -> [a] -> [a]
++ [Item [MenuItem ListedBuffer]
MenuItem ListedBuffer
item]
    spin Buffer
current (MenuItem ListedBuffer
item : [MenuItem ListedBuffer]
rest) [MenuItem ListedBuffer]
result =
      Buffer
-> [MenuItem ListedBuffer]
-> [MenuItem ListedBuffer]
-> [MenuItem ListedBuffer]
spin Buffer
current [MenuItem ListedBuffer]
rest (MenuItem ListedBuffer
item MenuItem ListedBuffer
-> [MenuItem ListedBuffer] -> [MenuItem ListedBuffer]
forall a. a -> [a] -> [a]
: [MenuItem ListedBuffer]
result)
    spin Buffer
_ [] [MenuItem ListedBuffer]
result =
      [MenuItem ListedBuffer]
result
    lens :: Getting Buffer (MenuItem ListedBuffer) Buffer
lens =
      #meta . #buffer

buffers ::
  Members [AtomicState Env, Settings !! SettingError, Rpc, Rpc !! RpcError] r =>
  Sem r [MenuItem ListedBuffer]
buffers :: forall (r :: EffectRow).
Members
  '[AtomicState Env, Settings !! SettingError, Rpc, Rpc !! RpcError]
  r =>
Sem r [MenuItem ListedBuffer]
buffers = do
  Path Abs Dir
cwd <- Sem r (Path Abs Dir)
forall (m :: * -> *). MonadRpc m => m (Path Abs Dir)
nvimCwd
  [Buffer]
bufs <- (Buffer -> Sem r Bool) -> [Buffer] -> Sem r [Buffer]
forall (m :: * -> *) a.
Applicative m =>
(a -> m Bool) -> [a] -> m [a]
filterM Buffer -> Sem r Bool
forall (m :: * -> *). MonadRpc m => Buffer -> m Bool
bufferIsFile ([Buffer] -> Sem r [Buffer]) -> Sem r [Buffer] -> Sem r [Buffer]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (Buffer -> Sem r Bool) -> [Buffer] -> Sem r [Buffer]
forall (m :: * -> *) a.
Applicative m =>
(a -> m Bool) -> [a] -> m [a]
filterM Buffer -> Sem r Bool
forall (r :: EffectRow).
Member (Rpc !! RpcError) r =>
Buffer -> Sem r Bool
buflisted ([Buffer] -> Sem r [Buffer]) -> Sem r [Buffer] -> Sem r [Buffer]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (Env -> [Buffer]) -> Sem r [Buffer]
forall s s' (r :: EffectRow).
Member (AtomicState s) r =>
(s -> s') -> Sem r s'
atomicGets Env -> [Buffer]
Env.buffers
  [Int]
numbers <- (Buffer -> Sem r Int) -> [Buffer] -> Sem r [Int]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Buffer -> Sem r Int
forall (m :: * -> *). MonadRpc m => Buffer -> m Int
bufferGetNumber [Buffer]
bufs
  [Text]
names <- (Buffer -> Sem r Text) -> [Buffer] -> Sem r [Text]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Buffer -> Sem r Text
forall (m :: * -> *). MonadRpc m => Buffer -> m Text
bufferGetName [Buffer]
bufs
  let items :: [MenuItem ListedBuffer]
items = Text -> Int -> (Buffer, Int, Text) -> MenuItem ListedBuffer
item (Path Abs Dir -> Text
forall b t. Path b t -> Text
pathText Path Abs Dir
cwd) ([Int] -> Int
padding [Int]
numbers) ((Buffer, Int, Text) -> MenuItem ListedBuffer)
-> [(Buffer, Int, Text)] -> [MenuItem ListedBuffer]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Buffer] -> [Int] -> [Text] -> [(Buffer, Int, Text)]
forall a b c. [a] -> [b] -> [c] -> [(a, b, c)]
zip3 [Buffer]
bufs [Int]
numbers [Text]
names
  Sem r Bool
-> Sem r [MenuItem ListedBuffer]
-> Sem r [MenuItem ListedBuffer]
-> Sem r [MenuItem ListedBuffer]
forall (m :: * -> *) a. Monad m => m Bool -> m a -> m a -> m a
ifM (Bool -> Setting Bool -> Sem r Bool
forall a (r :: EffectRow).
(MsgpackDecode a, Member (Settings !! SettingError) r) =>
a -> Setting a -> Sem r a
Settings.or Bool
False Setting Bool
Settings.buffersCurrentLast) ([MenuItem ListedBuffer] -> Sem r [MenuItem ListedBuffer]
forall (r :: EffectRow).
Member Rpc r =>
[MenuItem ListedBuffer] -> Sem r [MenuItem ListedBuffer]
moveCurrentLast [MenuItem ListedBuffer]
items) ([MenuItem ListedBuffer] -> Sem r [MenuItem ListedBuffer]
forall (f :: * -> *) a. Applicative f => a -> f a
pure [MenuItem ListedBuffer]
items)
  where
    padding :: [Int] -> Int
padding =
      Text -> Int
Text.length (Text -> Int) -> ([Int] -> Text) -> [Int] -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Text
forall b a. (Show a, IsString b) => a -> b
show (Int -> Text) -> ([Int] -> Int) -> [Int] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Int] -> Int
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum
    item :: Text -> Int -> (Buffer, Int, Text) -> MenuItem ListedBuffer
item Text
cwd Int
pad (Buffer
buf, Int
num, Text
name) =
      ListedBuffer -> Text -> Text -> MenuItem ListedBuffer
forall a. a -> Text -> Text -> MenuItem a
MenuItem (Buffer -> Int -> Text -> ListedBuffer
ListedBuffer Buffer
buf Int
num Text
name) Text
text' Text
text'
      where
        text' :: Text
text' =
          Text
" * " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text -> Text
padded Int
pad (Int -> Text
forall b a. (Show a, IsString b) => a -> b
show Int
num) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"  " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> Text -> Text
strip Text
cwd Text
name
    padded :: Int -> Text -> Text
padded Int
pad Text
num =
      Int -> Text -> Text
Text.replicate (Int
pad Int -> Int -> Int
forall a. Num a => a -> a -> a
- Text -> Int
Text.length Text
num) Text
" " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
num
    strip :: Text -> Text -> Text
strip Text
cwd Text
name =
      Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
name (Maybe Text -> Text) -> Maybe Text -> Text
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Maybe Text
Text.stripPrefix Text
cwd Text
name

actions ::
  Member Rpc r =>
  Mappings BuffersState r BufferAction
actions :: forall (r :: EffectRow).
Member Rpc r =>
Mappings BuffersState r BufferAction
actions =
  [
    (MappingSpec
"<cr>", MenuWidget BuffersState r BufferAction
forall (r :: EffectRow). MenuWidget BuffersState r BufferAction
load),
    (MappingSpec
"d", Text -> MenuWidget BuffersState r BufferAction
forall (r :: EffectRow) a.
Member Rpc r =>
Text -> MenuWidget BuffersState r a
deleteWith Text
"bdelete"),
    (MappingSpec
"D", Text -> MenuWidget BuffersState r BufferAction
forall (r :: EffectRow) a.
Member Rpc r =>
Text -> MenuWidget BuffersState r a
deleteWith Text
"bdelete!"),
    (MappingSpec
"w", Text -> MenuWidget BuffersState r BufferAction
forall (r :: EffectRow) a.
Member Rpc r =>
Text -> MenuWidget BuffersState r a
deleteWith Text
"bwipeout"),
    (MappingSpec
"W", Text -> MenuWidget BuffersState r BufferAction
forall (r :: EffectRow) a.
Member Rpc r =>
Text -> MenuWidget BuffersState r a
deleteWith Text
"bwipeout!")
  ]

bufferAction ::
  Member Rpc r =>
  BufferAction ->
  Sem r ()
bufferAction :: forall (r :: EffectRow). Member Rpc r => BufferAction -> Sem r ()
bufferAction = \case
  Load ListedBuffer
buf ->
    ListedBuffer -> Sem r ()
forall (r :: EffectRow). Member Rpc r => ListedBuffer -> Sem r ()
loadListedBuffer ListedBuffer
buf

type BuffersStack =
  [
    ModalWindowMenus () ListedBuffer !! RpcError,
    AtomicState Env,
    Settings !! SettingError,
    Rpc !! RpcError,
    Log
  ]

buffersMenu ::
   r .
  Members BuffersStack r =>
  Members [Rpc, Stop Report] r =>
  Sem r ()
buffersMenu :: forall (r :: EffectRow).
(Members BuffersStack r, Members '[Rpc, Stop Report] r) =>
Sem r ()
buffersMenu = do
  [MenuItem ListedBuffer]
items <- Sem r [MenuItem ListedBuffer]
forall (r :: EffectRow).
Members
  '[AtomicState Env, Settings !! SettingError, Rpc, Rpc !! RpcError]
  r =>
Sem r [MenuItem ListedBuffer]
buffers
  MenuResult BufferAction
result <- Sem (Stop RpcError : r) (MenuResult BufferAction)
-> Sem r (MenuResult BufferAction)
forall e (r :: EffectRow) a.
(Reportable e, Member (Stop Report) r) =>
Sem (Stop e : r) a -> Sem r a
mapReport do
    [MenuItem (Item BuffersState)]
-> BuffersState
-> WindowOptions
-> Mappings BuffersState (Stop RpcError : r) BufferAction
-> Sem (Stop RpcError : r) (MenuResult BufferAction)
forall mres result s (r :: EffectRow).
(MenuState s,
 Members
   '[UiMenus WindowConfig mres s !! RpcError, Log, Stop RpcError]
   r) =>
[MenuItem (Item s)]
-> s
-> WindowOptions
-> Mappings s r result
-> Sem r (MenuResult result)
staticWindowMenu [MenuItem (Item BuffersState)]
[MenuItem ListedBuffer]
items (Filter -> BuffersState
forall mode i. mode -> Modal mode i
modal Filter
Fuzzy) (WindowOptions
forall a. Default a => a
def WindowOptions -> (WindowOptions -> WindowOptions) -> WindowOptions
forall a b. a -> (a -> b) -> b
& IsLabel
  "items"
  (ASetter WindowOptions WindowOptions ScratchOptions ScratchOptions)
ASetter WindowOptions WindowOptions ScratchOptions ScratchOptions
#items ASetter WindowOptions WindowOptions ScratchOptions ScratchOptions
-> ScratchOptions -> WindowOptions -> WindowOptions
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ScratchOptions
scratchOptions) Mappings BuffersState (Stop RpcError : r) BufferAction
forall (r :: EffectRow).
Member Rpc r =>
Mappings BuffersState r BufferAction
actions
  (BufferAction -> Sem r ()) -> MenuResult BufferAction -> Sem r ()
forall (r :: EffectRow) a.
Members '[Rpc, Stop Report] r =>
(a -> Sem r ()) -> MenuResult a -> Sem r ()
handleResult BufferAction -> Sem r ()
forall (r :: EffectRow). Member Rpc r => BufferAction -> Sem r ()
bufferAction MenuResult BufferAction
result
  where
    scratchOptions :: ScratchOptions
scratchOptions =
      ScratchOptions
forall a. Default a => a
def {
        $sel:name:ScratchOptions :: ScratchId
name = Text -> ScratchId
ScratchId Text
name,
        $sel:syntax:ScratchOptions :: [Syntax]
syntax = [Item [Syntax]
Syntax
buffersSyntax],
        $sel:filetype:ScratchOptions :: Maybe Text
filetype = Text -> Maybe Text
forall a. a -> Maybe a
Just Text
name
      }
    name :: Text
name =
      Text
"proteome-buffers"

proBuffers ::
  Members BuffersStack r =>
  Handler r ()
proBuffers :: forall (r :: EffectRow). Members BuffersStack r => Handler r ()
proBuffers =
  forall (eff :: (* -> *) -> * -> *) e (r :: EffectRow) a.
(Reportable e, Members '[eff !! e, Stop Report] r) =>
Sem (eff : r) a -> Sem r a
resumeReport @Rpc do
    Sem (Rpc : Stop Report : r) ()
forall (r :: EffectRow).
(Members BuffersStack r, Members '[Rpc, Stop Report] r) =>
Sem r ()
buffersMenu