[all] Reorganize haskell code into multiple packages

This commit is contained in:
Joscha 2020-03-14 01:02:57 +00:00
parent 0edc241149
commit 4b8d0ee4a4
37 changed files with 368 additions and 140 deletions

1
.gitignore vendored
View file

@ -1,3 +1,2 @@
.stack-work/
forest.cabal
*~

View file

@ -1,4 +1,4 @@
# Changelog for forest
## upcoming
* create project
- create project

View file

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

1
forest-cabin/README.md Normal file
View file

@ -0,0 +1 @@
# forest-cabin

View file

@ -0,0 +1,52 @@
cabal-version: 1.12
-- This file has been generated from package.yaml by hpack version 0.31.2.
--
-- see: https://github.com/sol/hpack
--
-- hash: c619b22393d818639b183c69031b267a4ed16faeaf609a75ef1cadb9288195e1
name: forest-cabin
version: 0.1.0.0
synopsis: A forest server hosted at forest.plugh.de
description: Please see the README at <https://github.com/Garmelon/forest#readme>
homepage: https://github.com/Garmelon/forest#readme
bug-reports: https://github.com/Garmelon/forest/issues
author: Garmelon <joscha@plugh.de>
maintainer: Garmelon <joscha@plugh.de>
copyright: 2020 Garmelon
license: MIT
build-type: Simple
extra-source-files:
README.md
source-repository head
type: git
location: https://github.com/Garmelon/forest
library
other-modules:
Paths_forest_cabin
hs-source-dirs:
src
build-depends:
base >=4.7 && <5
, forest-common
, forest-server
, websockets
default-language: Haskell2010
executable forest-cabin
main-is: Main.hs
other-modules:
Paths_forest_cabin
hs-source-dirs:
app
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, forest-cabin
, forest-common
, forest-server
, websockets
default-language: Haskell2010

32
forest-cabin/package.yaml Normal file
View file

@ -0,0 +1,32 @@
name: forest-cabin
version: 0.1.0.0
license: MIT
author: Garmelon <joscha@plugh.de>
copyright: 2020 Garmelon
synopsis: A forest server hosted at forest.plugh.de
description: Please see the README at <https://github.com/Garmelon/forest#readme>
github: Garmelon/forest
extra-source-files:
- README.md
dependencies:
- base >= 4.7 && < 5
- forest-common
- forest-server
- websockets
library:
source-dirs: src
executables:
forest-cabin:
source-dirs: app
main: Main.hs
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- forest-cabin

1
forest-common/README.md Normal file
View file

@ -0,0 +1 @@
# forest-common

View file

@ -0,0 +1,44 @@
cabal-version: 1.12
-- This file has been generated from package.yaml by hpack version 0.31.2.
--
-- see: https://github.com/sol/hpack
--
-- hash: e59723e563cf364a74b1032409ed7a9d3ecbec3a6baa34554771cb5c1a5689d9
name: forest-common
version: 0.1.0.0
synopsis: A tree-based multi-user interaction thing
description: Please see the README at <https://github.com/Garmelon/forest#readme>
homepage: https://github.com/Garmelon/forest#readme
bug-reports: https://github.com/Garmelon/forest/issues
author: Garmelon <joscha@plugh.de>
maintainer: Garmelon <joscha@plugh.de>
copyright: 2020 Garmelon
license: MIT
build-type: Simple
extra-source-files:
README.md
source-repository head
type: git
location: https://github.com/Garmelon/forest
library
exposed-modules:
Forest.Api
Forest.Node
Forest.OrderedMap
Forest.Util
other-modules:
Paths_forest_common
hs-source-dirs:
src
build-depends:
aeson
, async
, base >=4.7 && <5
, containers
, text
, websockets
default-language: Haskell2010

View file

@ -0,0 +1,23 @@
name: forest-common
version: 0.1.0.0
license: MIT
author: Garmelon <joscha@plugh.de>
copyright: 2020 Garmelon
synopsis: A tree-based multi-user interaction thing
description: Please see the README at <https://github.com/Garmelon/forest#readme>
github: Garmelon/forest
extra-source-files:
- README.md
dependencies:
- base >= 4.7 && < 5
- aeson
- async
- containers
- text
- websockets
library:
source-dirs: src

View file

@ -1,11 +1,16 @@
{-# LANGUAGE OverloadedStrings #-}
module Forest.Util
( findPrev
(
-- * List operations
findPrev
, findNext
-- * Monadic looping constructs
, whileM
, runUntilJustM
, whileNothingM
-- * Multithreading helpers
, withThread
-- * Websocket helper functions
, sendPacket
, closeWithErrorMessage
, receivePacket
@ -24,9 +29,6 @@ findPrev f as = fst <$> find (f . snd) (zip as $ tail as)
findNext :: (a -> Bool) -> [a] -> Maybe a
findNext f as = snd <$> find (f . fst) (zip as $ tail as)
withThread :: IO () -> IO () -> IO ()
withThread thread main = withAsync thread $ const main
-- | Run a monadic action until it returns @False@ for the first time.
whileM :: Monad m => m Bool -> m ()
whileM f = do
@ -36,13 +38,16 @@ whileM f = do
else pure ()
-- | Run a monadic action until it returns @Just a@ for the first time.
runUntilJustM :: Monad m => m (Maybe a) -> m a
runUntilJustM f = do
whileNothingM :: Monad m => m (Maybe a) -> m a
whileNothingM f = do
result <- f
case result of
Nothing -> runUntilJustM f
Nothing -> whileNothingM f
Just a -> pure a
withThread :: IO () -> IO () -> IO ()
withThread thread main = withAsync thread $ const main
sendPacket :: ToJSON a => WS.Connection -> a -> IO ()
sendPacket conn packet = WS.sendTextData conn $ encode packet

1
forest-server/README.md Normal file
View file

@ -0,0 +1 @@
# forest-server

View file

@ -0,0 +1,47 @@
cabal-version: 1.12
-- This file has been generated from package.yaml by hpack version 0.31.2.
--
-- see: https://github.com/sol/hpack
--
-- hash: c0d366de2ff27f13dd69d751b47017143df332454ad700dd8fb5089d9837f1a8
name: forest-server
version: 0.1.0.0
synopsis: A framework for forest servers
description: Please see the README at <https://github.com/Garmelon/forest#readme>
homepage: https://github.com/Garmelon/forest#readme
bug-reports: https://github.com/Garmelon/forest/issues
author: Garmelon <joscha@plugh.de>
maintainer: Garmelon <joscha@plugh.de>
copyright: 2020 Garmelon
license: MIT
build-type: Simple
extra-source-files:
README.md
source-repository head
type: git
location: https://github.com/Garmelon/forest
library
exposed-modules:
Forest.Server
Forest.Server.Broadcast
Forest.Server.TreeModule
Forest.Server.TreeModule.Animate
Forest.Server.TreeModule.Const
Forest.Server.TreeModule.Fork
Forest.Server.TreeModule.SharedEditing
other-modules:
Paths_forest_server
hs-source-dirs:
src
build-depends:
base >=4.7 && <5
, containers
, forest-common
, text
, transformers
, websockets
default-language: Haskell2010

View file

@ -0,0 +1,23 @@
name: forest-server
version: 0.1.0.0
license: MIT
author: Garmelon <joscha@plugh.de>
copyright: 2020 Garmelon
synopsis: A framework for forest servers
description: Please see the README at <https://github.com/Garmelon/forest#readme>
github: Garmelon/forest
extra-source-files:
- README.md
dependencies:
- base >= 4.7 && < 5
- containers
- forest-common
- text
- transformers
- websockets
library:
source-dirs: src

View file

@ -32,7 +32,7 @@ sendUpdatesThread conn nodeChan nodeA = do
{- Main server application that receives and processes client packets -}
receivePackets :: TreeModule a () => WS.Connection -> a () -> IO ()
receivePackets conn treeModule = runUntilJustM $ do
receivePackets conn treeModule = whileNothingM $ do
packet <- receivePacket conn
case packet of
ClientEdit path text -> do

1
forest-tui/README.md Normal file
View file

@ -0,0 +1 @@
# forest-tui

View file

@ -0,0 +1,74 @@
cabal-version: 1.12
-- This file has been generated from package.yaml by hpack version 0.31.2.
--
-- see: https://github.com/sol/hpack
--
-- hash: 9ca3a1fe555e2dceb3459b6ae920b1ed93aac76398d4909a7030d7992b79ce40
name: forest-tui
version: 0.1.0.0
synopsis: A terminal-based client for forest
description: Please see the README at <https://github.com/Garmelon/forest#readme>
homepage: https://github.com/Garmelon/forest#readme
bug-reports: https://github.com/Garmelon/forest/issues
author: Garmelon <joscha@plugh.de>
maintainer: Garmelon <joscha@plugh.de>
copyright: 2020 Garmelon
license: MIT
build-type: Simple
extra-source-files:
README.md
source-repository head
type: git
location: https://github.com/Garmelon/forest
library
exposed-modules:
Forest.Client
Forest.Client.NodeUtil
Forest.Client.Options
Forest.Client.UiState
Forest.Client.Websocket
Forest.Client.Widgets.NodeEditor
Forest.Client.Widgets.WidgetTree
other-modules:
Paths_forest_tui
hs-source-dirs:
src
build-depends:
base >=4.7 && <5
, brick
, containers
, forest-common
, optparse-applicative
, safe
, text
, text-zipper
, vty
, websockets
, wuss
default-language: Haskell2010
executable forest
main-is: Main.hs
other-modules:
Paths_forest_tui
hs-source-dirs:
app
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, brick
, containers
, forest-common
, forest-tui
, optparse-applicative
, safe
, text
, text-zipper
, vty
, websockets
, wuss
default-language: Haskell2010

39
forest-tui/package.yaml Normal file
View file

@ -0,0 +1,39 @@
name: forest-tui
version: 0.1.0.0
license: MIT
author: Garmelon <joscha@plugh.de>
copyright: 2020 Garmelon
synopsis: A terminal-based client for forest
description: Please see the README at <https://github.com/Garmelon/forest#readme>
github: Garmelon/forest
extra-source-files:
- README.md
dependencies:
- base >= 4.7 && < 5
- brick
- containers
- forest-common
- optparse-applicative
- safe
- text
- text-zipper
- vty
- websockets
- wuss
library:
source-dirs: src
executables:
forest:
source-dirs: app
main: Main.hs
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- forest-tui

View file

@ -17,7 +17,7 @@ import qualified Network.WebSockets as WS
import Forest.Api
import Forest.Client.UiState
import Forest.Client.Websocket
import Forest.Client.WidgetTree
import Forest.Client.Widgets.WidgetTree
import Forest.Node
import Forest.Util

View file

@ -40,9 +40,9 @@ import qualified Data.Text as T
import qualified Graphics.Vty as Vty
import Safe
import Forest.Client.NodeEditor
import Forest.Client.NodeUtil
import Forest.Client.WidgetTree
import Forest.Client.Widgets.NodeEditor
import Forest.Client.Widgets.WidgetTree
import Forest.Node
import qualified Forest.OrderedMap as OMap

View file

@ -1,6 +1,6 @@
{-# LANGUAGE OverloadedStrings #-}
module Forest.Client.NodeEditor
module Forest.Client.Widgets.NodeEditor
( NodeEditor
, getCurrentText
, beginEdit

View file

@ -1,6 +1,6 @@
{-# LANGUAGE OverloadedStrings #-}
module Forest.Client.WidgetTree
module Forest.Client.Widgets.WidgetTree
( WidgetTree(..)
, renderWidgetTreeWith
, renderWidgetTree

View file

@ -1,52 +0,0 @@
name: forest
version: 0.1.0.0
license: MIT
author: "Garmelon <joscha@plugh.de>"
copyright: "2020 Garmelon"
synopsis: A tree-based multi-user interaction thing
description: Please see the README on GitHub at <https://github.com/Garmelon/forest#readme>
github: "Garmelon/forest"
extra-source-files:
- README.md
- CHANGELOG.md
dependencies:
- base >= 4.7 && < 5
- aeson
- async
- brick
- containers
- optparse-applicative
- safe
- text
- text-zipper
- transformers
- vty
- websockets
- wuss
library:
source-dirs: src
executables:
forest-server:
main: Main.hs
source-dirs: server
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- forest
forest-client:
main: Main.hs
source-dirs: client
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- forest

View file

@ -1,66 +1,6 @@
# 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
- forest-cabin
- forest-common
- forest-server
- forest-tui