Provide some utility macros and functions for the ACFlow toolkit.
ACFlow.COLORSACFlow.MODESACFlow.catch_errorACFlow.colorizeACFlow.goodbyeACFlow.line_to_arrayACFlow.overviewACFlow.promptACFlow.query_argsACFlow.requireACFlow.setup_argsACFlow.sorryACFlow.trace_errorACFlow.welcomeACFlow.@cswitchACFlow.@pcsACFlow.@time_call
Color Constants
ACFlow.COLORS — ConstantCOLORSA global dict, which is used to specify the system colors.
ACFlow.MODES — ConstantMODESA global dict, which is used to specify the mode for output characters.
Macros
ACFlow.@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
endACFlow.@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.
ACFlow.@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!" greenQuery Runtime Environment
ACFlow.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 ACFlow toolkit is minimizing the dependence on the third-party libraries as far as possible. Note that the ACFlow 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
ACFlow.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("ac.toml")
1-element Array{String,1}:
"ac.toml"See also: query_args.
ACFlow.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.
Error Handler
ACFlow.trace_error — Functiontrace_error(io)Write exceptions or errors to terminal or external file.
Arguments
- io -> Output stream.
Returns
N/A
See also: catch_error.
ACFlow.catch_error — Functioncatch_error()Catch the thrown exceptions or errors, print them to the terminal or external file (err.out).
Arguments
N/A
Returns
N/A
Examples
try
return solve(read_data())
catch ex
catch_error()
endSee also: trace_error.
Colorful Outputs
ACFlow.welcome — Functionwelcome()Print out the welcome messages to the screen.
Arguments
N/A
Returns
N/A
ACFlow.overview — Functionoverview()Print out the overview of ACFlow to the screen.
Arguments
N/A
Returns
N/A
ACFlow.goodbye — Functiongoodbye()Print the goodbye messages to the screen.
Arguments
N/A
Returns
N/A
ACFlow.sorry — Functionsorry()Print an error message to the screen.
Arguments
N/A
Returns
N/A
ACFlow.prompt — Functionprompt(msg::String)Print a stylized ACFlow message to the screen.
Arguments
- msg -> Message that need to be printed.
Returns
N/A
Input/Output Operations
ACFlow.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
- arr -> 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
ACFlow.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.