Browse Source

Track changes to Byline

tags/v0.2.0.0
Peter J. Jones 4 years ago
parent
commit
ed821a1a84

+ 4
- 0
default.nix View File

@@ -9,10 +9,13 @@ let
# Libraries:
aeson
ansi-terminal
base
binary
bytestring
colour
containers
either
exceptions
haskeline
http-client
http-client-tls
@@ -25,6 +28,7 @@ let
parsec
process
temporary
terminfo-hs
text
text-binary
time

+ 2
- 1
src/Vimeta/UI/CommandLine/Config.hs View File

@@ -19,6 +19,7 @@ module Vimeta.UI.CommandLine.Config
) where

--------------------------------------------------------------------------------
import Control.Monad
import Control.Monad.Trans.Either
import Data.Monoid
import Data.Text (Text)
@@ -65,7 +66,7 @@ run opts = do

where
byline :: ReportType -> String -> IO ()
byline rt = runByline . reportLn rt . text . Text.pack
byline rt = void . runByline . reportLn rt . text . Text.pack

--------------------------------------------------------------------------------
app :: Options -> Config -> EitherT String IO (Maybe String)

+ 10
- 9
src/Vimeta/UI/Term/Common.hs View File

@@ -14,11 +14,12 @@ the LICENSE file.
--------------------------------------------------------------------------------
module Vimeta.UI.Term.Common
( byline
, bylineMaybe
, notEmpty
, execVimetaBylineApp
) where

--------------------------------------------------------------------------------
import Control.Monad
import Control.Monad.Trans.Class (lift)
import Data.Text (Text)
import qualified Data.Text as Text
@@ -33,18 +34,18 @@ byline :: Byline IO a -> Vimeta (Byline IO) a
byline = Vimeta . lift . lift

--------------------------------------------------------------------------------
bylineMaybe :: Text -> Byline IO (Maybe a) -> Vimeta (Byline IO) a
bylineMaybe msg bm = do
result <- byline bm
case result of
Nothing -> die (Text.unpack msg)
Just a -> return a
notEmpty :: Stylized -> Text -> IO (Either Stylized Text)
notEmpty errortxt input = return $ if Text.length clean > 0
then Right clean
else Left errortxt
where
clean :: Text
clean = Text.strip input

--------------------------------------------------------------------------------
-- | Helper function to run a 'Vimeta' value based in 'Byline'.
execVimetaBylineApp :: (Config -> Config) -> Vimeta (Byline IO) () -> IO ()
execVimetaBylineApp cf vimeta = runByline $ do
execVimetaBylineApp cf vimeta = void $ runByline $ do
v <- execVimeta cf vimeta

case v of

+ 7
- 3
src/Vimeta/UI/Term/MovieSearch.hs View File

@@ -18,8 +18,6 @@ module Vimeta.UI.Term.MovieSearch
) where

--------------------------------------------------------------------------------
import Control.Applicative
import Data.Maybe
import Data.Monoid
import Data.Text (Text)
import Network.API.TheMovieDB
@@ -32,7 +30,7 @@ import Vimeta.UI.Util
-- | Search for a movie and interact with the user through the terminal.
search :: Text -> Vimeta (Byline IO) Movie
search initial = do
name <- byline $ fromMaybe initial <$> ask "search (movie name): " (Just initial)
name <- byline $ askUntil searchPrompt (Just initial) (notEmpty searchErr)
movies <- tmdb (searchMovies name)
answer <- byline $ askWithMenuRepeatedly (mkMenu movies) prompt eprompt

@@ -44,6 +42,12 @@ search initial = do
-- The Menu.
mkMenu movies = banner "Choose a movie:" (menu movies displayMovie)

-- Search prompt.
searchPrompt = "search (movie name): "

-- Search error text.
searchErr = "please enter a valid search term" <> fg red

-- Menu prompt.
prompt = "movie> "


+ 1
- 1
src/Vimeta/UI/Term/TVSearch.hs View File

@@ -33,7 +33,7 @@ search = do
mprompt = "tv> "
eprompt = text message <> fg red

name <- bylineMaybe message $ ask prompt Nothing
name <- byline (askUntil prompt Nothing $ notEmpty eprompt)
series <- tmdb (searchTV name)
answer <- byline $ askWithMenuRepeatedly (mkMenu series) mprompt eprompt


+ 1
- 1
src/Vimeta/UI/Util.hs View File

@@ -28,7 +28,7 @@ import System.Locale (defaultTimeLocale)
--------------------------------------------------------------------------------
-- | Wrap some text with parenthesis.
parens :: Text -> Text
parens t = "(" <> t <> ")"
parens t = " (" <> t <> ")"

--------------------------------------------------------------------------------
-- | Format a 'Maybe Day' as a year ('Text').

+ 1
- 1
vendor/byline

@@ -1 +1 @@
Subproject commit 3f98ff82031913ec9ef28e521747f0ead5e6ae86
Subproject commit e7677e308a55c2b5f24a2399498128fce19f81e5

Loading…
Cancel
Save