Browse Source

Remove subtrees, redo build system

tags/v0.2.4.0
Peter J. Jones 1 year ago
parent
commit
909386aa3a
Signed by: Peter Jones <pjones@devalot.com> GPG Key ID: 9DAFAA8D01941E49
63 changed files with 41 additions and 3163 deletions
  1. 0
    1
      cabal.project
  2. 18
    0
      default.nix
  3. 0
    13
      stack.yaml
  4. 0
    2
      vendor/byline/.gitignore
  5. 0
    0
      vendor/byline/.gitmodules
  6. 0
    87
      vendor/byline/.travis.yml
  7. 0
    31
      vendor/byline/CHANGES.md
  8. 0
    28
      vendor/byline/GNUmakefile
  9. 0
    26
      vendor/byline/LICENSE
  10. 0
    23
      vendor/byline/README.md
  11. 0
    2
      vendor/byline/Setup.hs
  12. 0
    25
      vendor/byline/TODO
  13. 0
    110
      vendor/byline/byline.cabal
  14. 0
    45
      vendor/byline/examples/menu.hs
  15. 0
    51
      vendor/byline/examples/simple.hs
  16. 0
    122
      vendor/byline/src/System/Console/Byline.hs
  17. 0
    46
      vendor/byline/src/System/Console/Byline/Color.hs
  18. 0
    36
      vendor/byline/src/System/Console/Byline/Completion.hs
  19. 0
    126
      vendor/byline/src/System/Console/Byline/Internal/Byline.hs
  20. 0
    91
      vendor/byline/src/System/Console/Byline/Internal/Color.hs
  21. 0
    50
      vendor/byline/src/System/Console/Byline/Internal/Completion.hs
  22. 0
    128
      vendor/byline/src/System/Console/Byline/Internal/Render.hs
  23. 0
    59
      vendor/byline/src/System/Console/Byline/Internal/Types.hs
  24. 0
    206
      vendor/byline/src/System/Console/Byline/Menu.hs
  25. 0
    47
      vendor/byline/src/System/Console/Byline/Modifiers.hs
  26. 0
    154
      vendor/byline/src/System/Console/Byline/Primitive.hs
  27. 0
    71
      vendor/byline/src/System/Console/Byline/Stylized.hs
  28. 0
    12
      vendor/byline/stack.yaml
  29. 0
    3
      vendor/themoviedb/.gitignore
  30. 0
    87
      vendor/themoviedb/.travis.yml
  31. 0
    40
      vendor/themoviedb/CHANGES.md
  32. 0
    24
      vendor/themoviedb/LICENSE
  33. 0
    24
      vendor/themoviedb/README.md
  34. 0
    2
      vendor/themoviedb/Setup.hs
  35. 0
    13
      vendor/themoviedb/TODO.org
  36. 0
    145
      vendor/themoviedb/example/Main.hs
  37. 0
    78
      vendor/themoviedb/src/Network/API/TheMovieDB.hs
  38. 0
    80
      vendor/themoviedb/src/Network/API/TheMovieDB/Actions.hs
  39. 0
    63
      vendor/themoviedb/src/Network/API/TheMovieDB/Internal/Configuration.hs
  40. 0
    56
      vendor/themoviedb/src/Network/API/TheMovieDB/Internal/Date.hs
  41. 0
    63
      vendor/themoviedb/src/Network/API/TheMovieDB/Internal/HTTP.hs
  42. 0
    30
      vendor/themoviedb/src/Network/API/TheMovieDB/Internal/SearchResults.hs
  43. 0
    91
      vendor/themoviedb/src/Network/API/TheMovieDB/Internal/TheMovieDB.hs
  44. 0
    57
      vendor/themoviedb/src/Network/API/TheMovieDB/Internal/Types.hs
  45. 0
    79
      vendor/themoviedb/src/Network/API/TheMovieDB/Types/Episode.hs
  46. 0
    38
      vendor/themoviedb/src/Network/API/TheMovieDB/Types/Genre.hs
  47. 0
    86
      vendor/themoviedb/src/Network/API/TheMovieDB/Types/Movie.hs
  48. 0
    75
      vendor/themoviedb/src/Network/API/TheMovieDB/Types/Season.hs
  49. 0
    101
      vendor/themoviedb/src/Network/API/TheMovieDB/Types/TV.hs
  50. 0
    8
      vendor/themoviedb/stack.yaml
  51. 0
    15
      vendor/themoviedb/test/Main.hs
  52. 0
    73
      vendor/themoviedb/test/MovieTest.hs
  53. 0
    78
      vendor/themoviedb/test/TVTest.hs
  54. 0
    39
      vendor/themoviedb/test/TestHelper.hs
  55. 0
    1
      vendor/themoviedb/test/config-good.json
  56. 0
    1
      vendor/themoviedb/test/movie-bad.json
  57. 0
    1
      vendor/themoviedb/test/movie-good.json
  58. 0
    1
      vendor/themoviedb/test/search-good.json
  59. 0
    1
      vendor/themoviedb/test/search-tv-good.json
  60. 0
    1
      vendor/themoviedb/test/season-good.json
  61. 0
    1
      vendor/themoviedb/test/tv-good.json
  62. 0
    116
      vendor/themoviedb/themoviedb.cabal
  63. 23
    0
      vimeta.nix

+ 0
- 1
cabal.project View File

@@ -1 +0,0 @@
packages: ./ vendor/themoviedb vendor/byline

+ 18
- 0
default.nix View File

@@ -0,0 +1,18 @@
# These arguments are so you can override settings from the command
# line using the `nix-hs' tool.
{ nixpkgs ? import <nixpkgs> { }
, compiler ? "default"
, profiling ? false
}:

let
pkgs = nixpkgs;

buildInputs = with pkgs; [
# List extra dependencies here.
atomicparsley
];

in
pkgs.nix-hs.interactive ./vimeta.nix
{ inherit compiler profiling buildInputs; }

+ 0
- 13
stack.yaml View File

@@ -1,13 +0,0 @@
resolver: lts-7.20

packages:
- ./
- ./vendor/byline
- ./vendor/themoviedb

flags:
vimeta:
maintainer: true

extra-deps:
- terminfo-hs-0.2.1

+ 0
- 2
vendor/byline/.gitignore View File

@@ -1,2 +0,0 @@
/.stack-work
/build/.stack-work

+ 0
- 0
vendor/byline/.gitmodules View File


+ 0
- 87
vendor/byline/.travis.yml View File

@@ -1,87 +0,0 @@
# This Travis job script has been generated by a script via
#
# make_travis_yml_2.hs 'byline.cabal'
#
# For more information, see https://github.com/hvr/multi-ghc-travis
#
language: c
sudo: false

git:
submodules: false # whether to recursively clone submodules

cache:
directories:
- $HOME/.cabal/packages
- $HOME/.cabal/store

before_cache:
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/build-reports.log
# remove files that are regenerated by 'cabal update'
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/00-index.*
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/*.json
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.cache
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar.idx

matrix:
include:
- compiler: "ghc-7.8.4"
# env: TEST=--disable-tests BENCH=--disable-benchmarks
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-7.8.4], sources: [hvr-ghc]}}
- compiler: "ghc-7.10.3"
# env: TEST=--disable-tests BENCH=--disable-benchmarks
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-7.10.3], sources: [hvr-ghc]}}
- compiler: "ghc-8.0.1"
# env: TEST=--disable-tests BENCH=--disable-benchmarks
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.0.1], sources: [hvr-ghc]}}

before_install:
- HC=${CC}
- unset CC
- PATH=/opt/ghc/bin:/opt/ghc-ppa-tools/bin:$PATH
- PKGNAME='byline'

install:
- cabal --version
- echo "$(${HC} --version) [$(${HC} --print-project-git-commit-id 2> /dev/null || echo '?')]"
- BENCH=${BENCH---enable-benchmarks}
- TEST=${TEST---enable-tests}
- travis_retry cabal update -v
- sed -i 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config
- rm -fv cabal.project.local
- "echo 'packages: .' > cabal.project"
- rm -f cabal.project.freeze
- cabal new-build -w ${HC} ${TEST} ${BENCH} --dep -j2 all
- cabal new-build -w ${HC} --disable-tests --disable-benchmarks --dep -j2 all

# Here starts the actual work to be performed for the package under test;
# any command which exits with a non-zero exit code causes the build to fail.
script:
- if [ -f configure.ac ]; then autoreconf -i; fi
- rm -rf dist/
- cabal sdist # test that a source-distribution can be generated
- cd dist/
- SRCTAR=(${PKGNAME}-*.tar.gz)
- SRC_BASENAME="${SRCTAR/%.tar.gz}"
- tar -xvf "./$SRC_BASENAME.tar.gz"
- cd "$SRC_BASENAME/"
## from here on, CWD is inside the extracted source-tarball
- rm -fv cabal.project.local
- "echo 'packages: .' > cabal.project"
# this builds all libraries and executables (without tests/benchmarks)
- rm -f cabal.project.freeze
- cabal new-build -w ${HC} --disable-tests --disable-benchmarks all
# this builds all libraries and executables (including tests/benchmarks)
# - rm -rf ./dist-newstyle
- cabal new-build -w ${HC} ${TEST} ${BENCH} all

# there's no 'cabal new-test' yet, so let's emulate for now
- TESTS=( $(awk 'tolower($0) ~ /^test-suite / { print $2 }' *.cabal) )
- if [ "$TEST" != "--enable-tests" ]; then TESTS=(); fi
- shopt -s globstar;
RC=true; for T in ${TESTS[@]}; do echo "== $T ==";
if dist-newstyle/build/**/$SRC_BASENAME/**/build/$T/$T; then echo "= $T OK =";
else echo "= $T FAILED ="; RC=false; fi; done; $RC

# EOF

+ 0
- 31
vendor/byline/CHANGES.md View File

@@ -1,31 +0,0 @@
# Version History

## 0.2.4.0 (March 19, 2017)

- Update dependency bounds

- Add Travis CI build status for supported versions of GHC

## 0.2.3.0 (November 1, 2016)

- Increase upper bound on transformers package to `0.5` (Thanks to
slycelote).

## 0.2.2.0 (June 9, 2016)

- Build under LTS-5.15

## 0.2.1.0 (November 5, 2014)

- Updated dependencies

## 0.2.0.0 (May 22, 2015)

- Added the NoItems constructor for Choice to deal with menus that
are asked to display an empty list.

- Changes to build with GHC 7.8.4. and 7.10.1

## 0.1.0.0 (May 19, 2015)

- Initial release.

+ 0
- 28
vendor/byline/GNUmakefile View File

@@ -1,28 +0,0 @@
################################################################################
export TMPDIR = $(HOME)/tmp

################################################################################
TMP_DUMMY = $(TMPDIR)/.dummy
STACK_OPTS = --stack-yaml=build/stack.yaml

################################################################################
.PHONY: all test clean

################################################################################
all: $(TMP_DUMMY)
stack $(STACK_OPTS) setup
stack $(STACK_OPTS) build
hlint src examples

################################################################################
test:
stack $(STACK_OPTS) test

################################################################################
clean:
stack $(STACK_OPTS) clean

################################################################################
$(TMP_DUMMY):
mkdir -p $(dir $@)
touch $@

+ 0
- 26
vendor/byline/LICENSE View File

@@ -1,26 +0,0 @@
Copyright (c) 2015-2017 Peter J. Jones <pjones@devalot.com>
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the
distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ 0
- 23
vendor/byline/README.md View File

@@ -1,23 +0,0 @@
# Byline

[![Build Status](https://travis-ci.org/pjones/byline.svg?branch=master)](https://travis-ci.org/pjones/byline)

Byline simplifies writing interactive terminal applications by
building upon [ansi-terminal][] and [haskeline][]. This makes it
possible to print messages and prompts that include terminal escape
sequences such as colors that are automatically disabled when standard
input is a file. It also means that Byline works on both
POSIX-compatible systems and on Windows.

The primary features of Byline include printing messages, prompting
for input, and generating custom menus. It was inspired by the
[highline] Ruby library and the [terminal library][] by Craig Roche.

## Examples

Please see the example programs in the `examples` directory.

[ansi-terminal]: http://hackage.haskell.org/package/ansi-terminal
[haskeline]: https://hackage.haskell.org/package/haskeline
[highline]: https://github.com/JEG2/highline
[terminal library]: https://github.com/cdxr/terminal

+ 0
- 2
vendor/byline/Setup.hs View File

@@ -1,2 +0,0 @@
import Distribution.Simple
main = defaultMain

+ 0
- 25
vendor/byline/TODO View File

@@ -1,25 +0,0 @@
-*- org -*-
#+title: To-Do List

* Before First Release
** DONE Restore exception safety in `runByline` and `withCompletionFunc`
CLOSED: [2015-05-18 Mon 19:55]
- I'm not using `runInputT` anymore so we don't get MonadException either
** DONE When rendering colors directly via `ask`, don't use color codes on Windows
CLOSED: [2015-05-18 Mon 18:02]
** DONE Use TERMINFO to figure out if we can use rgb colors
CLOSED: [2015-05-18 Mon 18:02]
** DONE Downgrade full rgb colors to the default terminal colors
CLOSED: [2015-05-18 Mon 18:02]
** DONE Don't loop (in `askUntil`) if running in non-interactive (file) mode
CLOSED: [2015-05-14 Thu 17:00]
** DONE `askWithMenuRepeatedly` should do the right thing if reading from a file
CLOSED: [2015-05-14 Thu 17:01]
** DONE Put the `askUntil` confirmation function into the `Byline m a` monad
CLOSED: [2015-05-14 Thu 17:11]
** DONE Restore the ability to change the completion function
CLOSED: [2015-05-14 Thu 15:23]
** DONE Simplify the interface by aborting on EOF
CLOSED: [2015-05-14 Thu 16:27]
** DONE Remove `MonadException` from the interface
CLOSED: [2015-05-13 Wed 14:39]

+ 0
- 110
vendor/byline/byline.cabal View File

@@ -1,110 +0,0 @@
--------------------------------------------------------------------------------
name: byline
version: 0.2.4.0
synopsis: Library for creating command-line interfaces (colors, menus, etc.)
homepage: http://github.com/pjones/byline
bug-reports: http://github.com/pjones/byline/issues
license: BSD2
license-file: LICENSE
author: Peter Jones <pjones@devalot.com>
maintainer: Peter Jones <pjones@devalot.com>
copyright: Copyright: (c) 2015-2017 Peter J. Jones
category: System, User Interfaces
build-type: Simple
stability: experimental
tested-with: GHC == 7.8.4, GHC == 7.10.3, GHC == 8.0.1
cabal-version: >=1.18
description:
Byline simplifies writing interactive terminal applications by
building upon @ansi-terminal@ and @haskeline@. This makes it
possible to print messages and prompts that include terminal escape
sequences such as colors that are automatically disabled when
standard input is a file. It also means that Byline works on both
POSIX-compatible systems and on Windows.
.
The primary features of Byline include printing messages, prompting
for input, and generating custom menus. It was inspired by the
@highline@ Ruby library and the @terminal@ library by Craig Roche.

--------------------------------------------------------------------------------
extra-source-files:
CHANGES.md
README.md
examples/*.hs

--------------------------------------------------------------------------------
source-repository head
type: git
location: git://github.com/pjones/byline.git

--------------------------------------------------------------------------------
flag maintainer
description: Enable settings for the package maintainer.
manual: True
default: False

--------------------------------------------------------------------------------
flag build-examples
description: Build examples when building the library.
manual: True
default: False

--------------------------------------------------------------------------------
library
exposed-modules:
System.Console.Byline
System.Console.Byline.Color
System.Console.Byline.Completion
System.Console.Byline.Internal.Byline
System.Console.Byline.Internal.Color
System.Console.Byline.Internal.Completion
System.Console.Byline.Internal.Render
System.Console.Byline.Internal.Types
System.Console.Byline.Menu
System.Console.Byline.Modifiers
System.Console.Byline.Primitive
System.Console.Byline.Stylized

hs-source-dirs: src
default-language: Haskell2010
ghc-options: -Wall -fwarn-incomplete-uni-patterns

if flag(maintainer)
ghc-options: -Werror

build-depends: base >= 4.7 && < 5.0
, ansi-terminal >= 0.6 && < 0.7
, colour >= 2.3 && < 2.4
, containers >= 0.5 && < 0.6
, exceptions >= 0.8 && < 0.9
, haskeline >= 0.7 && < 0.8
, mtl >= 2.1 && < 2.3
, terminfo-hs >= 0.1 && < 0.3
, text >= 0.11 && < 1.3
, transformers >= 0.3 && < 0.6

--------------------------------------------------------------------------------
executable simple
main-is: examples/simple.hs
default-language: Haskell2010
ghc-options: -Wall -fwarn-incomplete-uni-patterns
build-depends: base, byline, text

if flag(maintainer)
ghc-options: -Werror

if !flag(build-examples)
buildable: False

--------------------------------------------------------------------------------
executable menu
main-is: examples/menu.hs
default-language: Haskell2010
ghc-options: -Wall -fwarn-incomplete-uni-patterns
build-depends: base, byline, text

if flag(maintainer)
ghc-options: -Werror

if !flag(build-examples)
buildable: False

+ 0
- 45
vendor/byline/examples/menu.hs View File

@@ -1,45 +0,0 @@
{-# LANGUAGE OverloadedStrings #-}

{-

This file is part of the package byline. It is subject to the license
terms in the LICENSE file found in the top-level directory of this
distribution and at git://pmade.com/byline/LICENSE. No part of the
byline package, including this file, may be copied, modified,
propagated, or distributed except according to the terms contained in
the LICENSE file.

-}

--------------------------------------------------------------------------------
module Main (main) where

--------------------------------------------------------------------------------
import Data.Text (Text)
import System.Console.Byline

--------------------------------------------------------------------------------
data Item = Fruit Text | Vegetable Text deriving Show

--------------------------------------------------------------------------------
displayItem :: Item -> Stylized
displayItem (Fruit name) = text name <> (" (fruit)" <> fg red)
displayItem (Vegetable name) = text name <> (" (vegetable)" <> fg green)

--------------------------------------------------------------------------------
items :: [Item]
items = [ Fruit "Watermelon"
, Vegetable "Cucumber"
, Fruit "Kiwi"
, Vegetable "Asparagus"
]

--------------------------------------------------------------------------------
main :: IO ()
main = do
let menuConfig = banner "Pick a snack: " $ menu items displayItem
prompt = "Which snack? "
onError = "please pick a valid item!" <> fg red

answer <- runByline $ askWithMenuRepeatedly menuConfig prompt onError
putStrLn ("you picked: " ++ show answer)

+ 0
- 51
vendor/byline/examples/simple.hs View File

@@ -1,53 +0,0 @@
{-# LANGUAGE OverloadedStrings #-}

{-

This file is part of the package byline. It is subject to the license
terms in the LICENSE file found in the top-level directory of this
distribution and at git://pmade.com/byline/LICENSE. No part of the
byline package, including this file, may be copied, modified,
propagated, or distributed except according to the terms contained in
the LICENSE file.

-}

--------------------------------------------------------------------------------
module Main (main) where

--------------------------------------------------------------------------------
import Control.Monad (void)
import Data.Text (Text)
import qualified Data.Text as Text
import System.Console.Byline

--------------------------------------------------------------------------------
main :: IO ()
main = void $ runByline $ do

-- Simple message to stdout:
sayLn "Okay, let's kick this off"

-- Now with some color:
sayLn ("I can use " <> ("color" <> fg blue) <> " too!")

-- Get user input with a stylized prompt:
let question = "What's your favorite " <> ("language" <> bold) <> "? "
language <- ask question Nothing

if Text.null language
then sayLn "Cat got your tongue?"
else sayLn ("I see, you like " <> (text language <> fg red) <> ".")

-- Keep prompting until a confirmation function indicates that the
-- user's input is sufficient:
name <- askUntil "What's your name? " Nothing atLeastThreeChars
sayLn $ "Hey there " <> text name <> fg (rgb 108 113 196)

--------------------------------------------------------------------------------
atLeastThreeChars :: Text -> IO (Either Stylized Text)
atLeastThreeChars input = return $
if Text.length input < 3
then Left "You can do better."
else Right input

+ 0
- 122
vendor/byline/src/System/Console/Byline.hs View File

@@ -1,122 +0,0 @@
{-

This file is part of the package byline. It is subject to the license
terms in the LICENSE file found in the top-level directory of this
distribution and at git://pmade.com/byline/LICENSE. No part of the
byline package, including this file, may be copied, modified,
propagated, or distributed except according to the terms contained in
the LICENSE file.

-}

--------------------------------------------------------------------------------
module System.Console.Byline
( -- * Introduction
--
-- | Byline provides a monad transformer that allows you to compose
-- interactive terminal actions. When producing output,
-- these actions accept stylized text that can include
-- foreground and background colors, underlined text, and
-- bold text.
--
-- Stylized text can be constructed with string literals
-- (using the @OverloadedStrings@ extension) or using the
-- 'text' function. Attributes such as color can be changed
-- using modifier functions and the @mappend@ operator,
-- @(<>)@.
--
-- Actions that read user input can work with completion
-- functions which are activated when the user presses the
-- tab key. Most input actions also support default values
-- that will be returned when the user presses the enter key
-- without providing any input.
--
-- Example:
--
-- @
-- {-\# LANGUAGE OverloadedStrings \#-}
--
-- ...
--
-- language <- runByline $ do
-- sayLn ("Look mom, " <> ("colors" <> fg blue) <> "!")
--
-- let question = "What's your favorite " <>
-- ("language" <> bold) <> "? "
--
-- ask question Nothing
-- @
--
-- More complete examples can be found in the @examples@
-- directory of the distribution tarball or in the
-- repository.

-- * Executing Interactive Sessions
Byline
, runByline

-- * Primitive Operations
, say
, sayLn
, ask
, askChar
, askPassword
, askUntil
, report
, reportLn

-- * Constructing Stylized Text
, Stylized
, text

-- * Modifying Output Text

-- | The 'Stylized' type is an instance of the monoid class.
-- This means you can change attributes of the text by using
-- the following functions along with @mappend@ or the @(<>)@
-- operator.
, fg, bg, bold, underline

-- * Specifying Colors
, Color
, black, red, green, yellow, blue, magenta, cyan, white, rgb

-- * Menus

-- | Menus provide a way to display a small number of list items
-- to the user. The desired list item is selected by typing
-- its index or by typing a unique prefix string. A default
-- completion function is provided to allow the user to
-- select a list item using tab completion.
, Menu
, Choice (..)
, menu
, askWithMenu
, askWithMenuRepeatedly
, banner
, prefix
, suffix
, Matcher
, matcher

-- * Completion
, CompletionFunc
, Completion (..)
, withCompletionFunc

-- * Utility Functions, Operators, and Types
, ReportType (..)
, (<>)
) where

--------------------------------------------------------------------------------
import Data.Monoid ((<>))

--------------------------------------------------------------------------------
import System.Console.Byline.Color
import System.Console.Byline.Completion
import System.Console.Byline.Internal.Byline
import System.Console.Byline.Menu
import System.Console.Byline.Modifiers
import System.Console.Byline.Primitive
import System.Console.Byline.Stylized

+ 0
- 46
vendor/byline/src/System/Console/Byline/Color.hs View File

@@ -1,69 +0,0 @@
{-

This file is part of the package byline. It is subject to the license
terms in the LICENSE file found in the top-level directory of this
distribution and at git://pmade.com/byline/LICENSE. No part of the
byline package, including this file, may be copied, modified,
propagated, or distributed except according to the terms contained in
the LICENSE file.

-}


--------------------------------------------------------------------------------
module System.Console.Byline.Color
( Color (..)
, black, red, green, yellow, blue, magenta, cyan, white
, rgb
) where

--------------------------------------------------------------------------------
import Data.Word
import qualified System.Console.ANSI as ANSI

--------------------------------------------------------------------------------
--
data Color = ColorCode ANSI.Color | ColorRGB (Word8, Word8, Word8)

--------------------------------------------------------------------------------
black, red, green, yellow, blue, magenta, cyan, white :: Color
black = ColorCode ANSI.Black
red = ColorCode ANSI.Red
green = ColorCode ANSI.Green
yellow = ColorCode ANSI.Yellow
blue = ColorCode ANSI.Blue
magenta = ColorCode ANSI.Magenta
cyan = ColorCode ANSI.Cyan
white = ColorCode ANSI.White

--------------------------------------------------------------------------------
--
--
--
--
--
rgb :: Word8 -> Word8 -> Word8 -> Color
rgb r g b = ColorRGB (r, g, b)

+ 0
- 36
vendor/byline/src/System/Console/Byline/Completion.hs View File

@@ -1,57 +0,0 @@
{-

This file is part of the package byline. It is subject to the license
terms in the LICENSE file found in the top-level directory of this
distribution and at git://pmade.com/byline/LICENSE. No part of the
byline package, including this file, may be copied, modified,
propagated, or distributed except according to the terms contained in
the LICENSE file.

-}

--------------------------------------------------------------------------------
module System.Console.Byline.Completion
( CompletionFunc
, Completion (..)
) where

--------------------------------------------------------------------------------
import Data.Text (Text)

--------------------------------------------------------------------------------
--
--
--
--
--
--
type CompletionFunc = (Text, Text) -> IO (Text, [Completion])

--------------------------------------------------------------------------------
data Completion = Completion
{ replacement :: Text -- ^ Text to insert to the right of the cursor.
, display :: Text -- ^ Text to display when listing all completions.
, isFinished :: Bool -- ^ Whether to follow the completed word with a
-- terminating space or close existing quotes.
} deriving (Eq, Ord, Show)

+ 0
- 126
vendor/byline/src/System/Console/Byline/Internal/Byline.hs View File

@@ -1,150 +0,0 @@
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# OPTIONS_HADDOCK hide #-}

{-

This file is part of the package byline. It is subject to the license
terms in the LICENSE file found in the top-level directory of this
distribution and at git://pmade.com/byline/LICENSE. No part of the
byline package, including this file, may be copied, modified,
propagated, or distributed except according to the terms contained in
the LICENSE file.

-}

--------------------------------------------------------------------------------
module System.Console.Byline.Internal.Byline
( Byline (..)
, Env (..)
, eof
, liftBase
, liftInputT
, runByline
) where

--------------------------------------------------------------------------------
import Control.Applicative
import Control.Monad.Catch
import Control.Monad.Reader
import Control.Monad.Trans.Maybe
import Data.IORef
import System.Environment (lookupEnv)
import System.IO (Handle, stdout)
import qualified System.Terminfo as Term
import qualified System.Terminfo.Caps as Term

--------------------------------------------------------------------------------
import qualified System.Console.Haskeline as H
import qualified System.Console.Haskeline.IO as H

--------------------------------------------------------------------------------
import System.Console.Byline.Internal.Completion
import System.Console.Byline.Internal.Render

--------------------------------------------------------------------------------
import Prelude

--------------------------------------------------------------------------------
data Env = Env
{ sayMode :: RenderMode
, askMode :: RenderMode
, outHandle :: Handle
, inputState :: H.InputState
, compFunc :: IORef (Maybe CompletionFunc)
}

--------------------------------------------------------------------------------
newtype Byline m a = Byline {unByline :: ReaderT Env (MaybeT m) a}
deriving (Functor, Applicative, Monad, MonadReader Env, MonadIO)

--------------------------------------------------------------------------------
defRenderMode :: H.InputT IO (RenderMode, RenderMode)
defRenderMode = do
termHint <- H.haveTerminalUI
maxColors <- liftIO (runMaybeT getMaxColors)

return $ case (termHint, maxColors) of
(True, Just n) | n < 256 -> (Simple, Simple)
| otherwise -> (Term256, Term256)
(True, Nothing) -> (Simple, Plain)
(False, _) -> (Plain, Plain)
where
getMaxColors :: MaybeT IO Int
getMaxColors = do
term <- MaybeT (lookupEnv "TERM")
db <- liftIO (Term.acquireDatabase term)

case db of
Left _ -> MaybeT (return Nothing)
Right d -> MaybeT (return $ Term.queryNumTermCap d Term.MaxColors)

--------------------------------------------------------------------------------
defEnv :: H.InputState
-> (RenderMode, RenderMode)
-> IORef (Maybe CompletionFunc)
-> Env
defEnv state (smode, amode) comp =
Env { sayMode = smode
, askMode = amode
, outHandle = stdout
, inputState = state
, compFunc = comp
}

--------------------------------------------------------------------------------
eof :: (Monad m) => Byline m a
eof = Byline $ lift (MaybeT $ return Nothing)

--------------------------------------------------------------------------------
liftBase :: (Monad m) => m a -> Byline m a
liftBase = Byline . lift . lift

--------------------------------------------------------------------------------
liftInputT :: (MonadIO m) => H.InputT IO a -> Byline m a
liftInputT input = do
state <- asks inputState
liftIO (H.queryInput state $ H.withInterrupt input)

--------------------------------------------------------------------------------
--
--
--
runByline :: (MonadIO m, MonadMask m) => Byline m a -> m (Maybe a)
runByline (Byline byline) = do
comp <- liftIO (newIORef Nothing)
let settings = H.setComplete (runCompletionFunction comp) H.defaultSettings

bracketOnError (liftIO $ H.initializeInput settings) -- Acquire.
(liftIO . H.cancelInput) -- Release.
(go comp) -- Use.
where
go comp state = do
modes <- liftIO (H.queryInput state defRenderMode)
output <- runMaybeT $ runReaderT byline (defEnv state modes comp)

liftIO (H.closeInput state)
return output

+ 0
- 91
vendor/byline/src/System/Console/Byline/Internal/Color.hs View File

@@ -1,101 +0,0 @@
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_HADDOCK hide #-}

{-

This file is part of the package byline. It is subject to the license
terms in the LICENSE file found in the top-level directory of this
distribution and at git://pmade.com/byline/LICENSE. No part of the
byline package, including this file, may be copied, modified,
propagated, or distributed except according to the terms contained in
the LICENSE file.

-}


--------------------------------------------------------------------------------
module System.Console.Byline.Internal.Color
( Color (..)
, colorAsANSI
, nearestColor
, term256Locations
) where

--------------------------------------------------------------------------------
import Control.Arrow (second)
import qualified Data.Colour.CIE as C
import qualified Data.Colour.SRGB as C
import Data.List (sortBy)
import Data.Maybe
import Data.Ord (comparing)
import Data.Word
import qualified System.Console.ANSI as ANSI

--------------------------------------------------------------------------------
import System.Console.Byline.Color

--------------------------------------------------------------------------------
colorAsANSI :: Color -> ANSI.Color
colorAsANSI (ColorCode c) = c
colorAsANSI (ColorRGB c) = nearestColor c ansiColorLocations

--------------------------------------------------------------------------------
nearestColor :: (Bounded a)
=> (Word8, Word8, Word8) -- ^ Original color.
-> [(a, (Double, Double, Double))] -- ^ List of colors and locations.
-> a -- ^ Destination color.
nearestColor (r, g, b) table =
case listToMaybe (sortColors $ distances table) of
Nothing -> minBound -- Should never happen.
Just (c, _) -> c

where
location :: (Double, Double, Double)
location = C.cieXYZView (C.sRGB24 r g b)

distance :: (Double, Double, Double) -> (Double, Double, Double) -> Double
distance (x1, y1, z1) (x2, y2, z2) = sqrt ((x ** 2) + (y ** 2) + (z ** 2))
where x = x1 - x2
y = y1 - y2
z = z1 - z2

distances :: [(a, (Double, Double, Double))] -> [(a, Double)]
distances = map (second (distance location))

sortColors :: [(a, Double)] -> [(a, Double)]
sortColors = sortBy (comparing snd)

--------------------------------------------------------------------------------
--
--
ansiColorLocations :: [(ANSI.Color, (Double, Double, Double))]
ansiColorLocations = [ (ANSI.Black, (0.0, 0.0, 0.0))
, (ANSI.Red, (0.2518, 0.1298, 0.0118))
, (ANSI.Green, (0.2183, 0.4366, 0.0728))
, (ANSI.Yellow, (0.4701, 0.5664, 0.0846))
, (ANSI.Blue, (0.1543, 0.0617, 0.8126))
, (ANSI.Magenta, (0.3619, 0.1739, 0.592))
, (ANSI.Cyan, (0.3285, 0.4807, 0.653))
, (ANSI.White, (0.7447, 0.7835, 0.8532))
]

--------------------------------------------------------------------------------
term256Locations :: [(Word8, (Double, Double, Double))]
term256Locations = zipWith (\c i -> (i, C.cieXYZView c)) colors [16..]
where
colors :: [C.Colour Double]
colors = do
r <- [0.0, 0.2 .. 1.0]
g <- [0.0, 0.2 .. 1.0]
b <- [0.0, 0.2 .. 1.0]
return (C.sRGB r g b)

+ 0
- 50
vendor/byline/src/System/Console/Byline/Internal/Completion.hs View File

@@ -1,55 +0,0 @@
{-# OPTIONS_HADDOCK hide #-}

{-

This file is part of the package byline. It is subject to the license
terms in the LICENSE file found in the top-level directory of this
distribution and at git://pmade.com/byline/LICENSE. No part of the
byline package, including this file, may be copied, modified,
propagated, or distributed except according to the terms contained in
the LICENSE file.

-}

--------------------------------------------------------------------------------
module System.Console.Byline.Internal.Completion
( CompletionFunc
, Completion (..)
, runCompletionFunction
) where

--------------------------------------------------------------------------------
import Data.IORef
import qualified Data.Text as Text
import qualified System.Console.Haskeline.Completion as H

--------------------------------------------------------------------------------
import System.Console.Byline.Completion

--------------------------------------------------------------------------------
convertCompletion :: Completion -> H.Completion
convertCompletion (Completion r d i) =
H.Completion { H.replacement = Text.unpack r
, H.display = Text.unpack d
, H.isFinished = i
}

--------------------------------------------------------------------------------
runCompletionFunction :: IORef (Maybe CompletionFunc) -> H.CompletionFunc IO
runCompletionFunction compref (left, right) = do
comp <- readIORef compref

case comp of
Nothing -> H.completeFilename (left, right)

Just f -> do
(output, completions) <-
f (Text.reverse $ Text.pack left, Text.pack right)

return (Text.unpack $ Text.reverse output,
map convertCompletion completions)

+ 0
- 128
vendor/byline/src/System/Console/Byline/Internal/Render.hs View File

@@ -1,148 +0,0 @@
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_HADDOCK hide #-}

{-

This file is part of the package byline. It is subject to the license
terms in the LICENSE file found in the top-level directory of this
distribution and at git://pmade.com/byline/LICENSE. No part of the
byline package, including this file, may be copied, modified,
propagated, or distributed except according to the terms contained in
the LICENSE file.

-}

--------------------------------------------------------------------------------
module System.Console.Byline.Internal.Render
( RenderMode (..)
, render
, renderText
) where

--------------------------------------------------------------------------------
import Control.Applicative
import Data.Maybe
import Data.Text (Text)
import qualified Data.Text as Text
import Data.Word
import System.Console.ANSI as ANSI
import System.IO (Handle, hPutStr)

--------------------------------------------------------------------------------
import System.Console.Byline.Internal.Color as C
import System.Console.Byline.Internal.Types
import System.Console.Byline.Stylized

--------------------------------------------------------------------------------
import Prelude

--------------------------------------------------------------------------------
data RenderMode = Plain -- ^ Text only, no modifiers.
| Simple -- ^ Allow up to 8 colors.
| Term256 -- ^ Allow up to 216 colors.

--------------------------------------------------------------------------------
data RenderInstruction = RenderText Text
| RenderSGR [SGR]

--------------------------------------------------------------------------------
render :: RenderMode -> Handle -> Stylized -> IO ()
render mode h stylized = mapM_ go (renderInstructions mode stylized)
where
go :: RenderInstruction -> IO ()
go (RenderText t) = hPutStr h (Text.unpack t)
go (RenderSGR s) = hSetSGR h s

--------------------------------------------------------------------------------
renderText :: RenderMode -> Stylized -> Text
renderText mode stylized = Text.concat $ map go (renderInstructions mode stylized)
where
go :: RenderInstruction -> Text
go (RenderText t) = t
go (RenderSGR _) = Text.empty

--------------------------------------------------------------------------------
renderInstructions :: RenderMode -> Stylized -> [RenderInstruction]
renderInstructions mode = concat . mapStylized renderMod
where
renderMod :: (Text, Modifier) -> [RenderInstruction]
renderMod (t, m) =
case mode of
-- Only rendering text.
Plain -> [ RenderText t ]

-- Render text with modifiers. The only difference between
-- 'Simple' and 'Term256' is handled by 'modToText'.
_ -> [ RenderSGR (modToSGR m)
, RenderText (modToText mode m)
, RenderText t
, RenderSGR [Reset]
]

--------------------------------------------------------------------------------
modToSGR :: Modifier -> [SGR]
modToSGR m =
catMaybes [ SetColor Foreground Dull <$> modColor modColorFG
, SetColor Background Dull <$> modColor modColorBG
, SetConsoleIntensity <$> modIntensity
, SetUnderlining <$> modUnderlining
]

where
modColor :: (Modifier -> OnlyOne C.Color) -> Maybe ANSI.Color
modColor f = C.colorAsANSI <$> unOne (f m)

modIntensity :: Maybe ConsoleIntensity
modIntensity = case modBold m of
Off -> Nothing
On -> Just BoldIntensity

modUnderlining :: Maybe Underlining
modUnderlining = case modUnderline m of
Off -> Nothing
On -> Just SingleUnderline

--------------------------------------------------------------------------------
--
modToText :: RenderMode -> Modifier -> Text
modToText Plain _ = Text.empty
modToText Simple _ = Text.empty
modToText Term256 m =
Text.concat $ catMaybes [ escape Foreground <$> modColor modColorFG
, escape Background <$> modColor modColorBG
]

where
modColor :: (Modifier -> OnlyOne C.Color) -> Maybe (Word8, Word8, Word8)
modColor f = case unOne (f m) of
Just (ColorRGB c) -> Just c
_ -> Nothing

-- Produce the correct CSI escape.
escape :: ConsoleLayer -> (Word8, Word8, Word8) -> Text
escape Foreground c = Text.concat ["\ESC[38;5;", colorIndex c, "m"]
escape Background c = Text.concat ["\ESC[48;5;", colorIndex c, "m"]

-- Return the 216-color index for (r, g, b).
colorIndex :: (Word8, Word8, Word8) -> Text
colorIndex c = Text.pack $ show (nearestColor c term256Locations)

+ 0
- 59
vendor/byline/src/System/Console/Byline/Internal/Types.hs View File

@@ -1,65 +0,0 @@
{-# OPTIONS_HADDOCK hide #-}

{-

This file is part of the package byline. It is subject to the license
terms in the LICENSE file found in the top-level directory of this
distribution and at git://pmade.com/byline/LICENSE. No part of the
byline package, including this file, may be copied, modified,
propagated, or distributed except according to the terms contained in
the LICENSE file.

-}

--------------------------------------------------------------------------------
module System.Console.Byline.Internal.Types
( Status (..)
, OnlyOne (..)
, Modifier (..)
) where

--------------------------------------------------------------------------------
import Data.Monoid

--------------------------------------------------------------------------------
import System.Console.Byline.Color (Color)

--------------------------------------------------------------------------------
data Status = On | Off

--------------------------------------------------------------------------------
instance Monoid Status where
mempty = Off
mappend Off Off = Off
mappend Off On = On
mappend On On = On
mappend On Off = On

--------------------------------------------------------------------------------
newtype OnlyOne a = OnlyOne {unOne :: Maybe a}

--------------------------------------------------------------------------------
instance Monoid (OnlyOne a) where
mempty = OnlyOne Nothing
mappend _ b@(OnlyOne (Just _)) = b
mappend a _ = a

--------------------------------------------------------------------------------
data Modifier = Modifier
{ modColorFG :: OnlyOne Color
, modColorBG :: OnlyOne Color
, modBold :: Status
, modUnderline :: Status
}

--------------------------------------------------------------------------------
instance Monoid Modifier where
mempty = Modifier mempty mempty mempty mempty
mappend (Modifier a b c d) (Modifier a' b' c' d') =
Modifier (a <> a') (b <> b') (c <> c') (d <> d')

+ 0
- 206
vendor/byline/src/System/Console/Byline/Menu.hs View File

@@ -1,250 +0,0 @@
{-# LANGUAGE OverloadedStrings #-}

{-

This file is part of the package byline. It is subject to the license
terms in the LICENSE file found in the top-level directory of this
distribution and at git://pmade.com/byline/LICENSE. No part of the
byline package, including this file, may be copied, modified,
propagated, or distributed except according to the terms contained in
the LICENSE file.

-}

--------------------------------------------------------------------------------
module System.Console.Byline.Menu
( Menu
, Choice (..)
, Matcher
, menu
, banner
, prefix
, suffix
, matcher
, askWithMenu
, askWithMenuRepeatedly
) where

--------------------------------------------------------------------------------
import Control.Applicative
import Control.Monad
import Control.Monad.IO.Class
import qualified Control.Monad.Reader as Reader
import Data.IORef
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Maybe
import Data.Monoid
import Data.Text (Text)
import qualified Data.Text as Text
import Text.Printf (printf)

--------------------------------------------------------------------------------
import System.Console.Byline.Internal.Byline
import System.Console.Byline.Internal.Completion
import System.Console.Byline.Internal.Render
import System.Console.Byline.Primitive
import System.Console.Byline.Stylized

--------------------------------------------------------------------------------
data Menu a = Menu
{ menuItems :: [a] -- ^ Menu items.
, menuBanner :: Maybe Stylized -- ^ Banner printed before menu.
, menuDisplay :: a -> Stylized -- ^ Stylize a menu item.
, menuItemPrefix :: Int -> Stylized -- ^ Stylize an item's index.
, menuItemSuffix :: Stylized -- ^ Printed after an item's index.
, menuBeforePrompt :: Maybe Stylized -- ^ Printed before the prompt.
, menuMatcher :: Matcher a -- ^ Matcher function.
}

--------------------------------------------------------------------------------
data Choice a = NoItems -- ^ Menu has no items to choose from.
| Match a -- ^ User picked a menu item.
| Other Text -- ^ User entered text that doesn't match an item.
deriving Show

--------------------------------------------------------------------------------
--
--
type Matcher a = Menu a -> Map Text a -> Text -> Choice a

--------------------------------------------------------------------------------
numbered :: Int -> Stylized
numbered = text . Text.pack . printf "%2d"

--------------------------------------------------------------------------------
matchOnPrefix :: Menu a -> Text -> [a]
matchOnPrefix config input = filter prefixCheck (menuItems config)
where
asText i = renderText Plain (menuDisplay config i)
prefixCheck i = input `Text.isPrefixOf` asText i

--------------------------------------------------------------------------------
defaultMatcher :: Matcher a
defaultMatcher config prefixes input =
case uniquePrefix <|> Map.lookup cleanInput prefixes of
Nothing -> Other input
Just match -> Match match

where
cleanInput = Text.strip input

-- uniquePrefix :: Maybe a
uniquePrefix = let matches = matchOnPrefix config cleanInput
in if length matches == 1
then listToMaybe matches
else Nothing

--------------------------------------------------------------------------------
defaultCompFunc :: Menu a -> CompletionFunc
defaultCompFunc config (left, _) = return ("", completions matches)
where
-- All matching menu items.
matches = if Text.null left
then menuItems config
else matchOnPrefix config left

-- Convert a menu item to a String.
asText i = renderText Plain (menuDisplay config i)

-- Convert menu items into Completion values.
completions = map (\i -> Completion (asText i) (asText i) True)

--------------------------------------------------------------------------------
menu :: [a] -> (a -> Stylized) -> Menu a
menu items displayF =
Menu { menuItems = items
, menuBanner = Nothing
, menuDisplay = displayF
, menuItemPrefix = numbered
, menuItemSuffix = text ") "
, menuBeforePrompt = Nothing
, menuMatcher = defaultMatcher
}

--------------------------------------------------------------------------------
banner :: Stylized -> Menu a -> Menu a
banner b m = m {menuBanner = Just b}

--------------------------------------------------------------------------------
prefix :: (Int -> Stylized) -> Menu a -> Menu a
prefix f m = m {menuItemPrefix = f}

--------------------------------------------------------------------------------
--
suffix :: Stylized -> Menu a -> Menu a
suffix s m = m {menuItemSuffix = s}

--------------------------------------------------------------------------------
matcher :: Matcher a -> Menu a -> Menu a
matcher f m = m {menuMatcher = f}

--------------------------------------------------------------------------------
--
askWithMenu :: (MonadIO m)
=> Menu a -- ^ The 'Menu' to display.
-> Stylized -- ^ The prompt.
-> Byline m (Choice a)
askWithMenu m prompt = do
currCompFunc <- Reader.asks compFunc >>= liftIO . readIORef

if null (menuItems m)
then return NoItems
else go currCompFunc

where
-- Use the default completion function for menus, but not if another
-- completion function is already active.
go comp = withCompletionFunc (fromMaybe (defaultCompFunc m) comp) $ do
prefixes <- displayMenu
answer <- ask prompt (Just firstItem)
return (menuMatcher m m prefixes answer)

-- The default menu item.
firstItem = Text.strip $ renderText Plain (menuItemPrefix m 1)

-- Print the entire menu.
displayMenu = do
case menuBanner m of
Nothing -> return ()
Just br -> sayLn (br <> "\n")

cache <- foldM listItem Map.empty $ zip [1..] (menuItems m)

case menuBeforePrompt m of
Nothing -> sayLn mempty -- Just for the newline.
Just bp -> sayLn ("\n" <> bp)

return cache

-- Print a menu item and cache its prefix in a Map.
listItem cache (index, item) = do
let bullet = menuItemPrefix m index
rendered = renderText Plain bullet

sayLn $ mconcat [ text " " -- Indent.
, bullet -- Unique identifier.
, menuItemSuffix m -- Spacer or marker.
, menuDisplay m item -- The item.
]

return (Map.insert (Text.strip rendered) item cache)

--------------------------------------------------------------------------------
askWithMenuRepeatedly :: (MonadIO m)
=> Menu a -- ^ The 'Menu' to display.
-> Stylized -- ^ The prompt.
-> Stylized -- ^ Error message.
-> Byline m (Choice a)
askWithMenuRepeatedly m prompt errprompt = go m
where
go config = do
answer <- askWithMenu config prompt

case answer of
Other _ -> go (config {menuBeforePrompt = Just errprompt})
_ -> return answer

+ 0
- 47
vendor/byline/src/System/Console/Byline/Modifiers.hs View File

@@ -1,60 +0,0 @@
{-

This file is part of the package byline. It is subject to the license
terms in the LICENSE file found in the top-level directory of this
distribution and at git://pmade.com/byline/LICENSE. No part of the
byline package, including this file, may be copied, modified,
propagated, or distributed except according to the terms contained in
the LICENSE file.

-}


--------------------------------------------------------------------------------
module System.Console.Byline.Modifiers
( fg
, bg
, bold
, underline
) where

--------------------------------------------------------------------------------
import Data.Monoid

--------------------------------------------------------------------------------
import System.Console.Byline.Internal.Color
import System.Console.Byline.Internal.Types
import System.Console.Byline.Stylized

--------------------------------------------------------------------------------
import Prelude

--------------------------------------------------------------------------------
--
fg :: Color -> Stylized
fg c = modStylized (mempty {modColorFG = OnlyOne (Just c)})

--------------------------------------------------------------------------------
bg :: Color -> Stylized
bg c = modStylized (mempty {modColorBG = OnlyOne (Just c)})

--------------------------------------------------------------------------------
bold :: Stylized
bold = modStylized (mempty {modBold = On})

--------------------------------------------------------------------------------
underline :: Stylized
underline = modStylized (mempty {modUnderline = On})

+ 0
- 154
vendor/byline/src/System/Console/Byline/Primitive.hs View File

@@ -1,173 +0,0 @@
{-# LANGUAGE OverloadedStrings #-}

{-

This file is part of the package byline. It is subject to the license
terms in the LICENSE file found in the top-level directory of this
distribution and at git://pmade.com/byline/LICENSE. No part of the
byline package, including this file, may be copied, modified,
propagated, or distributed except according to the terms contained in
the LICENSE file.

-}

--------------------------------------------------------------------------------
module System.Console.Byline.Primitive
( ReportType (..)
, say
, sayLn
, ask
, askChar
, askPassword
, askUntil
, report
, reportLn
, withCompletionFunc
) where

--------------------------------------------------------------------------------
import Control.Monad.IO.Class
import qualified Control.Monad.Reader as Reader
import Data.IORef
import Data.Maybe
import Data.Monoid
import Data.Text (Text)
import qualified Data.Text as T
import qualified System.Console.Haskeline as H

--------------------------------------------------------------------------------
--- Byline imports:
import System.Console.Byline.Color
import System.Console.Byline.Internal.Byline
import System.Console.Byline.Internal.Completion
import System.Console.Byline.Internal.Render
import System.Console.Byline.Modifiers
import System.Console.Byline.Stylized

--------------------------------------------------------------------------------
data ReportType = Error -- ^ Report errors with: @"error: "@
| Warning -- ^ Report warnings with: @"warning: "@

--------------------------------------------------------------------------------
say :: (MonadIO m) => Stylized -> Byline m ()
say message = do
env <- Reader.ask
liftIO $ render (sayMode env) (outHandle env) message

--------------------------------------------------------------------------------
sayLn :: (MonadIO m) => Stylized -> Byline m ()
sayLn message = say (message <> text "\n")

--------------------------------------------------------------------------------
ask :: (MonadIO m)
=> Stylized
-- ^ The prompt.

-> Maybe Text
-- ^ Optional default answer that will be returned if the user
-- presses return without providing any input (a zero-length
-- string).

-> Byline m Text
ask prompt defans = do
let prompt' = case defans of
Nothing -> prompt
Just s -> prompt <> text "[" <> text s <> "] "

answer <- liftInputT . H.getInputLine =<< renderPrompt prompt'

case answer of
Nothing -> eof
Just s | null s -> return (fromMaybe (T.pack s) defans)
| otherwise -> return (T.pack s)

--------------------------------------------------------------------------------
askChar :: (MonadIO m)
=> Stylized
-> Byline m Char
askChar prompt = do
answer <- liftInputT . H.getInputChar =<< renderPrompt prompt
case answer of
Nothing -> eof
Just c -> return c

--------------------------------------------------------------------------------
askPassword :: (MonadIO m)
=> Stylized
-- ^ The prompt.

-> Maybe Char
-- ^ Optional masking character that will be printed each
-- time the user presses a key.

-> Byline m Text
askPassword prompt maskchr = do
pass <- liftInputT . H.getPassword maskchr =<< renderPrompt prompt
case pass of
Nothing -> eof
Just s -> return (T.pack s)

--------------------------------------------------------------------------------
--
askUntil :: (MonadIO m)
=> Stylized -- ^ The prompt.
-> Maybe Text -- ^ Optional default answer.
-> (Text -> m (Either Stylized Text)) -- ^ Confirmation function.
-> Byline m Text
askUntil prompt defans confirm = go where
go = do
answer <- ask prompt defans
check <- liftBase (confirm answer)

case check of
Left msg -> sayLn msg >> go
Right result -> return result

--------------------------------------------------------------------------------
report :: (MonadIO m) => ReportType -> Stylized -> Byline m ()
report Error message = say $ (text "error: " <> fg red) <> message
report Warning message = say $ (text "warning: " <> fg yellow) <> message

--------------------------------------------------------------------------------
reportLn :: (MonadIO m) => ReportType -> Stylized -> Byline m ()
reportLn rt message = report rt (message <> text "\n")

--------------------------------------------------------------------------------
withCompletionFunc :: (MonadIO m) => CompletionFunc -> Byline m a -> Byline m a
withCompletionFunc comp byline = do
compref <- Reader.asks compFunc
current <- liftIO (readIORef compref)

-- Temporally change the completion function.
-- Exceptions will be dealt with in 'runByline'.
liftIO (writeIORef compref (Just comp))
output <- byline

-- Reset the completion function and return the result.
liftIO (writeIORef compref current)
return output

--------------------------------------------------------------------------------
renderPrompt :: (Monad m) => Stylized -> Byline m String
renderPrompt prompt = do
mode <- Reader.asks askMode
return $ T.unpack (renderText mode prompt)

+ 0
- 71
vendor/byline/src/System/Console/Byline/Stylized.hs View File

@@ -1,87 +0,0 @@
{-

This file is part of the package byline. It is subject to the license
terms in the LICENSE file found in the top-level directory of this
distribution and at git://pmade.com/byline/LICENSE. No part of the
byline package, including this file, may be copied, modified,
propagated, or distributed except according to the terms contained in
the LICENSE file.

-}

--------------------------------------------------------------------------------
module System.Console.Byline.Stylized
( Stylized
, Modifier
, text
, mapStylized
, modStylized
) where

--------------------------------------------------------------------------------
import Data.Monoid
import Data.String
import Data.Text (Text)
import qualified Data.Text as T

--------------------------------------------------------------------------------
import System.Console.Byline.Internal.Types

--------------------------------------------------------------------------------
data Stylized = StylizedText Text Modifier
| StylizedMod Modifier
| StylizedList [Stylized]

--------------------------------------------------------------------------------
--
text :: Text -> Stylized
text t = StylizedText t mempty

--------------------------------------------------------------------------------
mapStylized :: ((Text, Modifier) -> a) -> Stylized -> [a]
mapStylized f (StylizedText t m) = [ f (t, m) ]
mapStylized _ (StylizedMod _) = [ ] -- No op.
mapStylized f (StylizedList l) = concatMap (mapStylized f) l

--------------------------------------------------------------------------------
modStylized :: Modifier -> Stylized
modStylized = StylizedMod

--------------------------------------------------------------------------------
instance Monoid Stylized where
mempty = StylizedText mempty mempty

-- StylizedText on LHS.
mappend a@(StylizedText _ _) b@(StylizedText _ _) = StylizedList [a, b]
mappend (StylizedText t m) (StylizedMod m') = StylizedText t (m <> m')
mappend a@(StylizedText _ _) (StylizedList b) = StylizedList (a:b)

-- StylizedMod on LHS.
mappend (StylizedMod m) (StylizedText t m') = StylizedText t (m <> m')
mappend (StylizedMod m) (StylizedMod m') = StylizedMod (m <> m')
mappend m@(StylizedMod _) (StylizedList l) = StylizedList (map (m <>) l)

-- StylizedList on LHS.
mappend (StylizedList l) t@(StylizedText _ _) = StylizedList (l <> [t])
mappend (StylizedList l) m@(StylizedMod _) = StylizedList (map (<> m) l)
mappend (StylizedList l) (StylizedList l') = StylizedList (l <> l')

--------------------------------------------------------------------------------
instance IsString Stylized where
fromString = text . T.pack

+ 0
- 12
vendor/byline/stack.yaml View File

@@ -1,12 +0,0 @@
resolver: lts-7.20

flags:
byline:
maintainer: true
build-examples: true

packages:
- ./

extra-deps:
- terminfo-hs-0.2.1

+ 0
- 3
vendor/themoviedb/.gitignore View File

@@ -1,3 +0,0 @@
/dist
/.stack-work
/build/.stack-work

+ 0
- 87
vendor/themoviedb/.travis.yml View File

@@ -1,87 +0,0 @@
# This Travis job script has been generated by a script via
#
# make_travis_yml_2.hs 'themoviedb.cabal'
#
# For more information, see https://github.com/hvr/multi-ghc-travis
#
language: c
sudo: false

git:
submodules: false # whether to recursively clone submodules

cache:
directories:
- $HOME/.cabal/packages
- $HOME/.cabal/store

before_cache:
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/build-reports.log
# remove files that are regenerated by 'cabal update'
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/00-index.*
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/*.json
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.cache
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar.idx

matrix:
include:
- compiler: "ghc-7.8.4"
# env: TEST=--disable-tests BENCH=--disable-benchmarks
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-7.8.4], sources: [hvr-ghc]}}
- compiler: "ghc-7.10.3"
# env: TEST=--disable-tests BENCH=--disable-benchmarks
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-7.10.3], sources: [hvr-ghc]}}
- compiler: "ghc-8.0.1"
# env: TEST=--disable-tests BENCH=--disable-benchmarks
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.0.1], sources: [hvr-ghc]}}

before_install:
- HC=${CC}
- unset CC
- PATH=/opt/ghc/bin:/opt/ghc-ppa-tools/bin:$PATH
- PKGNAME='themoviedb'

install:
- cabal --version
- echo "$(${HC} --version) [$(${HC} --print-project-git-commit-id 2> /dev/null || echo '?')]"
- BENCH=${BENCH---enable-benchmarks}
- TEST=${TEST---enable-tests}
- travis_retry cabal update -v
- sed -i 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config
- rm -fv cabal.project.local
- "echo 'packages: .' > cabal.project"
- rm -f cabal.project.freeze
- cabal new-build -w ${HC} ${TEST} ${BENCH} --dep -j2 all
- cabal new-build -w ${HC} --disable-tests --disable-benchmarks --dep -j2 all

# Here starts the actual work to be performed for the package under test;
# any command which exits with a non-zero exit code causes the build to fail.
script:
- if [ -f configure.ac ]; then autoreconf -i; fi
- rm -rf dist/
- cabal sdist # test that a source-distribution can be generated
- cd dist/
- SRCTAR=(${PKGNAME}-*.tar.gz)
- SRC_BASENAME="${SRCTAR/%.tar.gz}"
- tar -xvf "./$SRC_BASENAME.tar.gz"
- cd "$SRC_BASENAME/"
## from here on, CWD is inside the extracted source-tarball
- rm -fv cabal.project.local
- "echo 'packages: .' > cabal.project"
# this builds all libraries and executables (without tests/benchmarks)
- rm -f cabal.project.freeze
- cabal new-build -w ${HC} --disable-tests --disable-benchmarks all
# this builds all libraries and executables (including tests/benchmarks)
# - rm -rf ./dist-newstyle
- cabal new-build -w ${HC} ${TEST} ${BENCH} all

# there's no 'cabal new-test' yet, so let's emulate for now
- TESTS=( $(awk 'tolower($0) ~ /^test-suite / { print $2 }' *.cabal) )
- if [ "$TEST" != "--enable-tests" ]; then TESTS=(); fi
- shopt -s globstar;
RC=true; for T in ${TESTS[@]}; do echo "== $T ==";
if dist-newstyle/build/**/$SRC_BASENAME/**/build/$T/$T; then echo "= $T OK =";
else echo "= $T FAILED ="; RC=false; fi; done; $RC

# EOF

+ 0
- 40
vendor/themoviedb/CHANGES.md View File

@@ -1,40 +0,0 @@
# Version History

## 1.1.3.0 (March 19, 2017)

- Widen dependencies for LTS-7.20

- Build with latest Hackage too!

- Add Travis CI build status for supported versions of GHC

## 1.1.2.0 (June 9, 2016)

- Widen dependencies for LTS-5.15

## 1.1.1.0 (July 22, 2015)

- Widen dependencies for aeson, either, and text-binary

## 1.1.0.0 (May 22, 2015)

- Added Ord instance for TV, Season, and Episode
- Removed unused dependencies from build-depends
- Changes to build with GHC 7.8.4. and 7.10.1

## 1.0.0.0 (April 5, 2015)

- Major rewrite of the interface
- Removed utility functions for loading API keys
- Added types and functions for TV series information
- Fixed bug: https://github.com/pjones/themoviedb/issues/1
- Fixed bug: https://github.com/pjones/themoviedb/issues/2

## 0.1.0.1 (December 17, 2012)

- Small internal changes to compile with GHC 7.6.1.
- Also compiles with GHC 7.4.2 and HP 2012.4.0.0.

## 0.1.0.0 (December 14, 2012)

- Initial release.

+ 0
- 24
vendor/themoviedb/LICENSE View File

@@ -1,24 +0,0 @@
# Copyright and Authors

Copyright (C) 2012-2017 Peter Jones <pjones@devalot.com>

# License (MIT)

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 0
- 24
vendor/themoviedb/README.md View File

@@ -1,24 +0,0 @@
# TheMovieDB API for Haskell

[![Build Status](https://travis-ci.org/pjones/themoviedb.svg?branch=master)](https://travis-ci.org/pjones/themoviedb)

This is a simple library that provides functions for retrieving movie
metadata from [TheMovieDB][] API. To use this library you need to
request an API key from TheMovieDB. Follow the directions on the
[API][] page.

[TheMovieDB]: http://themoviedb.org
[API]: http://docs.themoviedb.apiary.io

# Documentation

See the [Network.API.TheMovieDB][] module for complete documentation.

[Network.API.TheMovieDB]: https://github.com/pjones/themoviedb/blob/master/src/Network/API/TheMovieDB.hs

# Example

There's an [example][] application in the `example` directory.
Surprising, I know.

[example]: https://github.com/pjones/themoviedb/blob/master/example/Main.hs

+ 0
- 2
vendor/themoviedb/Setup.hs View File

@@ -1,2 +0,0 @@
import Distribution.Simple
main = defaultMain

+ 0
- 13
vendor/themoviedb/TODO.org View File

@@ -1,13 +0,0 @@
#+title: TheMovieDB To-do List

* Milestone: Release 1.0.0.0
** DONE Switch to HTTPS/SSL/TLS (via http-conduit)
CLOSED: [2015-03-20 Fri 18:02]
- This requires using something other than Network.HTTP.
** DONE Remove key utility functions
CLOSED: [2015-03-20 Fri 18:02]
** DONE Ensure parsing errors are handled properly
CLOSED: [2015-03-20 Fri 18:02]
** TODO Prune unneeded dependencies in the cabal file
** TODO Clean up documentation
** TODO Clean up tests

+ 0
- 145
vendor/themoviedb/example/Main.hs View File

@@ -1,154 +0,0 @@
{-# LANGUAGE OverloadedStrings #-}

{-

This file is part of the Haskell package themoviedb. It is subject to
the license terms in the LICENSE file found in the top-level directory
of this distribution and at git://pmade.com/themoviedb/LICENSE. No
part of themoviedb package, including this file, may be copied,
modified, propagated, or distributed except according to the terms
contained in the LICENSE file.

-}

--------------------------------------------------------------------------------
module Main (main) where

--------------------------------------------------------------------------------
import Control.Monad.IO.Class (liftIO)
import Data.Maybe (listToMaybe)
import Data.Text (Text)
import qualified Data.Text as T
import Data.Time (formatTime)
import Data.Time.Locale.Compat (defaultTimeLocale)
import Network.API.TheMovieDB
import System.Environment (getArgs)
import System.Exit (exitFailure, exitSuccess)
import Text.Printf (printf)

--------------------------------------------------------------------------------
printMovieHeader :: Movie -> IO ()
printMovieHeader m =
printf "%8d: %s (%s)\n" (movieID m) (T.unpack $ movieTitle m) year
where year = case movieReleaseDate m of
Just d -> formatTime defaultTimeLocale "%Y" d
Nothing -> "----"

--------------------------------------------------------------------------------
printTVHeader :: TV -> IO ()
printTVHeader t =
printf "%8d: %s (%s)\n" (tvID t) (T.unpack $ tvName t) year
where year = case tvFirstAirDate t of
Just d -> formatTime defaultTimeLocale "%Y" d
Nothing -> "----"

--------------------------------------------------------------------------------
printMovieDetails :: Movie -> IO ()
printMovieDetails m =
do putStrLn $ "Popularity: " ++ show (moviePopularity m)
putStrLn $ strJoin $ map genreName (movieGenres m)
putStrLn "-- "
putStrLn $ T.unpack (movieOverview m)
where strJoin = T.unpack . T.intercalate ", "

--------------------------------------------------------------------------------
printSeason :: Season -> IO ()
printSeason s =
do putStrLn $ "Season " ++ show (seasonNumber s) ++ " " ++ year
mapM_ (putStrLn . episode) $ seasonEpisodes s

where
episode e = "\tE" ++ show (episodeNumber e) ++ " "
++ T.unpack (episodeName e)

year = case seasonAirDate s of
Just d -> formatTime defaultTimeLocale "%Y" d
Nothing -> "----"

--------------------------------------------------------------------------------
searchAndListMovies :: Text -> TheMovieDB ()
searchAndListMovies query = do
movies <- searchMovies query
liftIO $ mapM_ printMovieHeader movies

--------------------------------------------------------------------------------
fetchAndPrintMovie :: ItemID -> TheMovieDB ()
fetchAndPrintMovie mid = do
cfg <- config
movie <- fetchMovie mid

liftIO $ do
printMovieHeader movie
mapM_ (putStrLn . T.unpack) (moviePosterURLs cfg movie)
printMovieDetails movie

--------------------------------------------------------------------------------
searchAndListTV :: Text -> TheMovieDB ()
searchAndListTV query = do
tvs <- searchTV query
liftIO $ mapM_ printTVHeader tvs

--------------------------------------------------------------------------------
fetchAndPrintTV :: ItemID -> TheMovieDB ()
fetchAndPrintTV tid = do
tv <- fetchTV tid
liftIO $ printTVHeader tv
liftIO $ mapM_ printSeason (tvSeasons tv)

--------------------------------------------------------------------------------
fetchAndPrintSeason :: ItemID -> Int -> TheMovieDB ()
fetchAndPrintSeason t s = do
season <- fetchTVSeason t s
liftIO $ printSeason season

--------------------------------------------------------------------------------
fetchAndPrintFullTV :: ItemID -> TheMovieDB ()
fetchAndPrintFullTV t = do
tv <- fetchFullTVSeries t
liftIO $ printTVHeader tv
liftIO $ mapM_ printSeason (tvSeasons tv)

--------------------------------------------------------------------------------
main :: IO ()
main = do
args <- getArgs
let key = maybe T.empty T.pack (listToMaybe args)

result <- runTheMovieDB key $
case args of
[_, "search", query] -> searchAndListMovies (T.pack query)
[_, "fetch", mid] -> fetchAndPrintMovie (read mid)
[_, "tsearch", query] -> searchAndListTV (T.pack query)
[_, "tfetch", tid] -> fetchAndPrintTV (read tid)
[_, "season", t, s] -> fetchAndPrintSeason (read t) (read s)
[_, "tfull", t] -> fetchAndPrintFullTV (read t)
_ -> liftIO (putStrLn usage >> exitFailure)

case result of
Left err -> print err >> exitFailure
Right _ -> exitSuccess

where usage = "Usage: tmdb key {search|fetch|tsearch|tfetch|season|tfull}\n\n" ++
"Description:\n" ++
" search: search TheMovieDB\n" ++
" fetch: fetch info about one movie\n" ++
" tsearch: search for TV series\n" ++
" tfetch: fetch TV series by ID\n" ++
" season: fetch one season by TV ID and season num\n" ++
" tfull: pull everything about TV series by ID\n" ++
"Examples:\n" ++
" tmdb KEY search \"back to the future\"\n" ++
" tmdb KEY fetch 105\n" ++
" tmdb KEY tsearch Firefly\n" ++
" tmdb KEY tfetch 1437\n" ++
" tmdb KEY season 1437 1\n" ++
" tmdb KEY tfull 1437\n"

+ 0
- 78
vendor/themoviedb/src/Network/API/TheMovieDB.hs View File

@@ -1,78 +0,0 @@
{-

This file is part of the Haskell package themoviedb. It is subject to
the license terms in the LICENSE file found in the top-level directory
of this distribution and at git://pmade.com/themoviedb/LICENSE. No
part of themoviedb package, including this file, may be copied,
modified, propagated, or distributed except according to the terms
contained in the LICENSE file.

-}

{- |

This library provides some data types and functions for fetching movie
metadata from <http://TheMovieDB.org>. To use this library start by
requesting an API key from <http://docs.themoviedb.apiary.io>.

Example:

@
import Network.API.TheMovieDB

main :: IO ()
main = do
-- The API key assigned to you (as a 'Text' value).
let key = "your API key"

-- The 'fetch' function will get a 'Movie' record based on its ID.
result <- runTheMovieDB key (fetchMovie 9340)