<commit_before>{-# LANGUAGE RecordWildCards, DeriveDataTypeable, CPP, ScopedTypeVariables #-}

module Main(main) where

import Control.Monad
import System.Directory
import Data.Time.Clock
import Data.List
import GHCi
import Util
import Test
import System.Console.CmdArgs
import Control.Exception


data Options = Options
    {command :: String
    ,height :: Int
    ,test :: Bool
    }
    deriving (Data,Typeable,Show)

options = cmdArgsMode $ Options
    {command = "" &= typ "COMMAND" &= help "Command to run (defaults to ghci or cabal repl)"
    ,height = 8 &= help "Number of lines to show"
    ,test = False &= help "Run the test suite"
    } &= verbosity &=
    program "ghcid" &= summary "Auto :reload'ing GHCi daemon"

#if defined(mingw32_HOST_OS)
foreign import stdcall unsafe "windows.h GetConsoleWindow"
    c_GetConsoleWindow :: IO Int

foreign import stdcall unsafe "windows.h SetWindowPos"
    c_SetWindowPos :: Int -> Int -> Int -> Int -> Int -> Int -> Int -> IO Int

c_HWND_TOPMOST = -1
#endif

main :: IO ()
main = do
    Options{..} <- cmdArgsRun options
#if defined(mingw32_HOST_OS)
    when (not test) $ do
        wnd <- c_GetConsoleWindow
        c_SetWindowPos wnd c_HWND_TOPMOST 0 0 0 0 3
        return ()
#endif
    runTest test $ \output -> do
        dotGhci <- doesFileExist ".ghci"
        ghci <- ghci $ if command /= "" then command
                       else if dotGhci then "ghci" else "cabal repl"
        let fire msg warnings = do
                start <- getCurrentTime
                load <- fmap parseLoad $ ghci msg
                modsActive <- fmap (map snd . parseShowModules) $ ghci ":show modules"
                modsLoad <- return $ nub $ map loadFile load
                whenLoud $ do
                    outStrLn $ "%ACTIVE: " ++ show modsActive<commit_msg>Added command-line parameter for topmost behaviour<commit_after>{-# LANGUAGE RecordWildCards, DeriveDataTypeable, CPP, ScopedTypeVariables #-}

module Main(main) where

import Control.Monad
import System.Directory
import Data.Time.Clock
import Data.List
import GHCi
import Util
import Test
import System.Console.CmdArgs
import Control.Exception


data Options = Options
    {command :: String
    ,height :: Int
    ,test :: Bool
    ,topmost :: Bool
    }
    deriving (Data,Typeable,Show)

options = cmdArgsMode $ Options
    {command = "" &= typ "COMMAND" &= help "Command to run (defaults to ghci or cabal repl)"
    ,height = 8 &= help "Number of lines to show"
    ,test = False &= help "Run the test suite"
    ,topmost = False &= help "Set window topmost (Windows only)"
    } &= verbosity &=
    program "ghcid" &= summary "Auto :reload'ing GHCi daemon"

#if defined(mingw32_HOST_OS)
foreign import stdcall unsafe "windows.h GetConsoleWindow"
    c_GetConsoleWindow :: IO Int

foreign import stdcall unsafe "windows.h SetWindowPos"
    c_SetWindowPos :: Int -> Int -> Int -> Int -> Int -> Int -> Int -> IO Int

c_HWND_TOPMOST = -1
#endif

main :: IO ()
main = do
    Options{..} <- cmdArgsRun options
#if defined(mingw32_HOST_OS)
    when ((not test) && topmost) $ do
        wnd <- c_GetConsoleWindow
        c_SetWindowPos wnd c_HWND_TOPMOST 0 0 0 0 3
        return ()
#endif
    runTest test $ \output -> do
        dotGhci <- doesFileExist ".ghci"
        ghci <- ghci $ if command /= "" then command
                       else if dotGhci then "ghci" else "cabal repl"
        let fire msg warnings = do
                start <- getCurrentTime
                load <- fmap parseLoad $ ghci msg
                modsActive <- fmap (map snd . parseShowModules) $ ghci ":show modules"
                modsLoad <- return $ nub $ map loadFile load
                whenLoud $ do
                    outStrLn $ "%ACTIVE: " ++ show modsActive
{'fraction_non_alphanumeric': 0.09840425531914894, 'fraction_numerical': 0.005851063829787234, 'mean_word_length': 2.5347744360902253, 'pattern_counts': {'":': 2, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '167347', 'n_tokens_mistral': 1181, 'n_tokens_neox': 1133, 'n_words': 385}