Commit e244b800 authored by coffee's avatar coffee

Add Text input

Add HOME/END
parent 1b4d047e
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include <ctype.h>
#include <curses.h> #include <curses.h>
...@@ -24,6 +25,7 @@ ...@@ -24,6 +25,7 @@
/* CONSTANT LITERALS */ /* CONSTANT LITERALS */
/*********************************************************************/ /*********************************************************************/
#define HGT 23 #define HGT 23
#define WDT 80
/*********************************************************************/ /*********************************************************************/
/* FUNCTION DECLARATIONS */ /* FUNCTION DECLARATIONS */
...@@ -45,24 +47,40 @@ struct STATUS{ ...@@ -45,24 +47,40 @@ struct STATUS{
/*********************************************************************/ /*********************************************************************/
/* PANE_A100_DRAW */ /* PANE_A100_DRAW */
/*********************************************************************/ /*********************************************************************/
void draw(Screen *scr) { void draw(Screen *scr) {
size_t oldy, oldx;
getyx(stdscr, oldy, oldx); size_t oldy, oldx;
getyx(stdscr, oldy, oldx);
for (FNODE *node = scr->root ; node != NULL; node = node->next) { for (FNODE *node = scr->root ; node != NULL; node = node->next) {
Field* fld = node->field; Field* fld = node->field;
switch (fld->type) { switch (fld->type) {
case INP:
move(fld->y, fld->x); case INP:
attron(fld->attr);
addstr(fld->text); move(fld->y, fld->x);
for (int i = strlen(fld->text); i < fld->len; i++) addch(' ');
break; attron(fld->attr);
case LBL:
move(fld->y, fld->x); addstr(fld->text);
attron(fld->attr);
addstr(fld->text); for (int i = strlen(fld->text); i < fld->len; i++) addch(' ');
break;
break;
case LBL:
move(fld->y, fld->x);
attron(fld->attr);
addstr(fld->text);
break;
case BTN: case BTN:
move(0, fld->x); move(0, fld->x);
attron(TEXT(7)); attron(TEXT(7));
...@@ -75,16 +93,19 @@ void draw(Screen *scr) { ...@@ -75,16 +93,19 @@ void draw(Screen *scr) {
hline(NCURSES_ACS(*fld->text),fld->len); hline(NCURSES_ACS(*fld->text),fld->len);
break; break;
default: default:
break; break;
} }
standend(); standend();
} }
move(oldy, oldx); move(oldy, oldx);
} }
void init() { void init() {
initscr(); initscr();
noecho(); noecho();
cbreak(); cbreak();
keypad(stdscr, true); keypad(stdscr, true);
curs_set(1); curs_set(1);
...@@ -119,16 +140,63 @@ void draw_status() { ...@@ -119,16 +140,63 @@ void draw_status() {
} }
/*********************************************************************/ /*********************************************************************/
/* PANEL_X0100_QUERY_FLD_TREE */ /* PANEL_X0100_GET_FLD */
/*********************************************************************/ /*********************************************************************/
Field* PANEL_X0100_QUERY_FLD_TREE(Screen* scr, int y, int x) { Field* PANEL_X0100_GET_FLD(Screen* scr, int y, int x) {
for (Field *fd = scr->fstinp; fd != NULL; fd = fd->nxfld) {
if (fd->y == y && (x >= fd->x && x < fd->x + fd->len )) {
return fd;
}
}
return NULL; return NULL;
} /* PANEL_X0100_QUERY_FLD_TREE */ } /* PANEL_X0100_GET_FLD */
/*********************************************************************/
/* PANEL_X0200_PUTCHAR */
/*********************************************************************/
Field* PANEL_X0200_PUTCHAR(Screen* scr, int y, int x, char ch) {
Field *fd = PANEL_X0100_GET_FLD(scr, y, x);
if (fd) {
attron(fd->attr);
addch(ch);
standend();
if (x == fd->x + fd->len -1 ) {
if (fd->nxfld)
move(fd->nxfld->y, fd->nxfld->x);
else
move (y,x);
}
}
return fd;
} /* PANEL_X0200_PUTCHAR */
/*********************************************************************/
/* PANEL_X0300_GO_HOME */
/*********************************************************************/
void PANEL_X0300_GO_HOME(Screen* scr, int *y, int *x) {
Field *fd = PANEL_X0100_GET_FLD(scr, *y, *x);
if (fd) {
*y = fd->y;
*x = fd->x;
}
} /* PANEL_X0300_GO_HOME */
/*********************************************************************/
/* PANEL_X0400_GO_END */
/*********************************************************************/
void PANEL_X0400_GO_END(Screen* scr, int *y, int *x) {
Field *fd = PANEL_X0100_GET_FLD(scr, *y, *x);
if (fd) {
*y = fd->y;
*x = fd->x + fd->len -1;
}
} /* PANEL_X0400_GO_END */
/*********************************************************************/ /*********************************************************************/
/* PANEL_X0200_BUILD_SCREEN */ /* PANEL_X0300_BUILD_SCREEN */
/*********************************************************************/ /*********************************************************************/
Screen* buildScreen(Field *fields) { Screen* buildScreen(Field *fields) {
Screen* scr; Screen* scr;
...@@ -152,9 +220,23 @@ Screen* buildScreen(Field *fields) { ...@@ -152,9 +220,23 @@ Screen* buildScreen(Field *fields) {
return scr; return scr;
} /* PANEL_X0200_BUILD_SCREEN */ } /* PANEL_X0200_BUILD_SCREEN */
/*********************************************************************/
/* PANEL_U0100_GET_FIELD_TEXT */
/*********************************************************************/
char* PANEL_U0100_GET_FIELD_TEXT(Field *fld) {
char *buf = malloc(WDT + 1);
int x, y;
getyx(stdscr,y, x);
mvinstr(fld->y, fld->x, buf);
move(y,x);
return buf;
} /* PANEL_U0100_GET_FIELD_TEXT */
int start(Screen *scr) {
init();
int start(Screen *scr) {
init();
draw(scr); draw(scr);
int x, y; int x, y;
...@@ -169,48 +251,83 @@ int start(Screen *scr) { ...@@ -169,48 +251,83 @@ int start(Screen *scr) {
int ch = getch(); int ch = getch();
switch (ch) { switch (ch) {
case KEY_LEFT:
if (x > 0) case KEY_LEFT:
x--;
break; if (x > 0)
case KEY_RIGHT:
if (x < 79) x--;
x++;
break; break;
case KEY_UP:
if (y > 0) case KEY_RIGHT:
y--;
break; if (x < 79)
case KEY_DOWN:
if (y < HGT - 1) x++;
y++;
break; break;
case KEY_HOME:
case KEY_STAB: case KEY_UP:
case KEY_BTAB:
case KEY_END: if (y > 0)
y--;
break;
case KEY_DOWN:
if (y < HGT - 1)
y++;
break;
case KEY_HOME:
PANEL_X0300_GO_HOME(scr, &y, &x);
break;
case KEY_END:
PANEL_X0400_GO_END(scr, &y, &x);
break;
case KEY_STAB:
case KEY_BTAB:
break;
case 10: case 10:
case KEY_ENTER: case KEY_ENTER:
status.inhibit = "X - SYSTEM"; status.inhibit = "X - SYSTEM";
draw_status(); draw_status();
scr = scr->submit(scr); scr = scr->submit(scr);
if(!scr)
goto exit;
status.inhibit = " "; status.inhibit = " ";
draw_status(); draw_status();
break; break;
default: default:
break; if (isprint(ch)) {
if(PANEL_X0200_PUTCHAR(scr, y, x, ch)){
getyx(stdscr,y, x);
goto redraw;}
}
break;
} }
addch(chr); addch(chr);
redraw:
chr = mvinch(y,x); // save attr chr = mvinch(y,x); // save attr
attr = chr & A_ATTRIBUTES; attr = chr & A_ATTRIBUTES;
chgat(1, A_REVERSE | attr, 0, NULL); chgat(1, A_REVERSE | attr, 0, NULL);
draw_status(); draw_status();
} }
cleanup: exit:
endwin(); endwin();
return 0; return 0;
} }
...@@ -73,7 +73,7 @@ typedef struct Field { ...@@ -73,7 +73,7 @@ typedef struct Field {
, len; , len;
char* text; char* text;
chtype attr; chtype attr;
short nxfld; struct Field *nxfld;
void* (*callback)(char*); void* (*callback)(char*);
} Field; } Field;
...@@ -98,5 +98,7 @@ typedef struct Screen { ...@@ -98,5 +98,7 @@ typedef struct Screen {
/*********************************************************************/ /*********************************************************************/
extern void init(); extern void init();
extern int start(Screen* scr); extern int start(Screen* scr);
Field* PANEL_X0100_GET_FLD(Screen* scr, int y, int x);
extern char* PANEL_U0100_GET_FIELD_TEXT(Field *fld);
extern Screen* buildScreen(Field *fields); extern Screen* buildScreen(Field *fields);
#endif #endif
...@@ -19,7 +19,11 @@ INP src/pane.h /^#define INP /;" d ...@@ -19,7 +19,11 @@ INP src/pane.h /^#define INP /;" d
INPT src/pane.h /^#define INPT /;" d INPT src/pane.h /^#define INPT /;" d
LBL src/pane.h /^#define LBL /;" d LBL src/pane.h /^#define LBL /;" d
OBJ Makefile /^OBJ = $(addprefix obj\/,$(notdir $(SRC:.c=.o)))$/;" m OBJ Makefile /^OBJ = $(addprefix obj\/,$(notdir $(SRC:.c=.o)))$/;" m
PANEL_X0100_QUERY_FLD_TREE src/pane.c /^Field* PANEL_X0100_QUERY_FLD_TREE(Screen* scr, int y, int x) {$/;" f typeref:typename:Field * PANEL_U0100_GET_FIELD_TEXT src/pane.c /^char* PANEL_U0100_GET_FIELD_TEXT(Field *fld) {$/;" f typeref:typename:char *
PANEL_X0100_GET_FLD src/pane.c /^Field* PANEL_X0100_GET_FLD(Screen* scr, int y, int x) {$/;" f typeref:typename:Field *
PANEL_X0200_PUTCHAR src/pane.c /^Field* PANEL_X0200_PUTCHAR(Screen* scr, int y, int x, char ch) {$/;" f typeref:typename:Field *
PANEL_X0300_GO_HOME src/pane.c /^void PANEL_X0300_GO_HOME(Screen* scr, int *y, int *x) {$/;" f typeref:typename:void
PANEL_X0400_GO_END src/pane.c /^void PANEL_X0400_GO_END(Screen* scr, int *y, int *x) {$/;" f typeref:typename:void
PANE_H src/pane.h /^#define PANE_H$/;" d PANE_H src/pane.h /^#define PANE_H$/;" d
PROJECT Makefile /^PROJECT = icpl$/;" m PROJECT Makefile /^PROJECT = icpl$/;" m
RLR src/pane.h /^#define RLR /;" d RLR src/pane.h /^#define RLR /;" d
...@@ -28,6 +32,7 @@ STATUS src/pane.c /^struct STATUS{$/;" s file: ...@@ -28,6 +32,7 @@ STATUS src/pane.c /^struct STATUS{$/;" s file:
Screen src/pane.h /^typedef struct Screen {$/;" s Screen src/pane.h /^typedef struct Screen {$/;" s
Screen src/pane.h /^}Screen;$/;" t typeref:struct:Screen Screen src/pane.h /^}Screen;$/;" t typeref:struct:Screen
TEXT src/pane.h /^#define TEXT(/;" d TEXT src/pane.h /^#define TEXT(/;" d
WDT src/pane.c /^#define WDT /;" d file:
attr src/pane.h /^ chtype attr;$/;" m struct:Field typeref:typename:chtype attr src/pane.h /^ chtype attr;$/;" m struct:Field typeref:typename:chtype
buildScreen src/pane.c /^Screen* buildScreen(Field *fields) {$/;" f typeref:typename:Screen * buildScreen src/pane.c /^Screen* buildScreen(Field *fields) {$/;" f typeref:typename:Screen *
byte src/pane.h /^typedef unsigned char byte;$/;" t typeref:typename:unsigned char byte src/pane.h /^typedef unsigned char byte;$/;" t typeref:typename:unsigned char
...@@ -45,7 +50,7 @@ init src/pane.c /^void init() {$/;" f typeref:typename:void ...@@ -45,7 +50,7 @@ init src/pane.c /^void init() {$/;" f typeref:typename:void
isInsert src/pane.c /^ bool isInsert;$/;" m struct:STATUS typeref:typename:bool file: isInsert src/pane.c /^ bool isInsert;$/;" m struct:STATUS typeref:typename:bool file:
len src/pane.h /^ , len;$/;" m struct:Field typeref:typename:size_t len src/pane.h /^ , len;$/;" m struct:Field typeref:typename:size_t
next src/pane.h /^ struct FNODE *next;$/;" m struct:FNODE typeref:struct:FNODE * next src/pane.h /^ struct FNODE *next;$/;" m struct:FNODE typeref:struct:FNODE *
nxfld src/pane.h /^ short nxfld;$/;" m struct:Field typeref:typename:short nxfld src/pane.h /^ struct Field *nxfld;$/;" m struct:Field typeref:struct:Field *
obj/ Makefile /^obj\/:$/;" t obj/ Makefile /^obj\/:$/;" t
obj/%.o Makefile /^obj\/%.o : %.c $(HEADERS) | obj\/$/;" t obj/%.o Makefile /^obj\/%.o : %.c $(HEADERS) | obj\/$/;" t
obj/%.o Makefile /^obj\/%.o : %.c %.h $(HEADERS) | obj\/$/;" t obj/%.o Makefile /^obj\/%.o : %.c %.h $(HEADERS) | obj\/$/;" t
......
...@@ -40,6 +40,8 @@ ...@@ -40,6 +40,8 @@
/*********************************************************************/ /*********************************************************************/
#include "../../icpl/src/pane.h" #include "../../icpl/src/pane.h"
#include <stdbool.h> /* STDLIB BOOLEANS TYPE */ #include <stdbool.h> /* STDLIB BOOLEANS TYPE */
#include <string.h> /* STDLIB STRING FUNCTIONS */
#include <ctype.h> /* STDLIB TYPE UTILITY */
/*********************************************************************/ /*********************************************************************/
/* PREPROCESSOR DEFS */ /* PREPROCESSOR DEFS */
...@@ -51,6 +53,7 @@ ...@@ -51,6 +53,7 @@
#define TXTOPT "Option ===>" #define TXTOPT "Option ===>"
#define TXTCMD "Command ===>" #define TXTCMD "Command ===>"
#define TXTHDR "ISPF Primary Option Menu" #define TXTHDR "ISPF Primary Option Menu"
#define TXTQIT "Option X to terminate"
enum FLDNUM { enum FLDNUM {
BTN0, BTN0,
...@@ -67,8 +70,8 @@ enum FLDNUM { ...@@ -67,8 +70,8 @@ enum FLDNUM {
/* FUNCTION DECLARATIONS */ /* FUNCTION DECLARATIONS */
/*********************************************************************/ /*********************************************************************/
Screen* MAIN_A100_SUBMIT (Screen*); Screen* MAIN_A100_SUBMIT (Screen*);
void MAIN_B130_GET_NEXT_SCREEN (); void MAIN_B130_GET_NEXT_SCREEN (Screen*);
void MAIN_B120_VALIDATE_MENU (); void MAIN_B120_DO_MENU_ACTION ();
/*********************************************************************/ /*********************************************************************/
/* LOCAL DECLARATIONS */ /* LOCAL DECLARATIONS */
...@@ -84,12 +87,13 @@ Field MENUFLDS[] = { /* ISPF PRIMARY OPTION MENU */ ...@@ -84,12 +87,13 @@ Field MENUFLDS[] = { /* ISPF PRIMARY OPTION MENU */
[BTN5] = { BTN , 0, 48, 0,"Help" , A_NORMAL , }, [BTN5] = { BTN , 0, 48, 0,"Help" , A_NORMAL , },
/************************* INPUTS ***************************/ /************************* INPUTS ***************************/
[INP0] = { INP , 3, 13, 66, "" , INPT , NULL}, [INP0] = { INP , 3, 13, 66, "" , INPT , },
/************************* LABELS ***************************/ /************************* LABELS ***************************/
[OUT0] = { LBL , 3, 1, 0, "" , TEXT(2) , }, [OUT0] = { LBL , 3, 1, 0, "" , TEXT(2) , },
/*AUTO*/ { LBL , 2, 28, 0,TXTHDR , TEXT(4) , }, /*AUTO*/ { LBL , 2, 28, 0,TXTHDR , TEXT(4) , },
/*AUTO*/ { LBL , 3, 1, 0,TXTOPT , TEXT(2) , }, /*AUTO*/ { LBL , 3, 1, 0,TXTOPT , TEXT(2) , },
/*AUTO*/ { LBL , 20, 10, 0,TXTQIT , TEXT(7) , },
/************************* RULERS ***************************/ /************************* RULERS ***************************/
/*AUTO*/ { RLR, 1, 1, 78, "q" , TEXT(4) , }, /*AUTO*/ { RLR, 1, 1, 78, "q" , TEXT(4) , },
...@@ -100,6 +104,7 @@ Field MENUFLDS[] = { /* ISPF PRIMARY OPTION MENU */ ...@@ -100,6 +104,7 @@ Field MENUFLDS[] = { /* ISPF PRIMARY OPTION MENU */
/* WK_STORAGE */ /* WK_STORAGE */
/*********************************************************************/ /*********************************************************************/
bool WK_IS_VALID; bool WK_IS_VALID;
Screen *WK_SCREEN;
/*********************************************************************/ /*********************************************************************/
...@@ -128,36 +133,45 @@ int MAIN_A000_INIT() { ...@@ -128,36 +133,45 @@ int MAIN_A000_INIT() {
/* MAIN_A100_SUBMIT */ /* MAIN_A100_SUBMIT */
/*********************************************************************/ /*********************************************************************/
Screen* MAIN_A100_SUBMIT (Screen* self) { Screen* MAIN_A100_SUBMIT (Screen* self) {
WK_SCREEN = self;
int y, x; int y, x;
getyx(stdscr, y, x); getyx(stdscr, y, x);
MAIN_B120_VALIDATE_MENU(); Field *WK_CUR_FIELD = PANEL_X0100_GET_FLD(self,y,x);
if (WK_IS_VALID) {
MAIN_B130_GET_NEXT_SCREEN(); if (WK_CUR_FIELD->type == BTN)
} MAIN_B120_DO_MENU_ACTION();
else { else
} MAIN_B130_GET_NEXT_SCREEN(self);
return self; return WK_SCREEN;
} /* MAIN_A100_SUBMIT */ } /* MAIN_A100_SUBMIT */
/*********************************************************************/ /*********************************************************************/
/* MAIN_B120_VALIDATE_MENU */ /* MAIN_B120_DO_MENU_ACTION */
/*********************************************************************/ /*********************************************************************/
void MAIN_B120_VALIDATE_MENU (){ void MAIN_B120_DO_MENU_ACTION() {
addch('*');
return; return;
} /* MAIN_B120_VALIDATE_MENU */ } /* MAIN_B120_DO_MENU_ACTION */
/*********************************************************************/ /*********************************************************************/
/* MAIN_B130_GET_NEXT_SCREEN */ /* MAIN_B130_GET_NEXT_SCREEN */
/*********************************************************************/ /*********************************************************************/
void MAIN_B130_GET_NEXT_SCREEN (){ void MAIN_B130_GET_NEXT_SCREEN (Screen *self){
char* text = PANEL_U0100_GET_FIELD_TEXT(self->fstinp);
for (int i = 0; i < strlen(text); ++i) {
text[i] = toupper(text[i]);
}
char* token = strtok(text, " ");
if (strcmp(token,"X") == 0)
WK_SCREEN = NULL;
// ADD OTHER OPTIONS HERE
return; return;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment