{-# LANGUAGE RankNTypes #-}
module Matterhorn.Draw.ManageAttachments
( drawAttachmentList
, drawFileBrowser
)
where
import Prelude ()
import Matterhorn.Prelude
import Brick
import Brick.Keybindings
import Brick.Widgets.Border
import Brick.Widgets.Center
import qualified Brick.Widgets.FileBrowser as FB
import Brick.Widgets.List
import Data.Maybe ( fromJust )
import Lens.Micro.Platform ( Lens' )
import Matterhorn.Types
import Matterhorn.Themes
drawAttachmentList :: ChatState -> Lens' ChatState (MessageInterface Name i) -> Widget Name
drawAttachmentList :: forall i.
ChatState
-> Lens' ChatState (MessageInterface Name i) -> Widget Name
drawAttachmentList ChatState
st Lens' ChatState (MessageInterface Name i)
which =
let addBinding :: Text
addBinding = Maybe Binding -> Text
ppMaybeBinding forall a b. (a -> b) -> a -> b
$ forall k. (Show k, Ord k) => KeyConfig k -> k -> Maybe Binding
firstActiveBinding KeyConfig KeyEvent
kc KeyEvent
AttachmentListAddEvent
delBinding :: Text
delBinding = Maybe Binding -> Text
ppMaybeBinding forall a b. (a -> b) -> a -> b
$ forall k. (Show k, Ord k) => KeyConfig k -> k -> Maybe Binding
firstActiveBinding KeyConfig KeyEvent
kc KeyEvent
AttachmentListDeleteEvent
escBinding :: Text
escBinding = Maybe Binding -> Text
ppMaybeBinding forall a b. (a -> b) -> a -> b
$ forall k. (Show k, Ord k) => KeyConfig k -> k -> Maybe Binding
firstActiveBinding KeyConfig KeyEvent
kc KeyEvent
CancelEvent
openBinding :: Text
openBinding = Maybe Binding -> Text
ppMaybeBinding forall a b. (a -> b) -> a -> b
$ forall k. (Show k, Ord k) => KeyConfig k -> k -> Maybe Binding
firstActiveBinding KeyConfig KeyEvent
kc KeyEvent
AttachmentOpenEvent
kc :: KeyConfig KeyEvent
kc = ChatState
stforall s a. s -> Getting a s a -> a
^.Lens' ChatState ChatResources
csResourcesforall b c a. (b -> c) -> (a -> b) -> a -> c
.Lens' ChatResources Config
crConfigurationforall b c a. (b -> c) -> (a -> b) -> a -> c
.Lens' Config (KeyConfig KeyEvent)
configUserKeysL
in forall n. Widget n -> Widget n -> Widget n
borderWithLabel (forall n. AttrName -> Widget n -> Widget n
withDefAttr AttrName
clientEmphAttr forall a b. (a -> b) -> a -> b
$ forall n. Text -> Widget n
txt Text
"Attachments") forall a b. (a -> b) -> a -> b
$
forall n. [Widget n] -> Widget n
vBox [ forall (t :: * -> *) n e.
(Traversable t, Splittable t, Ord n, Show n) =>
(Bool -> e -> Widget n) -> Bool -> GenericList n t e -> Widget n
renderList Bool -> AttachmentData -> Widget Name
renderAttachmentItem Bool
True (ChatState
stforall s a. s -> Getting a s a -> a
^.Lens' ChatState (MessageInterface Name i)
whichforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall n i. Lens' (MessageInterface n i) (EditState n)
miEditorforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall n. Lens' (EditState n) (List n AttachmentData)
esAttachmentList)
, forall n. Widget n
hBorder
, forall n. Widget n -> Widget n
hCenter forall a b. (a -> b) -> a -> b
$ forall n. AttrName -> Widget n -> Widget n
withDefAttr AttrName
clientMessageAttr forall a b. (a -> b) -> a -> b
$
forall n. Text -> Widget n
txt forall a b. (a -> b) -> a -> b
$ Text
addBinding forall a. Semigroup a => a -> a -> a
<> Text
":add " forall a. Semigroup a => a -> a -> a
<>
Text
delBinding forall a. Semigroup a => a -> a -> a
<> Text
":delete " forall a. Semigroup a => a -> a -> a
<>
Text
openBinding forall a. Semigroup a => a -> a -> a
<> Text
":open " forall a. Semigroup a => a -> a -> a
<>
Text
escBinding forall a. Semigroup a => a -> a -> a
<> Text
":close"
]
renderAttachmentItem :: Bool -> AttachmentData -> Widget Name
renderAttachmentItem :: Bool -> AttachmentData -> Widget Name
renderAttachmentItem Bool
_ AttachmentData
d =
forall n. Padding -> Widget n -> Widget n
padRight Padding
Max forall a b. (a -> b) -> a -> b
$ forall n. String -> Widget n
str forall a b. (a -> b) -> a -> b
$ FileInfo -> String
FB.fileInfoSanitizedFilename forall a b. (a -> b) -> a -> b
$ AttachmentData -> FileInfo
attachmentDataFileInfo AttachmentData
d
drawFileBrowser :: ChatState -> Lens' ChatState (MessageInterface Name i) -> Widget Name
drawFileBrowser :: forall i.
ChatState
-> Lens' ChatState (MessageInterface Name i) -> Widget Name
drawFileBrowser ChatState
st Lens' ChatState (MessageInterface Name i)
which =
forall n. Widget n -> Widget n -> Widget n
borderWithLabel (forall n. AttrName -> Widget n -> Widget n
withDefAttr AttrName
clientEmphAttr forall a b. (a -> b) -> a -> b
$ forall n. Text -> Widget n
txt Text
"Attach File") forall a b. (a -> b) -> a -> b
$
forall n. (Show n, Ord n) => Bool -> FileBrowser n -> Widget n
FB.renderFileBrowser Bool
True forall a b. (a -> b) -> a -> b
$ forall a. HasCallStack => Maybe a -> a
fromJust (ChatState
stforall s a. s -> Getting a s a -> a
^.Lens' ChatState (MessageInterface Name i)
whichforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall n i. Lens' (MessageInterface n i) (EditState n)
miEditorforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall n. Lens' (EditState n) (Maybe (FileBrowser n))
esFileBrowser)