on master help sign in
issue #2004 resolved by --consolewith cmd line param
commit1bf27316b5618bc026c141b426134086966737c5 authorAndreas Reuleaux <arx@a-rx.info> dateWed 18 Mar 2015, 09:55 (12 years ago) parente6d1cfd
5 files changed+65−23
idris.cabal+1 src/Idris/AbsSyntaxTree.hs+24−21 src/Idris/CmdOptions.hs+30 src/Idris/REPL.hs+9−1 test/docs001/run+1−1
idris.cabal+1
@@ -801,6 +801,7 @@ Library
801801 , vector-binary-instances < 0.3
802802 , xml < 1.4
803803 , zlib < 0.6
804+ , safe
804805 Extensions: MultiParamTypeClasses
805806 , DeriveFoldable
806807 , DeriveTraversable
src/Idris/AbsSyntaxTree.hs+24−21
@@ -66,27 +66,27 @@ toplevel = EInfo [] emptyContext id Nothing Nothing (\_ _ _ -> fail "Not impleme
6666eInfoNames :: ElabInfo -> [Name]
6767eInfoNames info = map fst (params info) ++ M.keys (inblock info)
6868
69−data IOption = IOption { opt_logLevel :: Int,
70− opt_typecase :: Bool,
71− opt_typeintype :: Bool,
72− opt_coverage :: Bool,
73− opt_showimp :: Bool, -- ^^ show implicits
74− opt_errContext :: Bool,
75− opt_repl :: Bool,
76− opt_verbose :: Bool,
77− opt_nobanner :: Bool,
78− opt_quiet :: Bool,
79− opt_codegen :: Codegen,
80− opt_outputTy :: OutputType,
81− opt_ibcsubdir :: FilePath,
82− opt_importdirs :: [FilePath],
83− opt_triple :: String,
84− opt_cpu :: String,
85− opt_cmdline :: [Opt], -- remember whole command line
86− opt_origerr :: Bool,
87− opt_autoSolve :: Bool, -- ^ automatically apply "solve" tactic in prover
88− opt_autoImport :: [FilePath], -- ^ e.g. Builtins+Prelude
89− opt_optimise :: [Optimisation]
69+data IOption = IOption { opt_logLevel :: Int,
70+ opt_typecase :: Bool,
71+ opt_typeintype :: Bool,
72+ opt_coverage :: Bool,
73+ opt_showimp :: Bool, -- ^^ show implicits
74+ opt_errContext :: Bool,
75+ opt_repl :: Bool,
76+ opt_verbose :: Bool,
77+ opt_nobanner :: Bool,
78+ opt_quiet :: Bool,
79+ opt_codegen :: Codegen,
80+ opt_outputTy :: OutputType,
81+ opt_ibcsubdir :: FilePath,
82+ opt_importdirs :: [FilePath],
83+ opt_triple :: String,
84+ opt_cpu :: String,
85+ opt_cmdline :: [Opt], -- remember whole command line
86+ opt_origerr :: Bool,
87+ opt_autoSolve :: Bool, -- ^ automatically apply "solve" tactic in prover
88+ opt_autoImport :: [FilePath], -- ^ e.g. Builtins+Prelude
89+ opt_optimise :: [Optimisation]
9090 }
9191 deriving (Show, Eq)
9292
@@ -151,6 +151,8 @@ data OutputMode = RawOutput Handle -- ^ Print user output directly to the handle
151151data ConsoleWidth = InfinitelyWide -- ^ Have pretty-printer assume that lines should not be broken
152152 | ColsWide Int -- ^ Manually specified - must be positive
153153 | AutomaticWidth -- ^ Attempt to determine width, or 80 otherwise
154+ deriving (Show, Eq)
155+
154156
155157-- | The global state used in the Idris monad
156158data IState = IState {
@@ -463,6 +465,7 @@ data Opt = Filename String
463465 | ShowOrigErr
464466 | AutoWidth -- ^ Automatically adjust terminal width
465467 | AutoSolve -- ^ Automatically issue "solve" tactic in interactive prover
468+ | UseConsoleWidth ConsoleWidth
466469 deriving (Show, Eq)
467470
468471-- Parsed declarations
src/Idris/CmdOptions.hs+30
@@ -11,6 +11,12 @@ import Options.Applicative.Arrows
1111import Data.Char
1212import Data.Maybe
1313
14+import Text.ParserCombinators.ReadP hiding (many, option)
15+
16+import Safe (lastMay)
17+
18+
19+
1420import qualified Text.PrettyPrint.ANSI.Leijen as PP
1521
1622runArgParser :: IO [Opt]
@@ -67,6 +73,7 @@ parser = runA $ proc () -> do
6773 files <- asA (many $ argument (fmap Filename str) (metavar "FILES")) -< ()
6874 A parseVersion >>> A helper -< (flags ++ files)
6975
76+
7077parseFlags :: Parser [Opt]
7178parseFlags = many $
7279 flag' NoBanner (long "nobanner" <> help "Suppress the banner")
@@ -132,6 +139,10 @@ parseFlags = many $
132139 <|> (TargetCPU <$> strOption (long "cpu" <> metavar "CPU" <> help "Select target CPU e.g. corei7 or cortex-m3 (for LLVM codegen)"))
133140 <|> flag' (ColourREPL True) (long "colour" <> long "color" <> help "Force coloured output")
134141 <|> flag' (ColourREPL False) (long "nocolour" <> long "nocolor" <> help "Disable coloured output")
142+
143+ <|> (UseConsoleWidth <$> option (str >>= parseConsoleWidth) (long "consolewidth" <> metavar "WIDTH" <> help "Select console width: auto, infinite, nat"))
144+
145+
135146 where
136147 getExt s = case maybeRead s of
137148 Just ext -> ext
@@ -151,3 +162,22 @@ preProcOpts (x:xs) ys = preProcOpts xs (x:ys)
151162parseCodegen :: String -> Codegen
152163parseCodegen "bytecode" = Bytecode
153164parseCodegen cg = Via (map toLower cg)
165+
166+
167+
168+
169+parseConsoleWidth :: Monad m => String -> m ConsoleWidth
170+parseConsoleWidth "auto" = return AutomaticWidth
171+parseConsoleWidth "infinite" = return InfinitelyWide
172+parseConsoleWidth s =
173+ case lastMay (readP_to_S (integerReader) s) of
174+ Just (r, _) -> return $ ColsWide r
175+ _ -> fail $ "Cannot parse: " ++ s
176+
177+
178+
179+integerReader :: ReadP Int
180+integerReader = do
181+ digits <- many1 $ satisfy isDigit
182+ return $ read digits
183+
src/Idris/REPL.hs+9−1
@@ -1554,7 +1554,9 @@ idrisMain opts =
15541554 when (DefaultTotal `elem` opts) $ do i <- getIState
15551555 putIState (i { default_total = True })
15561556 setColourise $ not quiet && last (True : opt getColour opts)
1557− when (not runrepl) $ setWidth InfinitelyWide
1557+
1558+ when (not runrepl) $ mapM_ setWidth (opt getConsoleWidth opts)
1559+
15581560 mapM_ addLangExt (opt getLanguageExt opts)
15591561 setREPL runrepl
15601562 setQuiet (quiet || isJust script || not (null immediate))
@@ -1777,6 +1779,12 @@ getCodegen :: Opt -> Maybe Codegen
17771779getCodegen (UseCodegen x) = Just x
17781780getCodegen _ = Nothing
17791781
1782+
1783+getConsoleWidth :: Opt -> Maybe ConsoleWidth
1784+getConsoleWidth (UseConsoleWidth x) = Just x
1785+getConsoleWidth _ = Nothing
1786+
1787+
17801788getExecScript :: Opt -> Maybe String
17811789getExecScript (InterpretScript expr) = Just expr
17821790getExecScript _ = Nothing
test/docs001/run+1−1
@@ -1,3 +1,3 @@
11#!/usr/bin/env bash
2−idris --nobanner --nocolor docs001.idr < input
2+idris --nobanner --nocolor --consolewidth 80 docs001.idr < input
33rm *.ibc