Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: CI

on:
push:
branches:
- main
pull_request:

jobs:
build:
name: Build
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: haskell-actions/setup@v2
with:
ghc-version: "9.8.2"
cabal-version: "3.12.1.0"

- run: |
cabal update
cabal build all

tests:
name: Tests
runs-on: ubuntu-latest
needs: build

steps:
- uses: actions/checkout@v4

- uses: haskell-actions/setup@v2
with:
ghc-version: "9.8.2"
cabal-version: "3.12.1.0"

- run: |
cabal update
cabal test all

format-hs:
name: Haskell format
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: haskell-actions/setup@v2
with:
ghc-version: "9.8.2"
cabal-version: "3.12.1.0"

- name: Install ormolu
run: |
cabal install ormolu --overwrite-policy=always
echo "$HOME/.cabal/bin" >> "$GITHUB_PATH"

- name: Check formatting
run: |
find . \
-name '*.hs' \
-not -path './dist-newstyle/*' \
-not -path './runtimes/*' \
-exec ormolu --mode check {} +

prettier:
name: Prettier
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: "20"

- run: npm install --global prettier

- run: prettier --check . --ignore-path .prettierignore
6 changes: 3 additions & 3 deletions cli/CLI/UI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@

module CLI.UI where

import CLI.AppEnv (ConfigLoadResult (clrWarning))
import Control.Concurrent (forkIO, threadDelay)
import Control.Concurrent.MVar (MVar, newMVar, withMVar)
import Control.Exception (SomeException, displayException, try)
import Control.Monad (unless, when)
import Data.Bits ((.|.))
import Data.Char (toLower)
import Data.Foldable (for_)
import Data.IORef (IORef, atomicModifyIORef', modifyIORef', newIORef, readIORef, writeIORef)
import Data.List (isInfixOf)
import Data.Maybe (isNothing)
import Data.Foldable (for_)
import Data.Text (Text)
import Data.Text qualified as T
import Data.Text.IO qualified as TIO
import System.Environment (lookupEnv)
import System.Info (os)
import System.IO (Handle, hFlush, hIsTerminalDevice, stdin, stdout)
import CLI.AppEnv (ConfigLoadResult (clrWarning))
import System.Info (os)
#if defined(mingw32_HOST_OS)
import System.Win32.Console (eNABLE_PROCESSED_OUTPUT, eNABLE_VIRTUAL_TERMINAL_PROCESSING, getConsoleMode, setConsoleMode)
import System.Win32.Types (withHandleToHANDLE)
Expand Down
21 changes: 12 additions & 9 deletions cli/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@
module Main where

import CLI.Commands
import CLI.Runtime (Runtime, mkRuntime)
import CLI.Config qualified as Config
import CLI.Download qualified as Download
import CLI.Onboarding (runOnboarding)
import CLI.Runtime (Runtime, mkRuntime)
import CLI.Submit qualified as Submit
import Control.Exception (SomeException, try)
import Data.List (find)
import Data.Version (showVersion)
import GHC.IO.Encoding (utf8)
import Options.Applicative
import Options.Applicative.Help.Pretty (Doc, pretty, vsep)
import Paths_openleetcode qualified
import System.Environment (getArgs, withArgs)
import System.Exit (exitWith, ExitCode (ExitFailure, ExitSuccess))
import System.Exit (ExitCode (ExitFailure, ExitSuccess), exitWith)
import System.IO (hSetEncoding, stderr, stdout)
#if defined(mingw32_HOST_OS)
import System.Win32.Console (setConsoleOutputCP)
Expand Down Expand Up @@ -70,11 +68,16 @@ cliHelpFooter =

initConsoleEncoding :: IO ()
initConsoleEncoding = do
#if defined(mingw32_HOST_OS)
do
_ <- try (setConsoleOutputCP 65001) :: IO (Either SomeException ())
pure ()
#endif
setupWindowsCP
_ <- try (hSetEncoding stdout utf8) :: IO (Either SomeException ())
_ <- try (hSetEncoding stderr utf8) :: IO (Either SomeException ())
pure ()

setupWindowsCP :: IO ()
#if defined(mingw32_HOST_OS)
setupWindowsCP = do
_ <- try (setConsoleOutputCP 65001) :: IO (Either SomeException ())
pure ()
#else
setupWindowsCP = pure ()
#endif
Loading