Utilities
Provide some utility macros and functions for the ACTest toolkit.
Contents
Index
ACTest.COLORS
ACTest.MODES
ACTest.colorize
ACTest.goodbye
ACTest.line_to_array
ACTest.overview
ACTest.prompt
ACTest.query_args
ACTest.require
ACTest.setup_args
ACTest.sorry
ACTest.welcome
ACTest.@cswitch
ACTest.@pcs
ACTest.@time_call
Color Constants
ACTest.COLORS
— ConstantCOLORS
A global dict, which is used to specify the system colors.
ACTest.MODES
— ConstantMODES
A global dict, which is used to specify the mode for output characters.
Macros
ACTest.@cswitch
— Macro@cswitch(constexpr, body)
Provides a C-like switch statement with the falling through behavior. This implementation was borrowed from the following github repository:
- https://github.com/Gnimuc/CSyntax.jl
Examples
engine = get_d("engine")
@cswitch engine begin
@case "vasp"
just_do_it()
break
@default
sorry()
break
end
ACTest.@time_call
— Macro@time_call(ex)
Evaluate a function call (ex
), and then print the elapsed time (number of seconds) it took to execute.
This macro is a variation of the standard @elapsed
macro.
ACTest.@pcs
— Macro@pcs(x...)
Try to print colorful strings. Here x
is a combination of strings and colors. Its format likes string1 color1 string2 color2 (repeat)
. For the supported colors, please check the global dict COLORS
.
Examples
julia> @pcs "Hello world!" blue
julia> @pcs "Hello " red "world!" green
Query Runtime Environment
ACTest.require
— Functionrequire()
Check the version of julia runtime environment. It should be higher than v1.6.x. One of the most important philosophies of the ACTest
toolkit is minimizing the dependence on the third-party libraries as far as possible. Note that the ACTest
toolkit relys on the TOML
package to parse the *.toml file. Only in v1.6.0 and higher versions, julia includes the TOML
package in its standard library.
Arguments
N/A
Returns
N/A
ACTest.setup_args
— Functionsetup_args(x::Vararg{String})
Setup ARGS
manually. This function is used only in REPL
environment. We can use this function to update ARGS
, so that the query_args()
and the other related functions can work correctly.
Arguments
- x -> Filename of configuration file.
Returns
- ARGS -> Global variable.
Examples
julia> setup_args("act.toml")
1-element Array{String,1}:
"act.toml"
See also: query_args
.
ACTest.query_args
— Functionquery_args()
Check whether the configuration file (case.toml
) is provided.
Arguments
N/A
Returns
- x -> ARGS[1], where ARGS is a global variable.
See also: setup_args
.
Colorful Outputs
ACTest.welcome
— Functionwelcome()
Print out the welcome messages to the screen.
Arguments
N/A
Returns
N/A
ACTest.overview
— Functionoverview()
Print out the overview of ACTest to the screen.
Arguments
N/A
Returns
N/A
ACTest.goodbye
— Functiongoodbye()
Print the goodbye messages to the screen.
Arguments
N/A
Returns
N/A
ACTest.sorry
— Functionsorry()
Print an error message to the screen.
Arguments
N/A
Returns
N/A
ACTest.prompt
— Functionprompt(msg::String)
Print a stylized ACTest message to the screen.
Arguments
- msg -> Message that need to be printed.
Returns
N/A
Input/output Operations
ACTest.line_to_array
— Functionline_to_array(io::IOStream)
Convert a line (reading from an IOStream) to a string array.
Arguments
- io -> An IOStream struct.
Returns
- arr -> An array of String.
line_to_array(str::AbstractString)
Convert a string (AbstractString) to a string array.
Arguments
- str -> A String.
Returns
- ass -> An array of String.
Examples
julia> str = "Hello World!"
"Hello World!"
julia> line_to_array(str)
2-element Vector{SubString{String}}:
"Hello"
"World!"
Color Tools
ACTest.colorize
— Functioncolorize(
c::String,
s::String;
bg::String = "default",
m::String = "default"
)
Return some escape sequences, which will be displayed as colorized texts in the terminal.
Arguments
- c -> Color names.
- s -> The string that want to be printed.
- bg -> Background color.
- m -> Output mode.
Returns
- See above explanations.
colorize(
c::Symbol,
s::String;
bg::String = "default",
m::String = "default"
)
Return some escape sequences, which will be displayed as colorized texts in the terminal.
Arguments
- c -> Color names.
- s -> The string that want to be printed.
- bg -> Background color.
- m -> Output mode.
Returns
- See above explanations.