summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJefferson Delfes <jefferson.delfes@gmail.com>2013-10-21 09:39:06 -0400
committerJefferson Delfes <jefferson.delfes@gmail.com>2013-10-21 14:30:07 -0400
commit175f4a98033e54e77dc85f7a9658f00f492c775b (patch)
tree53362e411473d378fb3bebad7ffef070c32b8b78
parentb686a84309cc4c47789f8193f680757d98a76ee3 (diff)
rl_helper: add support to manage prompt string
If we want to change prompt string, we need to manage it inside rl_helper.
-rw-r--r--rl_helper.c9
-rw-r--r--rl_helper.h2
2 files changed, 10 insertions, 1 deletions
diff --git a/rl_helper.c b/rl_helper.c
index dc0af9d..2cc014f 100644
--- a/rl_helper.c
+++ b/rl_helper.c
@@ -44,6 +44,7 @@ char lnbuf[MAX_LINE_BUFFER]; /* buffer for our line editing */
size_t pos = 0;
char seq[MAX_SEQ]; /* sequence buffer (escape codes) */
size_t seq_pos = 0;
+const char *prompt = "> ";
typedef struct {
char sequence[MAX_SEQ];
@@ -92,7 +93,7 @@ void rl_clear_line() {
void rl_reprint_prompt() {
rl_clear_line();
- printf("> %s", lnbuf);
+ printf("%s%s", prompt, lnbuf);
fflush(stdout);
}
@@ -108,6 +109,12 @@ void rl_init(line_process_callback cb) {
line_cb = cb;
}
+void rl_set_prompt(const char *str) {
+
+ prompt = str;
+ rl_reprint_prompt();
+}
+
void rl_quit() {
rl_clear();
diff --git a/rl_helper.h b/rl_helper.h
index 0f23423..f1d6266 100644
--- a/rl_helper.h
+++ b/rl_helper.h
@@ -5,6 +5,8 @@ typedef void (*line_process_callback)(char *line);
/* initializes buffers and set line process callback */
void rl_init(line_process_callback cb);
+/* configure prompt string, (eg "> ") */
+void rl_set_prompt(const char *str);
/* close resources */
void rl_quit();
/* add char to line buffer */