summaryrefslogtreecommitdiff
path: root/readline.c
diff options
context:
space:
mode:
authoraliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>2009-03-05 23:01:23 +0000
committeraliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>2009-03-05 23:01:23 +0000
commit376253ece484b7dc86f215641dca47c3c88f38d1 (patch)
treecbbcd578628422d88cc6326012f59e7081d3c77e /readline.c
parentbb5fc20f7c1c65e95030da3629dd0d7a0cce38cd (diff)
monitor: Rework API (Jan Kiszka)
Refactor the monitor API and prepare it for decoupled terminals: term_print functions are renamed to monitor_* and all monitor services gain a new parameter (mon) that will once refer to the monitor instance the output is supposed to appear on. However, the argument remains unused for now. All monitor command callbacks are also extended by a mon parameter so that command handlers are able to pass an appropriate reference to monitor output services. For the case that monitor outputs so far happen without clearly identifiable context, the global variable cur_mon is introduced that shall once provide a pointer either to the current active monitor (while processing commands) or to the default one. On the mid or long term, those use case will be obsoleted so that this variable can be removed again. Due to the broad usage of the monitor interface, this patch mostly deals with converting users of the monitor API. A few of them are already extended to pass 'mon' from the command handler further down to internal functions that invoke monitor_printf. At this chance, monitor-related prototypes are moved from console.h to a new monitor.h. The same is done for the readline API. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6711 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'readline.c')
-rw-r--r--readline.c47
1 files changed, 29 insertions, 18 deletions
diff --git a/readline.c b/readline.c
index 5a089be89..ffa5424fa 100644
--- a/readline.c
+++ b/readline.c
@@ -21,8 +21,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#include "qemu-common.h"
-#include "console.h"
+#include "readline.h"
+#include "monitor.h"
#define TERM_CMD_BUF_SIZE 4095
#define TERM_MAX_CMDS 64
@@ -49,7 +49,7 @@ static char *term_history[TERM_MAX_CMDS];
static int term_hist_entry = -1;
static int nb_completions;
-int completion_index;
+static int completion_index;
static char *completions[NB_COMPLETIONS_MAX];
static ReadLineFunc *term_readline_func;
@@ -59,8 +59,10 @@ static void *term_readline_opaque;
void readline_show_prompt(void)
{
- term_printf("%s", term_prompt);
- term_flush();
+ Monitor *mon = cur_mon;
+
+ monitor_printf(mon, "%s", term_prompt);
+ monitor_flush(mon);
term_last_cmd_buf_index = 0;
term_last_cmd_buf_size = 0;
term_esc_state = IS_NORM;
@@ -69,22 +71,23 @@ void readline_show_prompt(void)
/* update the displayed command line */
static void term_update(void)
{
+ Monitor *mon = cur_mon;
int i, delta, len;
if (term_cmd_buf_size != term_last_cmd_buf_size ||
memcmp(term_cmd_buf, term_last_cmd_buf, term_cmd_buf_size) != 0) {
for(i = 0; i < term_last_cmd_buf_index; i++) {
- term_printf("\033[D");
+ monitor_printf(mon, "\033[D");
}
term_cmd_buf[term_cmd_buf_size] = '\0';
if (term_is_password) {
len = strlen(term_cmd_buf);
for(i = 0; i < len; i++)
- term_printf("*");
+ monitor_printf(mon, "*");
} else {
- term_printf("%s", term_cmd_buf);
+ monitor_printf(mon, "%s", term_cmd_buf);
}
- term_printf("\033[K");
+ monitor_printf(mon, "\033[K");
memcpy(term_last_cmd_buf, term_cmd_buf, term_cmd_buf_size);
term_last_cmd_buf_size = term_cmd_buf_size;
term_last_cmd_buf_index = term_cmd_buf_size;
@@ -93,17 +96,17 @@ static void term_update(void)
delta = term_cmd_buf_index - term_last_cmd_buf_index;
if (delta > 0) {
for(i = 0;i < delta; i++) {
- term_printf("\033[C");
+ monitor_printf(mon, "\033[C");
}
} else {
delta = -delta;
for(i = 0;i < delta; i++) {
- term_printf("\033[D");
+ monitor_printf(mon, "\033[D");
}
}
term_last_cmd_buf_index = term_cmd_buf_index;
}
- term_flush();
+ monitor_flush(mon);
}
static void term_insert_char(int ch)
@@ -285,15 +288,21 @@ static void term_hist_add(const char *cmdline)
/* completion support */
-void add_completion(const char *str)
+void readline_add_completion(const char *str)
{
if (nb_completions < NB_COMPLETIONS_MAX) {
completions[nb_completions++] = qemu_strdup(str);
}
}
+void readline_set_completion_index(int index)
+{
+ completion_index = index;
+}
+
static void term_completion(void)
{
+ Monitor *mon = cur_mon;
int len, i, j, max_width, nb_cols, max_prefix;
char *cmdline;
@@ -317,7 +326,7 @@ static void term_completion(void)
if (len > 0 && completions[0][len - 1] != '/')
term_insert_char(' ');
} else {
- term_printf("\n");
+ monitor_printf(mon, "\n");
max_width = 0;
max_prefix = 0;
for(i = 0; i < nb_completions; i++) {
@@ -347,9 +356,9 @@ static void term_completion(void)
nb_cols = 80 / max_width;
j = 0;
for(i = 0; i < nb_completions; i++) {
- term_printf("%-*s", max_width, completions[i]);
+ monitor_printf(mon, "%-*s", max_width, completions[i]);
if (++j == nb_cols || i == (nb_completions - 1)) {
- term_printf("\n");
+ monitor_printf(mon, "\n");
j = 0;
}
}
@@ -360,6 +369,8 @@ static void term_completion(void)
/* return true if command handled */
void readline_handle_byte(int ch)
{
+ Monitor *mon = cur_mon;
+
switch(term_esc_state) {
case IS_NORM:
switch(ch) {
@@ -380,13 +391,13 @@ void readline_handle_byte(int ch)
term_cmd_buf[term_cmd_buf_size] = '\0';
if (!term_is_password)
term_hist_add(term_cmd_buf);
- term_printf("\n");
+ monitor_printf(mon, "\n");
term_cmd_buf_index = 0;
term_cmd_buf_size = 0;
term_last_cmd_buf_index = 0;
term_last_cmd_buf_size = 0;
/* NOTE: readline_start can be called here */
- term_readline_func(term_readline_opaque, term_cmd_buf);
+ term_readline_func(mon, term_cmd_buf, term_readline_opaque);
break;
case 23:
/* ^W */