#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include "ftp.h"
#include "util.h"
+#ifdef __unix__
+#include <unistd.h>
+#define closesocket(s) close(s)
+#endif
+
struct ftp *ftp_alloc(void)
{
struct ftp *ftp;
return -1;
}
+ memset(&addr, 0, sizeof addr);
addr.sin_family = AF_INET;
- addr.sin_addr.s_addr = inet_addr(host->h_addr);
+ addr.sin_addr = *((struct in_addr*)host->h_addr);
addr.sin_port = htons(port);
if(connect(ftp->ctl, (struct sockaddr*)&addr, sizeof addr) == -1) {
ftp->ctl = -1;
return -1;
}
-
return 0;
}
init_input();
+ tg_init();
+
tg_bgchar(' ');
tg_clear();
tui_add_list_item(uilist, "another item");
tui_add_list_item(uilist, "foo");
- /*
- tg_bgcolor(1);
- tg_rect("Remote", 0, 0, 40, 23, TGFX_FRAME);
- tg_rect("Local", 40, 0, 40, 23, TGFX_FRAME);
-
- tg_bgcolor(0);
- tg_fgcolor(7);
- tg_text(0, 23, ">");
- tg_setcursor(2, 23);
- */
+ tg_setcursor(0, 24);
tui_draw(uilist);
}
done:
- tg_bgchar(' ');
- tg_bgcolor(0);
- tg_fgcolor(7);
- tg_clear();
+ tg_cleanup();
cleanup_input();
int i, x, y, num;
struct tui_list *wl = (struct tui_list*)w;
- tui_wtoscr(w, 0, 0, &x, &y);
+ tui_wtoscr(w, 0, 0, &x, &y);
- tg_bgcolor(1);
+ tg_bgcolor(TGFX_BLUE);
tg_rect(wl->title, x, y, wl->width, wl->height, TGFX_FRAME);
num = darr_size(wl->entries);
#include <curses.h>
#include "tgfx.h"
+static int fgcol, bgcol;
+static int bgchar;
+static int cur_x, cur_y;
+
+static int curses_color(int col);
+
+void tg_init(void)
+{
+ initscr();
+ raw();
+ keypad(stdscr, TRUE);
+ noecho();
+ start_color();
+
+ fgcol = curses_color(TGFX_WHITE);
+ bgcol = curses_color(TGFX_BLACK);
+ bgchar = ' ';
+
+ tg_color(fgcol | (bgcol << 4));
+}
+
+void tg_cleanup(void)
+{
+ endwin();
+}
+
+void tg_redraw(void)
+{
+ move(cur_y, cur_x);
+ refresh();
+}
+
void tg_clear(void)
{
}
void tg_fgcolor(int col)
{
+ fgcol = curses_color(col);
+ init_pair(1, fgcol, bgcol);
}
void tg_bgcolor(int col)
{
+ bgcol = curses_color(col);
+ init_pair(1, fgcol, bgcol);
}
void tg_color(int col)
{
+ fgcol = curses_color(col & 0xf);
+ bgcol = curses_color((col >> 4) & 0xf);
+ init_pair(1, fgcol, bgcol);
}
void tg_bgchar(int c)
{
+ bgchar = c;
}
void tg_setcursor(int x, int y)
{
+ move(y, x);
+ cur_x = x;
+ cur_y = y;
}
void tg_text(int x, int y, const char *fmt, ...)
{
+ va_list ap;
+
+ va_start(ap, fmt);
+ tg_vtext(x, y, fmt, ap);
+ va_end(ap);
+}
+
+void tg_vtext(int x, int y, const char *fmt, va_list ap)
+{
+ attron(COLOR_PAIR(1));
+ move(y, x);
+ vw_printw(stdscr, fmt, ap);
+ attroff(COLOR_PAIR(1));
}
void tg_rect(const char *label, int x, int y, int xsz, int ysz, unsigned int flags)
{
+ int i;
+
+ attron(COLOR_PAIR(1));
+
+ for(i=0; i<ysz; i++) {
+ move(y + i, x);
+ hline(bgchar, xsz);
+ }
+
+ if(flags & TGFX_FRAME) {
+ move(y, x + 1);
+ hline(ACS_HLINE, xsz - 2);
+ move(y + ysz - 1, x + 1);
+ hline(ACS_HLINE, xsz - 2);
+ move(y + 1, x);
+ vline(ACS_VLINE, ysz - 2);
+ move(y + 1, x + xsz - 1);
+ vline(ACS_VLINE, ysz - 2);
+
+ mvaddch(y, x, ACS_ULCORNER);
+ mvaddch(y, x + xsz - 1, ACS_URCORNER);
+ mvaddch(y + ysz - 1, x, ACS_LLCORNER);
+ mvaddch(y + ysz - 1, x + xsz - 1, ACS_LRCORNER);
+ }
+
+ if(label) {
+ tg_text(x + 2, y, "%s", label);
+ }
+
+ attroff(COLOR_PAIR(1));
+}
+
+static int curses_color(int col)
+{
+ switch(col) {
+ case TGFX_RED:
+ return COLOR_RED;
+ case TGFX_BLUE:
+ return COLOR_BLUE;
+ case TGFX_CYAN:
+ return COLOR_CYAN;
+ case TGFX_YELLOW:
+ return COLOR_YELLOW;
+ default:
+ break;
+ }
+ return col;
}