aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c99
1 files changed, 44 insertions, 55 deletions
diff --git a/src/main.c b/src/main.c
index 2b9db34..d15a7be 100644
--- a/src/main.c
+++ b/src/main.c
@@ -15,9 +15,11 @@
#include <string.h>
#include <ctype.h>
#include <conio.h> // for kbhit() and cgetc()
-#include "conio.h" // our local one.
+// #include "conio.h" // our local one.
#include "nio.h"
#include "irc.h"
+#include "screen.h"
+#include "edbox.h"
char url[256] = DEF_URL; // URL
char usernick[32] = DEF_NICK;
@@ -31,6 +33,7 @@ unsigned char rx_buf[MAX_IRC_MSG_LEN]; // RX buffer.
unsigned char tx_buf[MAX_IRC_MSG_LEN]; // TX buffer.
unsigned int txbuflen; // TX buffer length
char channel[32] = DEF_CHANNEL;
+static char got_line;
/* TODO: user modes (default +iw), fg/bg color... */
@@ -43,58 +46,43 @@ static void strcpy_to_eol(char *dst, const char *src) {
*dst = '\0';
}
-/**
- * Get URL from user.
- */
-void get_config(void) {
- OS.crsinh = 0;
+static void return_pressed(void) {
+ got_line = 1;
+}
- putchar(CH_CLR);
- print(BANNER);
+static void get_line(void) {
+ got_line = 0;
+ edbox_callback = return_pressed;
+ while(!got_line)
+ edbox_keystroke();
+ scr_print(SCR_SERVER, edit_box);
+}
+
+void get_config(void) {
+ scr_print(SCR_SERVER, BANNER);
while(1) {
- print("\nURL [");
- print(url);
- print("]?\n");
- get_line(tx_buf, sizeof(url) - 1);
- if(tx_buf[0] != CH_EOL) strcpy_to_eol(url, tx_buf);
-
- print("Nick [");
- print(usernick);
- print("]? ");
- get_line(tx_buf, sizeof(usernick) - 1);
- if(tx_buf[0] != CH_EOL) strcpy_to_eol(usernick, tx_buf);
-
- print("Channel [");
- print(channel);
- print("]? ");
- get_line(tx_buf, sizeof(channel) - 1);
- if(tx_buf[0] != CH_EOL) strcpy_to_eol(channel, tx_buf);
-
- /*
- print("\n\nURL: ");
- print(url);
- print("\nNick: ");
- print(usernick);
- print("\nChannel: ");
- print(channel);
- */
-
- print("\n\nAre these settings OK [Y/n]? ");
+ scr_print(SCR_SERVER, "\nURL [");
+ scr_print(SCR_SERVER, url);
+ scr_print(SCR_SERVER, "]?\n");
+ get_line();
+ if(edit_box[0] != CH_EOL) strcpy_to_eol(url, edit_box);
+
+ scr_print(SCR_SERVER, "Nick [");
+ scr_print(SCR_SERVER, usernick);
+ scr_print(SCR_SERVER, "]?\n");
+ get_line();
+ if(edit_box[0] != CH_EOL) strcpy_to_eol(usernick, edit_box);
+
+ scr_print(SCR_SERVER, "Channel [");
+ scr_print(SCR_SERVER, channel);
+ scr_print(SCR_SERVER, "]?\n");
+ get_line();
+ if(edit_box[0] != CH_EOL) strcpy_to_eol(channel, edit_box);
+
+ scr_print(SCR_SERVER, "\n\nAre these settings OK [Y/n]?\n");
if(tolower(cgetc()) != 'n') break;
}
-
- // print("Press Return to connect\n");
- // cgetc();
-}
-
-/**
- * Print error
- */
-void print_error(unsigned char err) {
- itoa(err, tmp, 10);
- print(tmp);
- print("\n");
}
void txbuf_init(void) {
@@ -125,15 +113,15 @@ void txbuf_send_str(const char *str) {
}
int fn_connect(void) {
- print("\n" "Connecting to: ");
- print(url);
- print("\n");
+ scr_print(SCR_SERVER, "Connecting to: ");
+ scr_print(SCR_SERVER, url);
+ scr_print(SCR_SERVER, "\n");
err = nopen(url, FNET_TRANSLATION);
if(err != SUCCESS) {
- print("Connection failed: ");
- print_error(err);
+ scr_print(SCR_SERVER, "Connection failed: ");
+ print_errnum();
return 0;
}
@@ -155,13 +143,14 @@ void fn_disconnect(void) {
}
int main(void) {
- OS.lmargn = 0; // Set left margin to 0
OS.shflok = 0; // turn off shift-lock.
OS.soundr = 0; // Turn off SIO beeping sound
- cursor(1); // Keep cursor on
+
+ scr_init();
while(1) {
get_config();
+ edbox_callback = cmd_execute;
if(fn_connect()) {
irc_register();
irc_loop();