diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-19 09:01:42 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-19 09:01:42 +0000 |
| commit | c23e61b4455cee8669c7d594478a4238048f032f (patch) | |
| tree | 084e9c90a440483797fdf64fb0fc43470d4b9d16 /src/util | |
| parent | 83588b7ee9349a941b91294fa83fe6e207883ab6 (diff) | |
fix vt100 cursor pos race
Diffstat (limited to 'src/util')
| -rw-r--r-- | src/util/prompt.cc | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/src/util/prompt.cc b/src/util/prompt.cc index 92ce2ce..0046b0f 100644 --- a/src/util/prompt.cc +++ b/src/util/prompt.cc @@ -7,29 +7,50 @@ namespace ov4 bool emit_prompt = true; /* emit prompt (default) */ - void print_prompt() + int print_prompt() { if (emit_prompt) { char hostname[MAXLINE]; gethostname(hostname, MAXLINE); + string _getlogin = safe_str(getlogin()); + string _gethostname = safe_str(hostname); + string _get_current_dir = get_current_dir(); + string _get_prompt = get_prompt_symbol(); + string _at_symbol = "@"; + string _space = " "; + string _semicolon = ":"; + cout << make_color((string)name, ov4::color::bright_green) - << " " - << make_color(safe_str(getlogin()) , ov4::color::bright_blue) - << make_color("@", ov4::color::bright_blue) - << make_color(hostname, ov4::color::bright_blue) - << ":" - << make_color(get_current_dir(), ov4::color::bright_purple) - << " " - << make_color(get_prompt(), ov4::color::bright_yellow) - << " " + << _space + << make_color(_getlogin , ov4::color::bright_blue) + << make_color(_at_symbol, ov4::color::bright_blue) + << make_color(_gethostname, ov4::color::bright_blue) + << _semicolon + << make_color(_get_current_dir, ov4::color::bright_purple) + << _space + << make_color(_get_prompt, ov4::color::bright_yellow) + << _space << flush; + + return + name.size() + + _space.size() + + _getlogin.size() + + _at_symbol.size() + + _gethostname.size() + + _semicolon.size() + + _get_current_dir.size() + + _space.size() + + _get_prompt.size() + + _space.size(); } + return 0; } - string get_prompt() + string get_prompt_symbol() { return (string)(safe_str(getlogin()) == "root" ? prompt_root : prompt_normal); } |
