Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into cross-compile
Browse files Browse the repository at this point in the history
  • Loading branch information
georgefst committed May 18, 2023
2 parents 15a67c3 + 756c3ff commit 20e114a
Show file tree
Hide file tree
Showing 16 changed files with 576 additions and 25 deletions.
53 changes: 45 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ name: CI
on:
pull_request:
push:
branches: [master]
branches:
- master

jobs:
cabal:
Expand All @@ -13,7 +14,17 @@ jobs:
strategy:
matrix:
os:
- ubuntu-latest
# ubuntu-22.04 (currently ubuntu-latest) appears to not be able to
# install ghc-8.2.2 with ghcup. Possibly because of
# https://github.com/haskell/actions/issues/133.
# TODO: Need to look into what is going on here, and try upgrading
# back to ubuntu-latest at some point.
# - ubuntu-latest
- ubuntu-20.04

# OSX builds were flakey at some point in the past, so we disabled
# them. pretty-simple doesn't have any interesting system-level
# dependencies, so it is probably okay we aren't testing on OSX.
# - macOS-latest
cabal:
- "latest"
Expand All @@ -23,14 +34,15 @@ jobs:
- "8.4.4"
- "8.6.5"
- "8.8.4"
- "8.10.4"
- "9.0.1"
- "8.10.7"
- "9.0.2"
- "9.2.4"

steps:
- uses: actions/checkout@v2
#if: github.event.action == 'opened' || github.event.action == 'synchronize' || github.event.ref == 'refs/heads/master'

- uses: haskell/actions/setup@v1
- uses: haskell/actions/setup@v2
id: setup-haskell-cabal
name: Setup Haskell
with:
Expand All @@ -46,11 +58,24 @@ jobs:
- name: Build
run: |
cabal update
cabal build all --enable-tests --enable-benchmarks --write-ghc-environment-files=always --flags="buildexample"
# TODO: We have a problem where cabal is not able to come up with a
# build plan on GHC-9.2 because the ./cabal.project file defines both
# pretty-simple, and ./web as packages. ./web uses a version of jsaddle
# that doesn't seem to work yet on GHC-9.2. It doesn't seem possible
# to tell cabal to just ignore the web package, and only run the solver
# for pretty-simple.
#
# This hacky workaround just deletes the cabal.project file, so that
# cabal doesn't realize there is another package in ./web.
#
# This workaround can likely be removed when we move to a more recent
# version of jsaddle.
rm ./cabal.project
cabal build package:pretty-simple --enable-tests --enable-benchmarks --write-ghc-environment-files=always --flags="buildexample"
- name: Test
run: |
cabal test all --enable-tests
cabal test package:pretty-simple --enable-tests
stack:
name: stack / ubuntu-latest
Expand All @@ -63,7 +88,7 @@ jobs:
- uses: actions/checkout@v2
#if: github.event.action == 'opened' || github.event.action == 'synchronize' || github.event.ref == 'refs/heads/master'

- uses: haskell/actions/setup@v1
- uses: haskell/actions/setup@v2
name: Setup Haskell Stack
with:
stack-version: ${{ matrix.stack }}
Expand All @@ -83,3 +108,15 @@ jobs:
run: |
stack test
nix-build-web:
name: Nix build GHCJS web
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: cachix/install-nix-action@v16
with:
extra_nix_config: |
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= miso-haskell.cachix.org-1:6N2DooyFlZOHUfJtAx1Q09H0P5XXYzoxxQYiwn6W1e8=
substituters = https://cache.nixos.org/ https://miso-haskell.cachix.org
- name: Build web
run: nix-build ./web
24 changes: 24 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
on:
push:
branches:
- master

jobs:
deploy:
name: Nix build and deploy GHCJS web app
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v16
with:
extra_nix_config: |
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= miso-haskell.cachix.org-1:6N2DooyFlZOHUfJtAx1Q09H0P5XXYzoxxQYiwn6W1e8= haskell-pretty-simple.cachix.org-1:AWHkzPidwcDzWUIUjKcx/PYgud2OBAa9SNUEoIOsATY=
substituters = https://cache.nixos.org/ https://miso-haskell.cachix.org https://haskell-pretty-simple.cachix.org
- name: Build
run: |
nix-build ./web
cp -rL result result-no-symlinks
- name: Deploy
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: result-no-symlinks/bin/web.jsexe
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ cabal.sandbox.config
*.hp
*.eventlog
.stack-work/
web/result
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@

## 4.1.2.0

* Fix a problem with the `pHPrint` function incorrectly
outputting a trailing newline to stdout, instead of the
handle you pass it.
[#118](https://github.com/cdepillabout/pretty-simple/pull/118)
* Add a [web app](https://cdepillabout.github.io/pretty-simple/) where you
can play around with `pretty-simple` in your browser.
[#116](https://github.com/cdepillabout/pretty-simple/pull/116).
This took a lot of hard work by [@georgefst](https://github.com/georgefst)!

## 4.1.1.0

* Make the pretty-printed output with `outputOptionsCompact` enabled a little
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ Just
)
```

If for whatever reason you're not able to incur a dependency on the `pretty-simple` library, you can simulate its behaviour by using `process` to call out to the command line executable (see below for installation):
```hs
pPrint :: Show a => a -> IO ()
pPrint = putStrLn <=< readProcess "pretty-simple" [] . show
```

There's also a [web app](https://cdepillabout.github.io/pretty-simple), compiled with GHCJS, where you can play around with `pretty-simple` in your browser.

## Features

- Easy-to-read
Expand Down
26 changes: 26 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
packages:
.
web

constraints: miso +jsaddle

-- https://github.com/ghcjs/jsaddle/pull/136
source-repository-package
type: git
location: https://github.com/avanov/jsaddle
tag: 0011573a2bafb0c2c17fe95d1212374f13e1b629
subdir: jsaddle

allow-newer:
jsaddle:aeson,
jsaddle:attoparsec,
jsaddle:base-compat,
jsaddle:base64-bytestring,
jsaddle:bytestring,
jsaddle:lens,
jsaddle:text,
jsaddle:time,
jsaddle-warp:aeson,
jsaddle-warp:bytestring,
jsaddle-warp:jsaddle,
jsaddle-warp:text,
2 changes: 1 addition & 1 deletion pretty-simple.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: pretty-simple
version: 4.1.1.0
version: 4.1.2.0
synopsis: pretty printer for data types with a 'Show' instance.
description: Please see <https://github.com/cdepillabout/pretty-simple#readme README.md>.
homepage: https://github.com/cdepillabout/pretty-simple
Expand Down
9 changes: 7 additions & 2 deletions src/Text/Pretty/Simple.hs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ import Prettyprinter (SimpleDocStream)
import Prettyprinter.Render.Terminal
(Color (..), Intensity(Vivid,Dull), AnsiStyle,
renderLazy, renderIO)
import System.IO (Handle, stdout)
import System.IO (Handle, stdout, hPutStrLn)

import Text.Pretty.Simple.Internal
(ColorOptions(..), Style(..), CheckColorTty(..),
Expand Down Expand Up @@ -526,7 +526,7 @@ pHPrintStringOpt checkColorTty outputOptions handle str = do
NoCheckColorTty -> pure outputOptions
liftIO $ do
renderIO handle $ layoutStringAnsi realOutputOpts str
putStrLn ""
hPutStrLn handle ""

-- | Like 'pShow' but takes 'OutputOptions' to change how the
-- pretty-printing is done.
Expand Down Expand Up @@ -658,6 +658,11 @@ layoutStringAnsi opts = fmap convertStyle . layoutString opts
-- ]
-- }
--
-- __Char__
--
-- >>> pPrint 'λ'
-- 'λ'
--
-- __Compactness options__
--
-- >>> pPrintStringOpt CheckColorTty defaultOutputOptionsDarkBg {outputOptionsCompact = True} "AST [] [Def ((3,1),(5,30)) (Id \"fact'\" \"fact'\") [] (Forall ((3,9),(3,26)) [((Id \"n\" \"n_0\"),KPromote (TyCon (Id \"Nat\" \"Nat\")))])]"
Expand Down
21 changes: 12 additions & 9 deletions src/Text/Pretty/Simple/Internal/Printer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,11 @@ hCheckTTY h options = liftIO $ conv <$> tty
-- suitable for passing to any /prettyprinter/ backend.
-- Used by 'Simple.pString' etc.
layoutString :: OutputOptions -> String -> SimpleDocStream Style
layoutString opts =
annotateStyle opts
. removeTrailingWhitespace
layoutString opts = annotateStyle opts . layoutStringAbstract opts

layoutStringAbstract :: OutputOptions -> String -> SimpleDocStream Annotation
layoutStringAbstract opts =
removeTrailingWhitespace
. layoutSmart defaultLayoutOptions
{layoutPageWidth = AvailablePerLine (outputOptionsPageWidth opts) 1}
. indent (outputOptionsInitialIndent opts)
Expand Down Expand Up @@ -231,15 +233,15 @@ prettyExpr opts = (if outputOptionsCompact opts then group else id) . \case
Brackets xss -> list "[" "]" xss
Braces xss -> list "{" "}" xss
Parens xss -> list "(" ")" xss
StringLit s -> join enclose (annotate Quote "\"") $ annotate String $ pretty $
case outputOptionsStringStyle opts of
Literal -> s
EscapeNonPrintable -> escapeNonPrintable $ readStr s
DoNotEscapeNonPrintable -> readStr s
CharLit s -> join enclose (annotate Quote "'") $ annotate String $ pretty s
StringLit s -> join enclose (annotate Quote "\"") $ annotate String $ pretty $ escapeString s
CharLit s -> join enclose (annotate Quote "'") $ annotate String $ pretty $ escapeString s
Other s -> pretty s
NumberLit n -> annotate Num $ pretty n
where
escapeString s = case outputOptionsStringStyle opts of
Literal -> s
EscapeNonPrintable -> escapeNonPrintable $ readStr s
DoNotEscapeNonPrintable -> readStr s
readStr :: String -> String
readStr s = fromMaybe s . readMaybe $ '"' : s ++ "\""
list :: Doc Annotation -> Doc Annotation -> CommaSeparated [Expr]
Expand Down Expand Up @@ -302,6 +304,7 @@ data Annotation
| Quote
| String
| Num
deriving (Eq, Show)

-- | Replace non-printable characters with hex escape sequences.
--
Expand Down
2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# For more information, see: http://docs.haskellstack.org/en/stable/yaml_configuration.html

# Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2)
resolver: lts-18.28
resolver: lts-19.28

# Local packages, usually specified by relative directory name
packages:
Expand Down
8 changes: 4 additions & 4 deletions stack.yaml.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
packages: []
snapshots:
- completed:
size: 590100
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/18/28.yaml
sha256: 428ec8d5ce932190d3cbe266b9eb3c175cd81e984babf876b64019e2cbe4ea68
original: lts-18.28
sha256: 7f4393ad659c579944d12202cffb12d8e4b8114566b015f77bbc303a24cff934
size: 619405
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/19/28.yaml
original: lts-19.28
16 changes: 16 additions & 0 deletions web/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

# pretty-simple Web Page

This directory contains an interactive web page that can be compiled with GHCJS
to show how `pretty-simple` works.

This Haskell package can be built with GHCJS with the command `nix-build`.
You'll need Nix [installed](https://nixos.org/download.html) for this to work.
You'll also need to setup the Miso Nix cache, as explained
[here](https://github.com/cdepillabout/pretty-simple/pull/117#issuecomment-1258023974).

This Haskell package can also be built with GHC with the command `cabal build web`.
Running this executable with `cabal run web` will start a web server listening on
`0.0.0.0:8000`. You should be able to see the web page by opening
<http://localhost:8000> in a web browser. _Note_ that you will need to run
`cabal run web` within this current directory.
40 changes: 40 additions & 0 deletions web/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
with (import
(builtins.fetchTarball {
url =
"https://github.com/dmjio/miso/archive/refs/tags/1.8.3.tar.gz";
sha256 = "0kcr5agbcynm003zj70yfkhsc169ahdcp9pkyr795p5mc3ykycjl";
})
{ });
#TODO we can remove all these patches once we're not stuck on such old tools
# unfortunately GHCJS 8.10.7 has serious performance issues: https://github.com/dmjio/miso/pull/693
let
hp = pkgs.haskell.packages.ghcjs86.override {
all-cabal-hashes = builtins.fetchurl {
url =
"https://github.com/commercialhaskell/all-cabal-hashes/archive/ead1bd926a1b10b04a5c07c8f15827091fa98b38.tar.gz";
sha256 = "15i7ia241wb3s9f6l9n2bqldb4ii73xrj49rfr02q43iqbmdjddv";
};
};
prettyprinter = hp.callHackage "prettyprinter" "1.7.0" { };
prettyprinter-ansi-terminal =
hp.callHackage "prettyprinter-ansi-terminal" "1.1.2" {
prettyprinter = prettyprinter;
};
app = hp.callCabal2nix "web" ./. {
prettyprinter = prettyprinter;
pretty-simple = hp.callCabal2nix "pretty-simple" ./.. {
prettyprinter = prettyprinter;
prettyprinter-ansi-terminal = prettyprinter-ansi-terminal;
};
};
in
pkgs.buildEnv {
name = "pretty-simple-web";
paths = [
app
(pkgs.runCommand "css" { } ''
mkdir -p $out/bin/web.jsexe
cp ${./style.css} $out/bin/web.jsexe/style.css
'')
];
}
Loading

0 comments on commit 20e114a

Please sign in to comment.