From c32d5faefcebf95f15d8dfe22bf3c03a7cbb521d Mon Sep 17 00:00:00 2001 From: Joscha Date: Sat, 29 Feb 2020 20:51:27 +0000 Subject: [PATCH] Create project --- .gitignore | 3 ++ CHANGELOG.md | 4 +++ LICENSE | 21 +++++++++++++ README.md | 1 + Setup.hs | 2 ++ app/Main.hs | 4 +++ package.yaml | 34 +++++++++++++++++++++ src/Profold/LineTree.hs | 40 +++++++++++++++++++++++++ src/Profold/Util.hs | 9 ++++++ stack.yaml | 66 +++++++++++++++++++++++++++++++++++++++++ stack.yaml.lock | 12 ++++++++ 11 files changed, 196 insertions(+) create mode 100644 .gitignore create mode 100644 CHANGELOG.md create mode 100644 LICENSE create mode 100644 README.md create mode 100644 Setup.hs create mode 100644 app/Main.hs create mode 100644 package.yaml create mode 100644 src/Profold/LineTree.hs create mode 100644 src/Profold/Util.hs create mode 100644 stack.yaml create mode 100644 stack.yaml.lock diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dc4c7ba --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.stack-work/ +profold.cabal +*~ \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..871aa6c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,4 @@ +# Changelog for profold + +## Upcoming +* create project diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..eee7b87 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Garmelon + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..1e8b593 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# profold diff --git a/Setup.hs b/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/app/Main.hs b/app/Main.hs new file mode 100644 index 0000000..683a8de --- /dev/null +++ b/app/Main.hs @@ -0,0 +1,4 @@ +module Main where + +main :: IO () +main = putStrLn "Nothing to see here" diff --git a/package.yaml b/package.yaml new file mode 100644 index 0000000..49e3510 --- /dev/null +++ b/package.yaml @@ -0,0 +1,34 @@ +name: profold +version: 0.1.0.0 +license: MIT +author: "Garmelon " +copyright: "2020 Garmelon" + +synopsis: A TUI viewer for GHC .prof files that can fold/unfold sections +description: Please see the README on GitHub at +github: "Garmelon/profold" + +extra-source-files: +- README.md +- CHANGELOG.md + +dependencies: +- base >= 4.7 && < 5 +- containers +- megaparsec +- text +- vector + +library: + source-dirs: src + +executables: + profold: + main: Main.hs + source-dirs: app + ghc-options: + - -threaded + - -rtsopts + - -with-rtsopts=-N + dependencies: + - profold diff --git a/src/Profold/LineTree.hs b/src/Profold/LineTree.hs new file mode 100644 index 0000000..6ae2c81 --- /dev/null +++ b/src/Profold/LineTree.hs @@ -0,0 +1,40 @@ +module Profold.LineTree + ( LineNode(..) + , Path + , onlyUnfolded + , flatten + , modify + , toggleFold + ) where + +import qualified Data.Text as T +import qualified Data.Vector as V + +import Profold.Util + +data LineNode = LineNode + { lineText :: T.Text + , lineChildren :: V.Vector LineNode + , lineFolded :: Bool + } deriving (Show) + +type Path = [Int] + +onlyUnfolded :: LineNode -> LineNode +onlyUnfolded ln + | lineFolded ln = ln{lineChildren = V.empty} + | otherwise = ln + +flatten :: LineNode -> V.Vector (Path, T.Text) +flatten ln = + V.cons ([], lineText ln) $ + V.imap (\i (is, t) -> (i : is, t)) $ + V.concatMap flatten $ + lineChildren ln + +modify :: (LineNode -> LineNode) -> Path -> LineNode -> LineNode +modify f [] ln = f ln +modify f (i:is) ln = ln{lineChildren = modifyAtIndex i (modify f is) $ lineChildren ln} + +toggleFold :: Path -> LineNode -> LineNode +toggleFold = modify $ \ln -> ln{lineFolded = not $ lineFolded ln} diff --git a/src/Profold/Util.hs b/src/Profold/Util.hs new file mode 100644 index 0000000..79c2b75 --- /dev/null +++ b/src/Profold/Util.hs @@ -0,0 +1,9 @@ +module Profold.Util + ( modifyAtIndex + ) where + +import qualified Data.Vector as V + +modifyAtIndex :: Int -> (a -> a) -> V.Vector a -> V.Vector a +-- Yes, this function looks ugly, but it's short enough that I don't care. +modifyAtIndex i f v = maybe v (\a -> v V.// [(i, f a)]) (v V.!? i) diff --git a/stack.yaml b/stack.yaml new file mode 100644 index 0000000..465f104 --- /dev/null +++ b/stack.yaml @@ -0,0 +1,66 @@ +# This file was automatically generated by 'stack init' +# +# Some commonly used options have been documented as comments in this file. +# For advanced use and comprehensive documentation of the format, please see: +# https://docs.haskellstack.org/en/stable/yaml_configuration/ + +# Resolver to choose a 'specific' stackage snapshot or a compiler version. +# A snapshot resolver dictates the compiler version and the set of packages +# to be used for project dependencies. For example: +# +# resolver: lts-3.5 +# resolver: nightly-2015-09-21 +# resolver: ghc-7.10.2 +# +# The location of a snapshot can be provided as a file or url. Stack assumes +# a snapshot provided as a file might change, whereas a url resource does not. +# +# resolver: ./custom-snapshot.yaml +# resolver: https://example.com/snapshots/2018-01-01.yaml +resolver: lts-15.1 + +# User packages to be built. +# Various formats can be used as shown in the example below. +# +# packages: +# - some-directory +# - https://example.com/foo/bar/baz-0.0.2.tar.gz +# subdirs: +# - auto-update +# - wai +packages: +- . +# Dependency packages to be pulled from upstream that are not in the resolver. +# These entries can reference officially published versions as well as +# forks / in-progress versions pinned to a git hash. For example: +# +# extra-deps: +# - acme-missiles-0.3 +# - git: https://github.com/commercialhaskell/stack.git +# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a +# +# extra-deps: [] + +# Override default flag values for local packages and extra-deps +# flags: {} + +# Extra package databases containing global packages +# extra-package-dbs: [] + +# Control whether we use the GHC we find on the path +# system-ghc: true +# +# Require a specific version of stack, using version ranges +# require-stack-version: -any # Default +# require-stack-version: ">=2.1" +# +# Override the architecture used by stack, especially useful on Windows +# arch: i386 +# arch: x86_64 +# +# Extra directories used by stack for building +# extra-include-dirs: [/path/to/dir] +# extra-lib-dirs: [/path/to/dir] +# +# Allow a newer minor version of GHC than the snapshot specifies +# compiler-check: newer-minor diff --git a/stack.yaml.lock b/stack.yaml.lock new file mode 100644 index 0000000..7e51098 --- /dev/null +++ b/stack.yaml.lock @@ -0,0 +1,12 @@ +# This file was autogenerated by Stack. +# You should not edit this file by hand. +# For more information, please see the documentation at: +# https://docs.haskellstack.org/en/stable/lock_files + +packages: [] +snapshots: +- completed: + size: 489011 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/15/1.yaml + sha256: d4ecc42b7125d68e4c3c036a08046ad0cd02ae0d9efbe3af2223a00ff8cc16f3 + original: lts-15.1