mirror of
https://github.com/jtdaugherty/brick.git
synced 2024-11-29 21:46:11 +03:00
Implement support for the new PositionOnly constructor
The API putCursor will request positioning but keep cursor invisible.
This commit is contained in:
parent
d95cc7f839
commit
ca8b1bae67
@ -115,7 +115,7 @@ library
|
|||||||
Brick.Widgets.Internal
|
Brick.Widgets.Internal
|
||||||
|
|
||||||
build-depends: base < 4.16.0.0,
|
build-depends: base < 4.16.0.0,
|
||||||
vty >= 5.31,
|
vty >= 5.33,
|
||||||
transformers,
|
transformers,
|
||||||
data-clist >= 0.1,
|
data-clist >= 0.1,
|
||||||
directory >= 1.2.5.0,
|
directory >= 1.2.5.0,
|
||||||
|
@ -441,7 +441,10 @@ renderApp vty app appState rs = do
|
|||||||
rs
|
rs
|
||||||
picWithCursor = case theCursor of
|
picWithCursor = case theCursor of
|
||||||
Nothing -> pic { picCursor = NoCursor }
|
Nothing -> pic { picCursor = NoCursor }
|
||||||
Just cloc -> pic { picCursor = AbsoluteCursor (cloc^.locationColumnL)
|
Just cloc -> pic { picCursor = (if cursorLocationVisible cloc
|
||||||
|
then AbsoluteCursor
|
||||||
|
else PositionOnly True)
|
||||||
|
(cloc^.locationColumnL)
|
||||||
(cloc^.locationRowL)
|
(cloc^.locationRowL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ module Brick.Types.Internal
|
|||||||
, CursorLocation(..)
|
, CursorLocation(..)
|
||||||
, cursorLocationL
|
, cursorLocationL
|
||||||
, cursorLocationNameL
|
, cursorLocationNameL
|
||||||
|
, cursorLocationVisibleL
|
||||||
, Context(..)
|
, Context(..)
|
||||||
, EventState(..)
|
, EventState(..)
|
||||||
, EventRO(..)
|
, EventRO(..)
|
||||||
@ -164,6 +165,8 @@ data CursorLocation n =
|
|||||||
-- ^ The location
|
-- ^ The location
|
||||||
, cursorLocationName :: !(Maybe n)
|
, cursorLocationName :: !(Maybe n)
|
||||||
-- ^ The name of the widget associated with the location
|
-- ^ The name of the widget associated with the location
|
||||||
|
, cursorLocationVisible :: !Bool
|
||||||
|
-- ^ Weather the cursor should actually be visible
|
||||||
}
|
}
|
||||||
deriving (Read, Show, Generic, NFData)
|
deriving (Read, Show, Generic, NFData)
|
||||||
|
|
||||||
|
@ -59,6 +59,7 @@ module Brick.Widgets.Core
|
|||||||
|
|
||||||
-- * Cursor placement
|
-- * Cursor placement
|
||||||
, showCursor
|
, showCursor
|
||||||
|
, putCursor
|
||||||
|
|
||||||
-- * Naming
|
-- * Naming
|
||||||
, Named(..)
|
, Named(..)
|
||||||
@ -994,7 +995,16 @@ showCursor :: n -> Location -> Widget n -> Widget n
|
|||||||
showCursor n cloc p =
|
showCursor n cloc p =
|
||||||
Widget (hSize p) (vSize p) $ do
|
Widget (hSize p) (vSize p) $ do
|
||||||
result <- render p
|
result <- render p
|
||||||
return $ result & cursorsL %~ (CursorLocation cloc (Just n):)
|
return $ result & cursorsL %~ (CursorLocation cloc (Just n) True:)
|
||||||
|
|
||||||
|
-- | When rendering the specified widget, also register a cursor
|
||||||
|
-- positioning request using the specified name and location.
|
||||||
|
-- The cursor will only be positioned but not made visible.
|
||||||
|
putCursor :: n -> Location -> Widget n -> Widget n
|
||||||
|
putCursor n cloc p =
|
||||||
|
Widget (hSize p) (vSize p) $ do
|
||||||
|
result <- render p
|
||||||
|
return $ result & cursorsL %~ (CursorLocation cloc (Just n) False:)
|
||||||
|
|
||||||
hRelease :: Widget n -> Maybe (Widget n)
|
hRelease :: Widget n -> Maybe (Widget n)
|
||||||
hRelease p =
|
hRelease p =
|
||||||
|
@ -798,7 +798,7 @@ renderFileInfo foc maxLen selFiles n listSel info =
|
|||||||
addAttr = maybe id (withDefAttr . attrForFileType) (fileInfoFileType info)
|
addAttr = maybe id (withDefAttr . attrForFileType) (fileInfoFileType info)
|
||||||
body = addAttr (hLimit (maxLen + 1) $
|
body = addAttr (hLimit (maxLen + 1) $
|
||||||
padRight Max $
|
padRight Max $
|
||||||
(if foc && listSel then showCursor n (Location (0,0)) else id) $
|
(if foc && listSel then putCursor n (Location (0,0)) else id) $
|
||||||
str $ fileInfoSanitizedFilename info <> suffix)
|
str $ fileInfoSanitizedFilename info <> suffix)
|
||||||
suffix = (if fileInfoFileType info == Just Directory then "/" else "") <>
|
suffix = (if fileInfoFileType info == Just Directory then "/" else "") <>
|
||||||
(if sel then "*" else "")
|
(if sel then "*" else "")
|
||||||
|
Loading…
Reference in New Issue
Block a user