aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorprofkhaos <profkhaos@Khaos-Phantom.(none)>2009-08-15 14:42:30 +0300
committerprofkhaos <profkhaos@Khaos-Phantom.(none)>2009-08-15 14:42:30 +0300
commitffa9c1e37afc2a805b5ad2d314bcde9eb1886919 (patch)
treeafdecbb98705ab2dcb038c5a3375cc16a20f1ab4
parent914b55ed4a1ad94a55f7136e7719d22b4d7ecbea (diff)
parent4672b07a84060fa42e8034d99a4900849787128a (diff)
downloadsyslinux-ffa9c1e37afc2a805b5ad2d314bcde9eb1886919.tar.gz
syslinux-ffa9c1e37afc2a805b5ad2d314bcde9eb1886919.tar.xz
syslinux-ffa9c1e37afc2a805b5ad2d314bcde9eb1886919.zip
Merge commit 'for-klausm/klausm' into elflink
Conflicts: core/elflink/cli.c
-rw-r--r--com32/elflink/modules/ansiraw.c1
-rw-r--r--com32/elflink/modules/cli.h4
-rw-r--r--com32/elflink/modules/menumain.c10
-rw-r--r--com32/elflink/modules/mytest.c3
-rw-r--r--com32/include/stdio.h2
-rw-r--r--com32/lib/sys/ansi.c63
-rw-r--r--com32/lib/sys/ansi.h28
-rw-r--r--com32/menu/menumain.c2
-rw-r--r--core/elflink/cli.c118
-rw-r--r--core/elflink/cli.h3
-rw-r--r--core/elflink/load_env32.c6
11 files changed, 167 insertions, 73 deletions
diff --git a/com32/elflink/modules/ansiraw.c b/com32/elflink/modules/ansiraw.c
index b50b47f0..d37922f5 100644
--- a/com32/elflink/modules/ansiraw.c
+++ b/com32/elflink/modules/ansiraw.c
@@ -47,7 +47,6 @@ static int ansiraw_init()
void console_ansi_raw(void)
{
openconsole(&dev_rawcon_r, &dev_ansiserial_w);
- printf("hmmm 2\n");
}
static void ansiraw_exit()
diff --git a/com32/elflink/modules/cli.h b/com32/elflink/modules/cli.h
index 6c5815d0..8674cfc6 100644
--- a/com32/elflink/modules/cli.h
+++ b/com32/elflink/modules/cli.h
@@ -1,6 +1,8 @@
#ifndef CLI_H
#define CLI_H
-extern const char *edit_cmdline(const char *input, int top);
+extern void clear_screen(void);
+extern int mygetkey(clock_t timeout);
+extern const char *edit_cmdline(const char *input, int top /*, int width */,int (*pDraw_Menu)(int, int, int),void (*show_fkey)(int));
#endif
diff --git a/com32/elflink/modules/menumain.c b/com32/elflink/modules/menumain.c
index 30cd2d07..d3b779af 100644
--- a/com32/elflink/modules/menumain.c
+++ b/com32/elflink/modules/menumain.c
@@ -285,7 +285,7 @@ static int ask_passwd(const char *menu_entry)
return rv;
}
-static void draw_menu(int sel, int top, int edit_line)
+static int draw_menu(int sel, int top, int edit_line)
{
int x, y;
int sbtop = 0, sbbot = 0;
@@ -331,11 +331,7 @@ static void draw_menu(int sel, int top, int edit_line)
printf("\1#8\033[%d;%dH%s",
TABMSG_ROW, 1 + HSHIFT + ((WIDTH - tabmsg_len) >> 1), tabmsg);
printf("\1#0\033[%d;1H", END_ROW);
-}
-
-static void clear_screen(void)
-{
- fputs("\033e\033%@\033)0\033(B\1#0\033[?25l\033[2J", stdout);
+ return 0;
}
static void display_help(const char *text)
@@ -852,7 +848,7 @@ static const char *run_menu(void)
}
if (ok) {
- cmdline = edit_cmdline(me->cmdline, top);
+ cmdline = edit_cmdline(me->cmdline, top,&draw_menu,&show_fkey);
done = !!cmdline;
clear = 1; /* In case we hit [Esc] and done is null */
} else {
diff --git a/com32/elflink/modules/mytest.c b/com32/elflink/modules/mytest.c
index 309a90ca..7ebf0a5f 100644
--- a/com32/elflink/modules/mytest.c
+++ b/com32/elflink/modules/mytest.c
@@ -21,8 +21,7 @@
static int mytest_main(int argc, char **argv)
{
console_ansi_raw();
- printf("hmmm\n");
- edit_cmdline("hello",1);
+ //edit_cmdline("",1);
menu_main(argc, argv);
return 0;
}
diff --git a/com32/include/stdio.h b/com32/include/stdio.h
index 1f3dc0e9..f37bdd9e 100644
--- a/com32/include/stdio.h
+++ b/com32/include/stdio.h
@@ -61,7 +61,7 @@ __extern int fputs(const char *, FILE *);
__extern int puts(const char *);
__extern int fputc(int, FILE *);
#define putc(c,f) fputc((c),(f))
-//#define putchar(c) fputc((c),stdout)
+#define putchar(c) fputc((c),stdout)
__extern int fgetc(FILE *);
__extern char *fgets(char *, int, FILE *);
diff --git a/com32/lib/sys/ansi.c b/com32/lib/sys/ansi.c
index 7d580856..f73c03e2 100644
--- a/com32/lib/sys/ansi.c
+++ b/com32/lib/sys/ansi.c
@@ -36,21 +36,22 @@
#include "ansi.h"
static const struct term_state default_state = {
+ .state = st_init,
+ .pvt = false,
+ .nparms = 0,
.xy = {0, 0},
.cindex = 0, /* First color table entry */
- .vtgraphics = 0,
+ .vtgraphics = false,
.intensity = 1,
- .underline = 0,
- .blink = 0,
- .reverse = 0,
+ .underline = false,
+ .blink = false,
+ .reverse = false,
.fg = 7,
.bg = 0,
- .autocr = 1, /* Mimic \n -> \r\n conversion by default */
+ .autocr = true, /* Mimic \n -> \r\n conversion by default */
+ .autowrap = true, /* Wrap lines by default */
.saved_xy = {0, 0},
- .cursor = 1,
- .state = st_init,
- .pvt = 0,
- .nparms = 0,
+ .cursor = true,
};
/* DEC VT graphics to codepage 437 table (characters 0x60-0x7F only) */
@@ -141,7 +142,8 @@ void __ansi_putchar(const struct term_info *ti, uint8_t ch)
break;
case '[':
st->state = st_csi;
- st->nparms = st->pvt = 0;
+ st->nparms = 0;
+ st->pvt = false;
memset(st->parms, 0, sizeof st->parms);
break;
case 'c':
@@ -170,7 +172,7 @@ void __ansi_putchar(const struct term_info *ti, uint8_t ch)
st->nparms = ANSI_MAX_PARMS - 1;
break;
} else if (ch == '?') {
- st->pvt = 1;
+ st->pvt = true;
} else {
switch (ch) {
case 'A':
@@ -278,22 +280,25 @@ void __ansi_putchar(const struct term_info *ti, uint8_t ch)
break;
case 'h':
case 'l':
- {
- int set = (ch == 'h');
- switch (st->parms[0]) {
- case 20:
- st->autocr = set;
- break;
- case 25:
- st->cursor = set;
- op->showcursor(st);
- break;
- default:
- /* Ignore */
- break;
- }
+ {
+ bool set = (ch == 'h');
+ switch (st->parms[0]) {
+ case 7: /* DECAWM */
+ st->autowrap = set;
+ break;
+ case 20: /* LNM */
+ st->autocr = set;
+ break;
+ case 25: /* DECTECM */
+ st->cursor = set;
+ op->showcursor(st);
+ break;
+ default:
+ /* Ignore */
+ break;
}
break;
+ }
case 'm':
{
static const int ansi2pc[8] =
@@ -421,8 +426,12 @@ void __ansi_putchar(const struct term_info *ti, uint8_t ch)
/* If we fell off the end of the screen, adjust */
if (xy.x >= cols) {
- xy.x = 0;
- xy.y++;
+ if (st->autowrap) {
+ xy.x = 0;
+ xy.y++;
+ } else {
+ xy.x = cols - 1;
+ }
}
while (xy.y >= rows) {
xy.y--;
diff --git a/com32/lib/sys/ansi.h b/com32/lib/sys/ansi.h
index 0d1f1025..40a531cc 100644
--- a/com32/lib/sys/ansi.h
+++ b/com32/lib/sys/ansi.h
@@ -6,6 +6,7 @@
#define COM32_LIB_SYS_ANSI_H
#include <inttypes.h>
+#include <stdbool.h>
#define ANSI_MAX_PARMS 16
@@ -22,22 +23,23 @@ struct curxy {
} __attribute__ ((packed));
struct term_state {
- struct curxy xy;
- int cindex; /* SOH color index */
- int vtgraphics; /* VT graphics on/off */
- int intensity;
- int underline;
- int blink;
- int reverse;
- int fg;
- int bg;
- int autocr;
- struct curxy saved_xy;
- int cursor;
enum ansi_state state;
- int pvt; /* Private code? */
int nparms; /* Number of parameters seen */
int parms[ANSI_MAX_PARMS];
+ bool pvt; /* Private code? */
+ struct curxy xy;
+ struct curxy saved_xy;
+ uint8_t cindex; /* SOH color index */
+ uint8_t fg;
+ uint8_t bg;
+ uint8_t intensity;
+ bool vtgraphics; /* VT graphics on/off */
+ bool underline;
+ bool blink;
+ bool reverse;
+ bool autocr;
+ bool autowrap;
+ bool cursor;
};
struct ansi_ops {
diff --git a/com32/menu/menumain.c b/com32/menu/menumain.c
index f74e224f..3af630f8 100644
--- a/com32/menu/menumain.c
+++ b/com32/menu/menumain.c
@@ -527,7 +527,7 @@ const char *edit_cmdline(const char *input, int top)
memmove(cmdline + cursor, cmdline + prevcursor,
len - prevcursor + 1);
- len -= (cursor - prevcursor);
+ len -= (prevcursor - cursor);
redraw = 1;
}
break;
diff --git a/core/elflink/cli.c b/core/elflink/cli.c
index 182dc6d0..0fba61cc 100644
--- a/core/elflink/cli.c
+++ b/core/elflink/cli.c
@@ -15,6 +15,11 @@
#include "menu.h"
#include "cli.h"
+void clear_screen(void)
+{
+ fputs("\033e\033%@\033)0\033(B\1#0\033[?25l\033[2J", stdout);
+}
+
int mygetkey(clock_t timeout)
{
clock_t t0, t;
@@ -49,34 +54,82 @@ int mygetkey(clock_t timeout)
}
}
-const char *edit_cmdline(const char *input, int top)
+const char *edit_cmdline(const char *input, int top /*, int width */,int (*pDraw_Menu)(int, int, int),void (*show_fkey)(int))
{
static char cmdline[MAX_CMDLINE_LEN];
int key, len, prev_len, cursor;
int redraw = 1; /* We enter with the menu already drawn */
+ int x, y;
+ bool done = false;
+ const char *ret;
+
+ int width = 0;
+
+ if (!width) {
+ int height;
+ if (getscreensize(1, &height, &width))
+ width = 80;
+ }
+
+ printf("width = %d\n", width);
strncpy(cmdline, input, MAX_CMDLINE_LEN);
cmdline[MAX_CMDLINE_LEN - 1] = '\0';
len = cursor = strlen(cmdline);
prev_len = 0;
+ x = y = 0;
- for (;;) {
- if (redraw > 1) {
+ while (!done) {
+ if (redraw > 1 && pDraw_Menu!=NULL) {
/* Clear and redraw whole screen */
/* Enable ASCII on G0 and DEC VT on G1; do it in this order
to avoid confusing the Linux console */
/* clear_screen();
draw_menu(-1, top, 1);
prev_len = 0;*/
+ clear_screen();
+ (*pDraw_Menu)(-1, top, 1);
+ prev_len = 0;
+ // printf("\033[0m\033[2J\033[H");
}
if (redraw > 0) {
+ int dy, at;
+
+ prev_len = max(len, prev_len);
+
/* Redraw the command line */
- printf("\033[?25l\033[%d;1H\1#9> \2#10%s",
- CMDLINE_ROW, pad_line(cmdline, 0, max(len, prev_len)));
- printf("\2#10\033[%d;3H%s\033[?25h",
- CMDLINE_ROW, pad_line(cmdline, 0, cursor));
+ printf("\033[?7l\033[?25l");
+ if (y)
+ printf("\033[%dA", y);
+ printf("\033[1G\033[1;36m> \033[0m");
+
+ x = 2;
+ y = 0;
+ at = 0;
+ while (at < prev_len) {
+ putchar(at >= len ? ' ' : cmdline[at]);
+ at++;
+ x++;
+ if (x >= width) {
+ printf("\r\n");
+ x = 0;
+ y++;
+ }
+ }
+ printf("\033[K\r");
+
+ dy = y - (cursor+2) / width;
+ x = (cursor+2) % width;
+
+ if (dy) {
+ printf("\033[%dA", dy);
+ y -= dy;
+ }
+ if (x)
+ printf("\033[%dC", x);
+ printf("\033[?25h");
prev_len = len;
redraw = 0;
}
@@ -90,11 +143,15 @@ const char *edit_cmdline(const char *input, int top)
case KEY_ENTER:
case KEY_CTRL('J'):
- return cmdline;
+ ret = cmdline;
+ done = true;
+ break;
case KEY_ESC:
case KEY_CTRL('C'):
- return NULL;
+ ret = NULL;
+ done = true;
+ break;
case KEY_BACKSPACE:
case KEY_DEL:
@@ -134,9 +191,19 @@ const char *edit_cmdline(const char *input, int top)
while (cursor && !my_isspace(cmdline[cursor - 1]))
cursor--;
+#if 0
memmove(cmdline + cursor, cmdline + prevcursor,
len - prevcursor + 1);
- len -= (cursor - prevcursor);
+#else
+ {
+ int i;
+ char *q = cmdline + cursor;
+ char *p = cmdline + prevcursor;
+ for (i = 0; i < len - prevcursor + 1; i++)
+ *q++ = *p++;
+ }
+#endif
+ len -= (prevcursor - cursor);
redraw = 1;
}
break;
@@ -152,7 +219,14 @@ const char *edit_cmdline(const char *input, int top)
case KEY_RIGHT:
case KEY_CTRL('F'):
if (cursor < len) {
- putchar(cmdline[cursor++]);
+ putchar(cmdline[cursor]);
+ cursor++;
+ x++;
+ if (x >= width) {
+ printf("\r\n");
+ y++;
+ x = 0;
+ }
}
break;
@@ -191,17 +265,26 @@ const char *edit_cmdline(const char *input, int top)
case KEY_F10:
case KEY_F11:
case KEY_F12:
- //show_fkey(key);
- redraw = 1;
+ if(show_fkey!=NULL)
+ {
+ (*show_fkey)(key);
+ redraw = 1;
+ }
break;
default:
if (key >= ' ' && key <= 0xFF && len < MAX_CMDLINE_LEN - 1) {
if (cursor == len) {
- cmdline[len] = key;
- cmdline[++len] = '\0';
- cursor++;
+ cmdline[len++] = key;
+ cmdline[len] = '\0';
putchar(key);
+ cursor++;
+ x++;
+ if (x >= width) {
+ printf("\r\n\033[K");
+ y++;
+ x = 0;
+ }
prev_len++;
} else {
memmove(cmdline + cursor + 1, cmdline + cursor,
@@ -214,5 +297,8 @@ const char *edit_cmdline(const char *input, int top)
break;
}
}
+
+ printf("\033[?7h");
+ return ret;
}
diff --git a/core/elflink/cli.h b/core/elflink/cli.h
index de27ed4b..8674cfc6 100644
--- a/core/elflink/cli.h
+++ b/core/elflink/cli.h
@@ -1,7 +1,8 @@
#ifndef CLI_H
#define CLI_H
+extern void clear_screen(void);
extern int mygetkey(clock_t timeout);
-extern const char *edit_cmdline(const char *input, int top);
+extern const char *edit_cmdline(const char *input, int top /*, int width */,int (*pDraw_Menu)(int, int, int),void (*show_fkey)(int));
#endif
diff --git a/core/elflink/load_env32.c b/core/elflink/load_env32.c
index 5211d131..38af23f9 100644
--- a/core/elflink/load_env32.c
+++ b/core/elflink/load_env32.c
@@ -71,7 +71,6 @@ void load_env32(com32sys_t * regs)
{
call_constr();
char *cmdline;
- //openconsole(&dev_stdcon_r, &dev_stdcon_w);
openconsole(&dev_rawcon_r, &dev_ansiserial_w);
printf("Calling initilization constructor procedures...\n");
printf("Starting 32 bit elf module subsystem...\n");
@@ -82,8 +81,9 @@ void load_env32(com32sys_t * regs)
printf("Str table size: %d\n",core_module.strtable_size);
printf("Sym table size: %d\n",core_module.symtable_size);
- cmdline=edit_cmdline("hello",1);
- //printf("%s\n",cmdline);
+ cmdline=edit_cmdline("",1,NULL,NULL);
+ printf("\n%s\n",cmdline);
+
//fgets(cmdline,100,stdin);
int i,n=5;