aboutsummaryrefslogtreecommitdiff
path: root/src/util/prompt.cc
blob: 0046b0f5cf08f8ddb2e7184d46774de12117f82c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

#include "util/prompt.h"

using namespace std;

namespace ov4
{

    bool emit_prompt = true; /* emit prompt (default) */

    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) 
                << _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_symbol()
    {
        return (string)(safe_str(getlogin()) == "root" ? prompt_root : prompt_normal);
    }
}