1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

tools: make the v REPL help screen look nicer (#10833)

This commit is contained in:
William Gooch 2021-07-17 04:23:29 -04:00 committed by GitHub
parent 355f46f475
commit 51dd8304bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 6 deletions

View File

@ -115,7 +115,7 @@ fn repl_help() {
fn run_repl(workdir string, vrepl_prefix string) {
if !is_stdin_a_pipe {
println(util.full_v_version(false))
println('Use Ctrl-C or `exit` to exit, or `help` to see other available commands')
println('Use Ctrl-C or ${util.pretty_print('exit')} to exit, or ${util.pretty_print('help')} to see other available commands')
}
if vstartup != '' {

View File

@ -60,9 +60,13 @@ fn main() {
// Running `./v` without args launches repl
if args.len == 0 {
if os.is_atty(0) != 0 {
println('Welcome to the V REPL (for help with V itself, type `exit`, then run `v help`).')
cmd_exit := util.pretty_print('exit')
cmd_help := util.pretty_print('v help')
file_main := util.pretty_print('main.v')
cmd_run := util.pretty_print('v run main.v')
println('Welcome to the V REPL (for help with V itself, type $cmd_exit, then run $cmd_help).')
eprintln(' NB: the REPL is highly experimental. For best V experience, use a text editor,')
eprintln(' save your code in a `main.v` file and do: `v run main.v`')
eprintln(' save your code in a $file_main file and execute: $cmd_run')
} else {
mut args_and_flags := util.join_env_vflags_and_os_args()[1..].clone()
args_and_flags << ['run', '-']
@ -124,7 +128,7 @@ fn main() {
if prefs.is_help {
invoke_help_and_exit(args)
}
eprintln('v $command: unknown command\nRun "v help" for usage.')
eprintln('v $command: unknown command\nRun ${util.pretty_print('v help')} for usage.')
exit(1)
}
@ -134,7 +138,7 @@ fn invoke_help_and_exit(remaining []string) {
2 { help.print_and_exit(remaining[1]) }
else {}
}
println('`v help`: provide only one help topic.')
println('For usage information, use `v help`.')
println('${util.pretty_print('v help')}: provide only one help topic.')
println('For usage information, use ${util.pretty_print('v help')}.')
exit(1)
}

View File

@ -5,6 +5,7 @@ module util
import os
import time
import term
import v.pref
import v.vmod
import v.util.recompilation
@ -569,3 +570,9 @@ pub fn find_all_v_files(roots []string) ?[]string {
}
return files
}
// Highlight a command with an on-brand background to make CLI
// commands immediately recognizable.
pub fn pretty_print(command string) string {
return term.bright_white(term.bg_cyan(' $command '))
}