mirror of
https://github.com/jtdaugherty/brick.git
synced 2024-11-22 05:36:00 +03:00
Add Brick.Main.customMainWithDefaultVty (fixes #488)
This commit is contained in:
parent
3852513d21
commit
c1aef1106e
@ -453,7 +453,6 @@ executable brick-custom-event-demo
|
||||
build-depends: base,
|
||||
brick,
|
||||
vty,
|
||||
vty-crossplatform,
|
||||
text,
|
||||
microlens >= 0.3.0.0,
|
||||
microlens-th,
|
||||
|
@ -12,13 +12,12 @@ import Control.Concurrent (threadDelay, forkIO)
|
||||
import Data.Monoid
|
||||
#endif
|
||||
import qualified Graphics.Vty as V
|
||||
import Graphics.Vty.CrossPlatform (mkVty)
|
||||
|
||||
import Brick.BChan
|
||||
import Brick.Main
|
||||
( App(..)
|
||||
, showFirstCursor
|
||||
, customMain
|
||||
, customMainWithDefaultVty
|
||||
, halt
|
||||
)
|
||||
import Brick.AttrMap
|
||||
@ -83,6 +82,4 @@ main = do
|
||||
writeBChan chan Counter
|
||||
threadDelay 1000000
|
||||
|
||||
let buildVty = mkVty V.defaultConfig
|
||||
initialVty <- buildVty
|
||||
void $ customMain initialVty buildVty (Just chan) theApp initialState
|
||||
void $ customMainWithDefaultVty (Just chan) theApp initialState
|
||||
|
@ -143,10 +143,9 @@ randomVal as = do
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
vty <- mkVty V.defaultConfig
|
||||
chan <- newBChan 10
|
||||
|
||||
-- Run thread to simulate incoming data
|
||||
void $ forkIO $ generateLines chan
|
||||
|
||||
void $ customMain vty (mkVty V.defaultConfig) (Just chan) app initialState
|
||||
void $ customMainWithDefaultVty (Just chan) app initialState
|
||||
|
@ -5,6 +5,7 @@ module Brick.Main
|
||||
, defaultMain
|
||||
, customMain
|
||||
, customMainWithVty
|
||||
, customMainWithDefaultVty
|
||||
, simpleMain
|
||||
, resizeOrQuit
|
||||
, simpleApp
|
||||
@ -130,10 +131,8 @@ defaultMain :: (Ord n)
|
||||
-> s
|
||||
-- ^ The initial application state.
|
||||
-> IO s
|
||||
defaultMain app st = do
|
||||
let builder = mkVty defaultConfig
|
||||
initialVty <- builder
|
||||
customMain initialVty builder Nothing app st
|
||||
defaultMain app st =
|
||||
fst <$> customMainWithDefaultVty Nothing app st
|
||||
|
||||
-- | A simple main entry point which takes a widget and renders it. This
|
||||
-- event loop terminates when the user presses any key, but terminal
|
||||
@ -235,6 +234,25 @@ customMain initialVty buildVty mUserChan app initialAppState = do
|
||||
restoreInitialState
|
||||
return s
|
||||
|
||||
-- | Like 'customMainWithVty', except that Vty is initialized with the
|
||||
-- default configuration.
|
||||
customMainWithDefaultVty :: (Ord n)
|
||||
=> Maybe (BChan e)
|
||||
-- ^ An event channel for sending custom
|
||||
-- events to the event loop (you write to this
|
||||
-- channel, the event loop reads from it).
|
||||
-- Provide 'Nothing' if you don't plan on
|
||||
-- sending custom events.
|
||||
-> App s e n
|
||||
-- ^ The application.
|
||||
-> s
|
||||
-- ^ The initial application state.
|
||||
-> IO (s, Vty)
|
||||
customMainWithDefaultVty mUserChan app initialAppState = do
|
||||
let builder = mkVty defaultConfig
|
||||
vty <- builder
|
||||
customMainWithVty vty builder mUserChan app initialAppState
|
||||
|
||||
-- | Like 'customMain', except the last 'Vty' handle used by the
|
||||
-- application is returned without being shut down with 'shutdown'. This
|
||||
-- allows the caller to re-use the 'Vty' handle for something else, such
|
||||
|
Loading…
Reference in New Issue
Block a user