Utilities

Provide some utility macros and functions for the ACFlow toolkit.

Contents

Index

Color Constants

ACFlow.COLORSConstant
COLORS

A global dict, which is used to specify the system colors.

ACFlow.MODESConstant
MODES

A global dict, which is used to specify the mode for output characters.

Macros

ACFlow.@cswitchMacro
@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
ACFlow.@time_callMacro
@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.@pcsMacro
@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

See also: COLORS, welcome.

Query Runtime Environment

ACFlow.requireFunction
require()

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_argsFunction
setup_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_argsFunction
query_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_errorFunction
trace_error(io)

Write exceptions or errors to terminal or external file.

Arguments

  • io -> Output stream.

Returns

N/A

See also: catch_error.

ACFlow.catch_errorFunction
catch_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()
end

See also: trace_error.

Colorful Outputs

ACFlow.welcomeFunction
welcome()

Print out the welcome messages to the screen.

Arguments

N/A

Returns

N/A

ACFlow.overviewFunction
overview()

Print out the overview of ACFlow to the screen.

Arguments

N/A

Returns

N/A

ACFlow.goodbyeFunction
goodbye()

Print the goodbye messages to the screen.

Arguments

N/A

Returns

N/A

ACFlow.sorryFunction
sorry()

Print an error message to the screen.

Arguments

N/A

Returns

N/A

ACFlow.promptFunction
prompt(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_arrayFunction
line_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

ACFlow.colorizeFunction
colorize(
    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.