v.util #

Constants #

const (
	emanager = new_error_manager()
)

emanager.support_color - should the error and other messages have ANSI terminal escape color codes in them. By default, v tries to autodetect, if the terminal supports colors. Use -color and -nocolor options to override the detection decision.

const (
	v_version = '0.2.2'
)
const (
	builtin_module_parts = ['math.bits', 'strconv', 'strconv.ftoa', 'hash', 'strings', 'builtin']
	bundle_modules       = ['clipboard', 'fontstash', 'gg', 'gx', 'sokol', 'szip', 'ui']
)

math.bits is needed by strconv.ftoa

const (
	external_module_dependencies_for_tool = map{
		'vdoc': ['markdown']
	}
)

fn args_quote_paths #

fn args_quote_paths(args []string) string

fn bold #

fn bold(msg string) string

fn cescaped_path #

fn cescaped_path(s string) string

fn check_module_is_installed #

fn check_module_is_installed(modulename string, is_verbose bool) ?bool

fn color_compare_files #

fn color_compare_files(diff_cmd string, file1 string, file2 string) string

fn color_compare_strings #

fn color_compare_strings(diff_cmd string, unique_prefix string, expected string, found string) string

fn contains_capital #

fn contains_capital(s string) bool

fn ensure_modules_for_all_tools_are_installed #

fn ensure_modules_for_all_tools_are_installed(is_verbose bool)

fn find_all_v_files #

fn find_all_v_files(roots []string) ?[]string

find_all_v_files - given a list of files/folders, finds all .v/.vsh files if some of the files/folders on the list does not exist, or a file is not a .v or .vsh file, returns an error instead.

fn find_working_diff_command #

fn find_working_diff_command() ?string

iterates through a list of known diff cli commands and returns it with basic options

fn formatted_error #

fn formatted_error(kind string, omsg string, filepath string, pos token.Position) string

formatted_error - kind may be 'error' or 'warn'

fn full_hash #

fn full_hash() string

fn full_v_version #

fn full_v_version(is_verbose bool) string

full_v_version() returns the full version of the V compiler

fn get_timers #

fn get_timers() &Timers

fn get_vtmp_folder #

fn get_vtmp_folder() string

fn githash #

fn githash(should_get_from_filesystem bool) string

githash(x) returns the current git commit hash. When x is false, it is very fast - it just returns a predefined C constant. When x is true, it tries to get the current commit hash, by parsing the relevant files in the .git/ folder, or if that is not possible for example when using a V from a V binary release, that does not have .git/ defaults to getting the predefined C constant again. NB: githash(true) must be called only when v detects that it builds itself. For all other programs, githash(false) should be used.

fn good_type_name #

fn good_type_name(s string) bool

HTTPRequest bad HttpRequest good

fn is_func_char #

fn is_func_char(c byte) bool

fn is_generic_type_name #

fn is_generic_type_name(name string) bool

is_generic_type_name returns true if the current token is a generic type name.

fn is_name_char #

fn is_name_char(c byte) bool

fn is_nl #

fn is_nl(c byte) bool

fn join_env_vflags_and_os_args #

fn join_env_vflags_and_os_args() []string

fn launch_tool #

fn launch_tool(is_verbose bool, tool_name string, args []string)

launch_tool - starts a V tool in a separate process, passing it the args. All V tools are located in the cmd/tools folder, in files or folders prefixed by the letter v, followed by the tool name, i.e. cmd/tools/vdoc/ or cmd/tools/vpm.v. The folder variant is suitable for larger and more complex tools, like v doc, because it provides you the ability to split their source in separate .v files, organized by topic, as well as have resources like static css/text/js files, that the tools can use. launch_tool uses a timestamp based detection mechanism, so that after v self, each tool will be recompiled too, before it is used, which guarantees that it would be up to date with V itself. That mechanism can be disabled by package managers by creating/touching a small cmd/tools/.disable_autorecompilation file, OR by changing the timestamps of all executables in cmd/tools to be < 1024 seconds (in unix time).

fn mod_path_to_full_name #

fn mod_path_to_full_name(mod string, path string) ?string

TODO: * properly define module location / v.mod rules * if possible split this function in two, one which gets the parent module path and another which turns it into the full name * create shared logic between these fns and builder.find_module_path

fn new_error_manager #

fn new_error_manager() &EManager

fn new_suggestion #

fn new_suggestion(wanted string, possibilities []string) Suggestion

fn new_timers #

fn new_timers(should_print bool) &Timers

fn no_cur_mod #

fn no_cur_mod(typename string, cur_mod string) string

no_cur_mod - removes cur_mod. prefix from typename, but only when it is at the start, i.e.: no_cur_mod('vproto.Abdcdef', 'proto') == 'vproto.Abdcdef' even though proto. is a substring

fn no_dots #

fn no_dots(s string) string

fn path_of_executable #

fn path_of_executable(path string) string

fn prepare_tool_when_needed #

fn prepare_tool_when_needed(source_name string)

fn qualify_import #

fn qualify_import(pref &pref.Preferences, mod string, file_path string) string

fn qualify_module #

fn qualify_module(mod string, file_path string) string

fn quote_path #

fn quote_path(s string) string

fn read_file #

fn read_file(file_path string) ?string

fn recompile_file #

fn recompile_file(vexe string, file string)

fn replace_op #

fn replace_op(s string) string

fn resolve_env_value #

fn resolve_env_value(str string, check_for_presence bool) ?string

resolve_env_value replaces all occurrences of $env('ENV_VAR_NAME') in str with the value of the env variable $ENV_VAR_NAME.

fn resolve_vroot #

fn resolve_vroot(str string, dir string) ?string

fn set_vroot_folder #

fn set_vroot_folder(vroot_path string)

fn short_module_name #

fn short_module_name(name string) string

fn should_bundle_module #

fn should_bundle_module(mod string) bool

fn should_recompile_tool #

fn should_recompile_tool(vexe string, tool_source string, tool_name string, tool_exe string) bool

NB: should_recompile_tool/4 compares unix timestamps that have 1 second resolution That means that a tool can get recompiled twice, if called in short succession. TODO: use a nanosecond mtime timestamp, if available.

fn skip_bom #

fn skip_bom(file_content string) string

fn smart_quote #

fn smart_quote(str string, raw bool) string

fn source_context #

fn source_context(kind string, source string, pos token.Position) []string

fn strip_main_name #

fn strip_main_name(name string) string

fn strip_mod_name #

fn strip_mod_name(name string) string

fn tabs #

fn tabs(n int) string

fn timing_measure #

fn timing_measure(label string)

fn timing_measure_cumulative #

fn timing_measure_cumulative(label string)

fn timing_set_should_print #

fn timing_set_should_print(should_print bool)

fn timing_start #

fn timing_start(label string)

fn verror #

fn verror(kind string, s string)

fn vhash #

fn vhash() string

vhash() returns the build string C.V_COMMIT_HASH . See cmd/tools/gen_vc.v .

fn vlines_escape_path #

fn vlines_escape_path(path string, ccompiler string) string

fn (Suggestion) add #

fn (mut s Suggestion) add(val string)

fn (Suggestion) add_many #

fn (mut s Suggestion) add_many(many []string)

fn (Suggestion) sort #

fn (mut s Suggestion) sort()

fn (Suggestion) say #

fn (s Suggestion) say(msg string) string

struct EManager #

struct EManager {
mut:
	support_color bool
}

fn (EManager) set_support_color #

fn (e &EManager) set_support_color(b bool)

struct Timers #

struct Timers {
pub mut:
	swatches     map[string]time.StopWatch
	should_print bool
}

fn (Timers) start #

fn (mut t Timers) start(name string)

fn (Timers) measure #

fn (mut t Timers) measure(name string) i64

fn (Timers) measure_cumulative #

fn (mut t Timers) measure_cumulative(name string) i64

fn (Timers) measure_pause #

fn (mut t Timers) measure_pause(name string)

fn (Timers) measure_resume #

fn (mut t Timers) measure_resume(name string)

fn (Timers) message #

fn (mut t Timers) message(name string) string

fn (Timers) show #

fn (mut t Timers) show(label string)

fn (Timers) show_if_exists #

fn (mut t Timers) show_if_exists(label string)

fn (Timers) dump_all #

fn (mut t Timers) dump_all()