/* Copyright (c) 2002 * Marko Boomstra (m.boomstra@chello.nl). All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #include #include #include #include #include #include #include #include #include #include "mudix.h" /* * Externals */ extern time_t current_time; extern char connect_name[]; extern int statusTimer; /* * Locals */ SCROLL *scrollbuf; int current_line = 0; int first_line = 0; int pos = 0; void scroll_setup(int lines) { int i; scrollbuf = (SCROLL *)calloc(sizeof(SCROLL), lines); for(i=0; iport); else sprintf(site, "Not connected"); login = trig_lookup(NULL, TRG_LOGIN); pBan += sprintf(banner, "MUDix v"VERSION" # %-10s (%s)", login? login->out: "M.Boomstra", site); while ((pBan-banner) < LEN_COL) { *pBan++ = ' '; if (fPrintTime && ((LEN_COL-24) <= (pBan-banner))) { sprintf(pBan, "%24s", ctime(¤t_time)); break; } } mvwprintw(wBanner, 0, 0, "%s", banner); return; } void print_cmd_line(void) { werase(wInput); if (pCursor >= (LINE_LENGTH + inbuf)) { mvwaddnstr(wInput, 0, 0, pCursor-LINE_LENGTH, LINE_LENGTH); } else mvwaddnstr(wInput, 0, 0, inbuf, pEndIn-inbuf); return; } void move_cursor(WINDOW *win, int direction, int value) { int x, y; getyx(win, y, x); switch(direction) { case UP: y -= value; if (y < 0) y = 0; break; case DOWN: y += value; if (y > (LEN_ROW-2)) y = (LEN_ROW-2); break; case LEFT: x -= value; if (x < 0) x = 0; break; case RIGHT: x += value; if (x > LINE_LENGTH) x = LINE_LENGTH; break; default: break; } wmove(win, y, x); return; } void print_to_eol(void) { waddnstr(wInput, pCursor, LINE_LENGTH - (pCursor - inbuf)); return; } void backspace(void) { move_cursor(wInput, LEFT, 1); wdelch(wInput); return; } void put_in_scroll(char *pBegin, char *pEnd, int attr) { char *pTmp = pBegin; int i; while (pTmp != pEnd && *pTmp) { if (isprint(*pTmp)) { scrollbuf[current_line].data[pos] = *pTmp; scrollbuf[current_line].attr[pos] = attr; pos++; } else if (*pTmp == TAB) { for (i=0; i= LEN_COL || !(pos%TAB_LEN)) break; } } if (pos >= LEN_COL || *pTmp == '\n') { scrollbuf[current_line].len = pos; pos = 0; if (current_line++ == MAX_LINES-1) current_line = 0; if (current_line == first_line) first_line = -1; } pTmp++; } write_log(pBegin, pTmp); return; } void show_scroll(int direction, int scroll_size) { static int pline; int i=0, j, x; if (panel_hidden(pScroll) == PANEL_HIDDEN) pline = current_line; switch (direction) { case UP: while (i++ < scroll_size) { if (pline == first_line) break; if (pline == 0) pline = MAX_LINES; pline--; if (pline == current_line) { if (++pline == MAX_LINES) { pline = 0; break; } } } werase(wScroll); for (i=pline, j=0; j= MAX_LINES) i -= MAX_LINES; pline = i; for (j=0; j