9||| Retrieves a value from the environment if the given key is present,
10||| otherwise it returns Nothing.
11getEnv : String -> IO (Maybe String)
14 is_nil <- nullStr str_ptr
17 else pure (Just str_ptr)
20 getEnv' = foreign FFI_C "getenv" (String -> IO String) key
22||| Sets an environment variable with a given value.
23||| Returns true if the operation was successful.
24setEnv : String -> String -> IO Bool
26 ok <- foreign FFI_C "setenv" (String -> String -> Int -> IO Int) key value 1
29||| Unsets an environment variable.
30||| Returns true if the variable was able to be unset.
31unsetEnv : String -> IO Bool
33 ok <- foreign FFI_C "unsetenv" (String -> IO Int) key
36getEnvironment : IO (List (String, String))
37getEnvironment = getAllPairs 0 []
39 getEnvPair : Int -> IO String
40 getEnvPair i = foreign FFI_C "getEnvPair" (Int -> IO String) i
42 splitEq : String -> (String, String)
44 -- FIXME: There has to be a better way to split this up
45 let (k, v) = break (== '=') str in
46 let (_, v') = break (/= '=') v in
49 getAllPairs : Int -> List String -> IO (List (String, String))
50 getAllPairs n acc = do
51 envPair <- getEnvPair n
52 is_nil <- nullStr envPair
54 then pure $ reverse $ map splitEq acc
55 else getAllPairs (n + 1) (envPair :: acc)
57||| Programs can either terminate successfully, or end in a caught
59data ExitCode : Type where
60 ||| Terminate successfully.
61 ExitSuccess : ExitCode
62 ||| Program terminated for some prescribed reason.
64 ||| @errNo A non-zero numerical value indicating failure.
65 ||| @prf Proof that the int value is non-zero.
66 ExitFailure : (errNo : Int)
67 -> {auto prf : So (not $ errNo == 0)}
70||| Quit with a particular exit code
72exit code = believe_me $ foreign FFI_C "exit" (Int -> IO ()) code
74||| Terminate the program with an `ExitCode`. This code indicates the
75||| success of the program's execution, and returns the success code
76||| to the program's caller.
78||| @code The `ExitCode` for program.
79exitWith : (code : ExitCode) -> IO a
80exitWith ExitSuccess = exit 0
81exitWith (ExitFailure errNo) = exit errNo
83||| Exit the program indicating failure.
85exitFailure = exitWith (ExitFailure 1)
87||| Exit the program after a successful run.
89exitSuccess = exitWith ExitSuccess
91||| Get the numbers of seconds since 1st January 1970, 00:00 UTC
93time = do MkRaw t <- foreign FFI_C "idris_time" (IO (Raw Integer))
96||| Specify interval to sleep for, must be in range [0, 1000000]
97usleep : (i : Int) -> { auto prf : So (i >= 0 && i <= 1000000) } -> IO ()
98usleep i = foreign FFI_C "usleep" (Int -> IO ()) i
100||| Execute a program and returns its exit status code.
101system : String -> IO Int
102system cmd = foreign FFI_C "system" (String -> IO Int) cmd
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list