Skip to content

Commit

Permalink
Merge pull request #38 from teloscube/vst/some-housekeeping
Browse files Browse the repository at this point in the history
Some Housekeeping
  • Loading branch information
vst authored Sep 28, 2023
2 parents 76a081b + 1d67806 commit 332a3f8
Show file tree
Hide file tree
Showing 30 changed files with 532 additions and 558 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
*~
.stack-work/
.ghc.environment*
dist-newstyle/
dist/
profiles.yaml
result
40 changes: 20 additions & 20 deletions .hlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,37 @@
#######################

- modules:
- {name: Control.Monad.Error, within: []}
- {name: [Data.Aeson], as: Aeson}
- {name: Data.ByteString, as: B }
- {name: Data.ByteString.Char8, as: BC }
- {name: Data.ByteString.Lazy, as: BL }
- {name: Data.ByteString.Lazy.Char8, as: BLC }
- {name: Data.List, as: List }
- {name: Data.Text, as: T }
- {name: Data.Text.Lazy, as: TL }
- {name: Data.Text.Encoding, as: TE }
- { name: Control.Monad.Error, within: [] }
- { name: [Data.Aeson], as: Aeson }
- { name: Data.ByteString, as: B }
- { name: Data.ByteString.Char8, as: BC }
- { name: Data.ByteString.Lazy, as: BL }
- { name: Data.ByteString.Lazy.Char8, as: BLC }
- { name: Data.List, as: List }
- { name: Data.Text, as: T }
- { name: Data.Text.Lazy, as: TL }
- { name: Data.Text.Encoding, as: TE }

##########################
# EXTENSION RESTRICTIONS #
##########################

- extensions:
- default: false # All extension are banned by default
- name: # Only these listed extensions can be used
- DeriveGeneric
- GADTs
- OverloadedStrings
- QuasiQuotes
- RecordWildCards
- ScopedTypeVariables
- default: false # All extension are banned by default
- name: # Only these listed extensions can be used
- DeriveGeneric
- GADTs
- OverloadedStrings
- QuasiQuotes
- RecordWildCards
- ScopedTypeVariables

################
# CUSTOM RULES #
################

# Replace a $ b $ c with a . b $ c
- group: {name: dollar, enabled: true}
- group: { name: dollar, enabled: true }

# Generalise map to fmap, ++ to <>
- group: {name: generalise, enabled: true}
- group: { name: generalise, enabled: true }
26 changes: 0 additions & 26 deletions Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2020-2022, Teloscube Pte Ltd
Copyright (c) 2020-2023, Teloscube Pte Ltd

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Expand Down
49 changes: 22 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# DECAF API Client Suite For Haskell
# DECAF CLI Application and Haskell Client Library

A Haskell client library to DECAF API and a small application demonstrating
library usage and providing some utilities for working with DECAF instances.
This repository mainly provides a Haskell client library for DECAF APIs and a
small application (1) demonstrating library usage and (2) providing some
utilities for working with DECAF Instances.

> **TODO:** Provide full README.
Expand Down Expand Up @@ -36,6 +37,7 @@ $ decafcli --help
decafcli - DECAF Command-line Client Application

Usage: decafcli [--version] COMMAND

DECAF Client

Available options:
Expand Down Expand Up @@ -101,19 +103,19 @@ nix-shell
Build:

```sh
cabal build
cabal build -O0
```

Open VSCode if you wish to do so:
Test:

```sh
code .
cabal test -O0
```

Run hlint:

```sh
hlint app/ src/ test/
hlint app/ src/ tests/
```

Format codebase:
Expand All @@ -122,35 +124,28 @@ Format codebase:
fourmolu -i app/ src/ test/
```

Run:

```sh
cabal run -O0 decafcli -- --help
```

## Release Process

```console
$ nix-shell
[inside-nix-shell]$ ./release.sh -n <VERSION>
```

... whereby `<VERSION>` follows [Haskell PVP
Specification](https://pvp.haskell.org/), such as `1.2.3.4`. Note that
there is no `v` prefix.
... where `<VERSION>` follows [Haskell PVP Specification], such as `1.2.3.4`.

## Static Compilation
Note that there is no `v` prefix.

We are able to statically build, strip and compress the executable inside a
Docker image. Following command performs the necessary compilation, copy the
file to host machine and inform the user about the path to the copied file:

```sh
./compile-static.sh
```
## License

> **IMPORTANT:** Note that everytime we update Nix sources or add a new
> dependency to Haskell project, we must regenerate the freeze file:
>
> ```sh
> cabal freeze
> mv cabal.project.freeze cabal.project.freeze.tmpl
> ```
[BSD 3-Clause License]. Copyright (c) 2020-2023, Teloscube Pte Ltd.

## License
<!-- REFERENCES -->

[BSD 3-Clause License](./LICENSE). Copyright (c) 2020-2022, Teloscube Pte Ltd.
[BSD 3-Clause License]: ./LICENSE
[Haskell PVP Specification]: https://pvp.haskell.org
2 changes: 0 additions & 2 deletions Setup.hs

This file was deleted.

54 changes: 26 additions & 28 deletions app/Decaf/Client/Cli/SubCommands/Tui.hs
Original file line number Diff line number Diff line change
Expand Up @@ -75,31 +75,31 @@ app =
}


handleEvent :: TuiState -> Brick.BrickEvent () e -> Brick.EventM () (Brick.Next TuiState)
handleEvent s (Brick.VtyEvent ev) = case ev of
Vty.EvKey Vty.KEsc [] -> Brick.halt s
Vty.EvKey (Vty.KChar 'q') _ -> Brick.halt s
Vty.EvKey (Vty.KChar 'a') _ -> Brick.continue (s {tuiStateWorld = TuiStateWorldAbout})
Vty.EvKey (Vty.KChar 'r') _ -> reloadTuiProfileInfos s >>= Brick.continue
Vty.EvKey _ _ -> Brick.continue s
Vty.EvMouseDown _n _i _but _mods -> Brick.continue s
Vty.EvMouseUp _n _i _mBut -> Brick.continue s
Vty.EvResize _n _i -> Brick.continue s
Vty.EvPaste _bs -> Brick.continue s
Vty.EvLostFocus -> Brick.continue s
Vty.EvGainedFocus -> Brick.continue s
handleEvent b _ = Brick.continue b
handleEvent :: Brick.BrickEvent () e -> Brick.EventM () TuiState ()
handleEvent (Brick.VtyEvent ev) = case ev of
Vty.EvKey Vty.KEsc [] -> Brick.halt
Vty.EvKey (Vty.KChar 'q') _ -> Brick.halt
Vty.EvKey (Vty.KChar 'a') _ -> Brick.modify (\s -> s {tuiStateWorld = TuiStateWorldAbout})
Vty.EvKey (Vty.KChar 'r') _ -> reloadTuiProfileInfos
Vty.EvKey _ _ -> pure ()
Vty.EvMouseDown _n _i _but _mods -> pure ()
Vty.EvMouseUp _n _i _mBut -> pure ()
Vty.EvResize _n _i -> pure ()
Vty.EvPaste _bs -> pure ()
Vty.EvLostFocus -> pure ()
Vty.EvGainedFocus -> pure ()
handleEvent _ = pure ()


attrMap :: Brick.AttrMap
attrMap =
Brick.attrMap
Vty.defAttr
[ ("info", Vty.defAttr {Vty.attrForeColor = Vty.SetTo Vty.black})
, ("muted", Vty.defAttr {Vty.attrForeColor = Vty.SetTo Vty.cyan})
, ("success", Vty.defAttr {Vty.attrForeColor = Vty.SetTo Vty.green})
, ("warning", Vty.defAttr {Vty.attrForeColor = Vty.SetTo Vty.yellow})
, ("failure", Vty.defAttr {Vty.attrForeColor = Vty.SetTo Vty.red})
[ (Brick.attrName "info", Vty.defAttr {Vty.attrForeColor = Vty.SetTo Vty.black})
, (Brick.attrName "muted", Vty.defAttr {Vty.attrForeColor = Vty.SetTo Vty.cyan})
, (Brick.attrName "success", Vty.defAttr {Vty.attrForeColor = Vty.SetTo Vty.green})
, (Brick.attrName "warning", Vty.defAttr {Vty.attrForeColor = Vty.SetTo Vty.yellow})
, (Brick.attrName "failure", Vty.defAttr {Vty.attrForeColor = Vty.SetTo Vty.red})
]


Expand Down Expand Up @@ -159,20 +159,18 @@ mkProfilesTableRow TuiProfileInfo {..} =
, widget tuiProfileInfoCountPolicy
]
where
widget (Left err) = Brick.withAttr "failure" $ Brick.txt err
widget (Right sv) = Brick.withAttr "success" $ Brick.txt sv
widget (Left err) = Brick.withAttr (Brick.attrName "failure") $ Brick.txt err
widget (Right sv) = Brick.withAttr (Brick.attrName "success") $ Brick.txt sv


-- * Event Logic


reloadTuiProfileInfos :: TuiState -> Brick.EventM () TuiState
reloadTuiProfileInfos state@TuiState {..} = do
reloadTuiProfileInfos :: Brick.EventM () TuiState ()
reloadTuiProfileInfos = do
TuiState {..} <- Brick.get
infos <- liftIO $ getTuiProfileInfos tuiStateProfiles
pure $
state
{ tuiStateWorld = TuiStateWorldProfileInfos infos
}
Brick.modify (\s -> s {tuiStateWorld = TuiStateWorldProfileInfos infos})


getTuiProfileInfos :: [DC.DecafProfile] -> IO [TuiProfileInfo]
Expand Down Expand Up @@ -225,7 +223,7 @@ getBaristaVersion client = do
getEstateVersion :: DC.DecafClient -> IO (Either T.Text T.Text)
getEstateVersion client = do
value <- DC.runDecafEstateJson (DC.path "version") client
case ACD.parseEither (ACD.at ["value"] ACD.auto) value of
case ACD.parseEither ACD.text value of
Left err -> pure $ Left (T.pack err)
Right sv -> pure $ Right sv

Expand Down
2 changes: 2 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
packages: .
write-ghc-environment-files: always
Loading

0 comments on commit 332a3f8

Please sign in to comment.