| File src/hstr.c changed (mode: 100644) (index fc115af..f3db5e8) |
| 26 |
26 |
#include "include/hstr_utils.h" |
#include "include/hstr_utils.h" |
| 27 |
27 |
|
|
| 28 |
28 |
#define SELECTION_CURSOR_IN_PROMPT -1 |
#define SELECTION_CURSOR_IN_PROMPT -1 |
| 29 |
|
#define SELECTION_PREFIX_MAX_LNG 500 |
|
|
29 |
|
#define SELECTION_PREFIX_MAX_LNG 512 |
| 30 |
30 |
#define CMDLINE_LNG 2048 |
#define CMDLINE_LNG 2048 |
|
31 |
|
#define HOSTNAME_BUFFER 128 |
|
32 |
|
|
| 31 |
33 |
|
|
| 32 |
34 |
#define Y_OFFSET_PROMPT 0 |
#define Y_OFFSET_PROMPT 0 |
| 33 |
35 |
#define Y_OFFSET_HELP 1 |
#define Y_OFFSET_HELP 1 |
| |
| ... |
... |
void get_env_configuration() |
| 129 |
131 |
|
|
| 130 |
132 |
int print_prompt() |
int print_prompt() |
| 131 |
133 |
{ |
{ |
| 132 |
|
char *hostname = get_hostname(); |
|
| 133 |
134 |
char *user = getenv(ENV_VAR_USER); |
char *user = getenv(ENV_VAR_USER); |
| 134 |
|
int xoffset = 0; |
|
|
135 |
|
char *hostname=malloc(HOSTNAME_BUFFER); |
|
136 |
|
int xoffset = 0, promptLength; |
| 135 |
137 |
|
|
| 136 |
138 |
if(hicolor) { |
if(hicolor) { |
| 137 |
139 |
color_attr_on(COLOR_PAIR(HH_COLOR_PROMPT)); |
color_attr_on(COLOR_PAIR(HH_COLOR_PROMPT)); |
| 138 |
140 |
color_attr_on(A_BOLD); |
color_attr_on(A_BOLD); |
| 139 |
141 |
} |
} |
| 140 |
|
mvprintw(Y_OFFSET_PROMPT, xoffset, "%s@%s$ ", (user?user:"me"), (hostname?hostname:"localhost")); |
|
|
142 |
|
user=(user?user:"me"); |
|
143 |
|
get_hostname(HOSTNAME_BUFFER, hostname); |
|
144 |
|
mvprintw(Y_OFFSET_PROMPT, xoffset, "%s@%s$ ", user, hostname); |
|
145 |
|
promptLength=strlen(user)+1+strlen(hostname)+1+1; |
|
146 |
|
free(hostname); |
| 141 |
147 |
if(hicolor) { |
if(hicolor) { |
| 142 |
148 |
color_attr_off(A_BOLD); |
color_attr_off(A_BOLD); |
| 143 |
149 |
color_attr_off(COLOR_PAIR(HH_COLOR_PROMPT)); |
color_attr_off(COLOR_PAIR(HH_COLOR_PROMPT)); |
| 144 |
150 |
} |
} |
| 145 |
151 |
refresh(); |
refresh(); |
| 146 |
152 |
|
|
| 147 |
|
return strlen(user)+1+strlen(hostname)+1+1; |
|
|
153 |
|
return promptLength; |
| 148 |
154 |
} |
} |
| 149 |
155 |
|
|
| 150 |
156 |
void print_help_label() |
void print_help_label() |
| File src/hstr_utils.c changed (mode: 100644) (index dccbfab..830c6da) |
| 11 |
11 |
#include <ctype.h> |
#include <ctype.h> |
| 12 |
12 |
|
|
| 13 |
13 |
#define DEFAULT_COMMAND "pwd" |
#define DEFAULT_COMMAND "pwd" |
| 14 |
|
#define HOSTNAME_BUFFER 100 |
|
| 15 |
14 |
#define PROC_HOSTNAME "/proc/sys/kernel/hostname" |
#define PROC_HOSTNAME "/proc/sys/kernel/hostname" |
| 16 |
15 |
|
|
| 17 |
16 |
void tiocsti() |
void tiocsti() |
| |
| ... |
... |
void reverse_char_pointer_array(char **array, unsigned length) |
| 50 |
49 |
} |
} |
| 51 |
50 |
} |
} |
| 52 |
51 |
|
|
| 53 |
|
char *get_hostname() |
|
|
52 |
|
void get_hostname(int bufferSize, char *buffer) |
| 54 |
53 |
{ |
{ |
| 55 |
|
char *b=malloc(HOSTNAME_BUFFER); |
|
| 56 |
|
if(access( PROC_HOSTNAME, F_OK ) != -1) { |
|
| 57 |
|
FILE *f = fopen(PROC_HOSTNAME, "r"); |
|
| 58 |
|
b=fgets(b, HOSTNAME_BUFFER, f); |
|
| 59 |
|
fclose(f); |
|
|
54 |
|
char *b=buffer; |
|
55 |
|
if(access(PROC_HOSTNAME, F_OK) != -1) { |
|
56 |
|
FILE *file = fopen(PROC_HOSTNAME, "r"); |
|
57 |
|
b=fgets(buffer, bufferSize, file); |
|
58 |
|
fclose(file); |
| 60 |
59 |
if(b) { |
if(b) { |
| 61 |
60 |
b[strlen(b)-1]=0; |
b[strlen(b)-1]=0; |
| 62 |
|
return b; |
|
|
61 |
|
return; |
| 63 |
62 |
} |
} |
| 64 |
63 |
} |
} |
| 65 |
|
strcpy(b,"localhost"); |
|
| 66 |
|
return b; |
|
|
64 |
|
strcpy(buffer,"localhost"); |
| 67 |
65 |
} |
} |
| 68 |
66 |
|
|
| 69 |
67 |
void toggle_case(char *str, bool lowercase) { |
void toggle_case(char *str, bool lowercase) { |
| File src/include/hstr_utils.h changed (mode: 100644) (index fa435c1..aa5733c) |
| 23 |
23 |
void tiocsti(); |
void tiocsti(); |
| 24 |
24 |
void fill_terminal_input(char* cmd, bool padding); |
void fill_terminal_input(char* cmd, bool padding); |
| 25 |
25 |
void reverse_char_pointer_array(char **array, unsigned length); |
void reverse_char_pointer_array(char **array, unsigned length); |
| 26 |
|
char *get_hostname(); |
|
|
26 |
|
void get_hostname(int bufferSize, char *buffer); |
| 27 |
27 |
void toggle_case(char *str, bool lowercase); |
void toggle_case(char *str, bool lowercase); |
| 28 |
28 |
|
|
| 29 |
29 |
#endif |
#endif |