[w3m-dev 02454] line number

From: Hironori Sakamoto <hsaka@mth.biglobe.ne.jp>
This commit is contained in:
Fumitoshi UKAI
2001-11-20 16:46:32 +00:00
parent ce759a27cb
commit 8ba4eebc4a
8 changed files with 90 additions and 63 deletions
+16
View File
@@ -1,3 +1,19 @@
2001-11-21 Hironori Sakamoto <hsaka@mth.biglobe.ne.jp>
* buffer.c (newBuffer): set COLS
* display.c (displayBuffer redrawLine redrawLineRegion
cursorRight arrangeCursor cursorXY):
new showLineNumber implementation
* main.c (ctrCsrH shiftvisualpos shiftl shiftr _movL _movR
_followForm follow_map process_mouse):
use buf->COLS, buf->rootX
* menu.c (popupMenu mainMn initSelectMenu):
use buf->rootX
* etc.c (columnSkip): use buf->COLS
* file.c (HTMLlineproc2body loadBuffer saveBufferDelNum getNextPage)
remove old showLineNumber codes
* fm.h (Buffer): add rootX, COLS
2001-11-21 Fumitoshi UKAI <ukai@debian.or.jp> 2001-11-21 Fumitoshi UKAI <ukai@debian.or.jp>
* XMakefile (clean): rm tagtable.c * XMakefile (clean): rm tagtable.c
+1
View File
@@ -31,6 +31,7 @@ newBuffer(int width)
return NULL; return NULL;
bzero((void *) n, sizeof(Buffer)); bzero((void *) n, sizeof(Buffer));
n->width = width; n->width = width;
n->COLS = COLS;
n->currentURL.scheme = SCM_UNKNOWN; n->currentURL.scheme = SCM_UNKNOWN;
n->baseURL = NULL; n->baseURL = NULL;
n->baseTarget = NULL; n->baseTarget = NULL;
+47 -17
View File
@@ -1,4 +1,4 @@
/* $Id: display.c,v 1.3 2001/11/15 00:32:13 a-ito Exp $ */ /* $Id: display.c,v 1.4 2001/11/20 16:46:32 ukai Exp $ */
#include <signal.h> #include <signal.h>
#include "fm.h" #include "fm.h"
@@ -209,6 +209,17 @@ displayBuffer(Buffer * buf, int mode)
reshapeBuffer(buf); reshapeBuffer(buf);
in_check_url = FALSE; in_check_url = FALSE;
} }
if (showLineNum) {
if (buf->lastLine && buf->lastLine->real_linenumber > 0)
buf->rootX = (int)(log(buf->lastLine->real_linenumber + 0.1)
/ log(10)) + 2;
if (buf->rootX < 5)
buf->rootX = 5;
if (buf->rootX > COLS)
buf->rootX = COLS;
} else
buf->rootX = 0;
buf->COLS = COLS - buf->rootX;
if (mode == B_FORCE_REDRAW || if (mode == B_FORCE_REDRAW ||
mode == B_SCROLL || mode == B_SCROLL ||
cline != buf->topLine || cline != buf->topLine ||
@@ -299,7 +310,7 @@ displayBuffer(Buffer * buf, int mode)
clear(); clear();
} }
standout(); standout();
message(msg->ptr, buf->cursorX, buf->cursorY); message(msg->ptr, buf->cursorX + buf->rootX, buf->cursorY);
standend(); standend();
refresh(); refresh();
#ifdef BUFINFO #ifdef BUFINFO
@@ -372,6 +383,25 @@ redrawLine(Buffer * buf, Line * l, int i)
return NULL; return NULL;
} }
move(i, 0); move(i, 0);
if (showLineNum) {
char tmp[16];
if (! buf->rootX) {
if (buf->lastLine->real_linenumber > 0)
buf->rootX = (int)(log(buf->lastLine->real_linenumber + 0.1)
/ log(10)) + 2;
if (buf->rootX < 5)
buf->rootX = 5;
if (buf->rootX > COLS)
buf->rootX = COLS;
buf->COLS = COLS - buf->rootX;
}
if (l->real_linenumber)
sprintf(tmp, "%*d:", buf->rootX - 1, l->real_linenumber);
else
sprintf(tmp, "%*s ", buf->rootX - 1, "");
addstr(tmp);
}
move(i, buf->rootX);
if (l->width < 0) if (l->width < 0)
l->width = COLPOS(l, l->len); l->width = COLPOS(l, l->len);
if (l->len == 0 || l->width - 1 < column) { if (l->len == 0 || l->width - 1 < column) {
@@ -393,7 +423,7 @@ redrawLine(Buffer * buf, Line * l, int i)
#ifndef JP_CHARSET #ifndef JP_CHARSET
delta = 1; delta = 1;
#endif #endif
for (j = 0; rcol - column < COLS && pos + j < l->len; j += delta) { for (j = 0; rcol - column < buf->COLS && pos + j < l->len; j += delta) {
#ifdef COLOR #ifdef COLOR
if (useVisitedColor && vpos <= pos + j && !(pr[j] & PE_VISITED)) { if (useVisitedColor && vpos <= pos + j && !(pr[j] & PE_VISITED)) {
a = retrieveAnchor(buf->href, l->linenumber, pos + j); a = retrieveAnchor(buf->href, l->linenumber, pos + j);
@@ -414,7 +444,7 @@ redrawLine(Buffer * buf, Line * l, int i)
delta = 1; delta = 1;
#endif #endif
ncol = COLPOS(l, pos + j + delta); ncol = COLPOS(l, pos + j + delta);
if (ncol - column > COLS) if (ncol - column > buf->COLS)
break; break;
#ifdef ANSI_COLOR #ifdef ANSI_COLOR
if (pc) if (pc)
@@ -486,7 +516,7 @@ redrawLine(Buffer * buf, Line * l, int i)
if (color_mode) if (color_mode)
do_color(0); do_color(0);
#endif #endif
if (rcol - column < COLS) if (rcol - column < buf->COLS)
clrtoeolx(); clrtoeolx();
return l->next; return l->next;
} }
@@ -526,7 +556,7 @@ redrawLineRegion(Buffer * buf, Line * l, int i, int bpos, int epos)
#ifndef JP_CHARSET #ifndef JP_CHARSET
delta = 1; delta = 1;
#endif #endif
for (j = 0; rcol - column < COLS && pos + j < l->len; j += delta) { for (j = 0; rcol - column < buf->COLS && pos + j < l->len; j += delta) {
#ifdef COLOR #ifdef COLOR
if (useVisitedColor && vpos <= pos + j && !(pr[j] & PE_VISITED)) { if (useVisitedColor && vpos <= pos + j && !(pr[j] & PE_VISITED)) {
a = retrieveAnchor(buf->href, l->linenumber, pos + j); a = retrieveAnchor(buf->href, l->linenumber, pos + j);
@@ -547,7 +577,7 @@ redrawLineRegion(Buffer * buf, Line * l, int i, int bpos, int epos)
delta = 1; delta = 1;
#endif #endif
ncol = COLPOS(l, pos + j + delta); ncol = COLPOS(l, pos + j + delta);
if (ncol - column > COLS) if (ncol - column > buf->COLS)
break; break;
#ifdef ANSI_COLOR #ifdef ANSI_COLOR
if (pc) if (pc)
@@ -555,12 +585,12 @@ redrawLineRegion(Buffer * buf, Line * l, int i, int bpos, int epos)
#endif #endif
if (j >= bcol && j < ecol) { if (j >= bcol && j < ecol) {
if (rcol < column) { if (rcol < column) {
move(i, 0); move(i, buf->rootX);
for (rcol = column; rcol < ncol; rcol++) for (rcol = column; rcol < ncol; rcol++)
addChar(' ', 0); addChar(' ', 0);
continue; continue;
} }
move(i, rcol - column); move(i, rcol - column + buf->rootX);
if (p[j] == '\t') { if (p[j] == '\t') {
for (; rcol < ncol; rcol++) for (; rcol < ncol; rcol++)
addChar(' ', 0); addChar(' ', 0);
@@ -787,7 +817,7 @@ disp_message_nsec(char *s, int redraw_current, int sec, int purge, int mouse)
return; return;
} }
if (Currentbuf != NULL) if (Currentbuf != NULL)
message(s, Currentbuf->cursorX, Currentbuf->cursorY); message(s, Currentbuf->cursorX + Currentbuf->rootX, Currentbuf->cursorY);
else else
message(s, LASTLINE, 0); message(s, LASTLINE, 0);
refresh(); refresh();
@@ -897,8 +927,8 @@ cursorRight(Buffer * buf, int n)
delta = 2; delta = 2;
#endif /* JP_CHARSET */ #endif /* JP_CHARSET */
vpos2 = COLPOS(l, buf->pos + delta) - buf->currentColumn - 1; vpos2 = COLPOS(l, buf->pos + delta) - buf->currentColumn - 1;
if (vpos2 >= COLS && n) { if (vpos2 >= buf->COLS && n) {
columnSkip(buf, n + (vpos2 - COLS) - (vpos2 - COLS) % n); columnSkip(buf, n + (vpos2 - buf->COLS) - (vpos2 - buf->COLS) % n);
buf->visualpos = cpos - buf->currentColumn; buf->visualpos = cpos - buf->currentColumn;
} }
buf->cursorX = buf->visualpos; buf->cursorX = buf->visualpos;
@@ -971,9 +1001,9 @@ arrangeCursor(Buffer * buf)
delta = 2; delta = 2;
#endif /* JP_CHARSET */ #endif /* JP_CHARSET */
col2 = COLPOS(buf->currentLine, buf->pos + delta); col2 = COLPOS(buf->currentLine, buf->pos + delta);
if (col < buf->currentColumn || col2 > COLS + buf->currentColumn) { if (col < buf->currentColumn || col2 > buf->COLS + buf->currentColumn) {
buf->currentColumn = 0; buf->currentColumn = 0;
if (col2 > COLS) if (col2 > buf->COLS)
columnSkip(buf, col); columnSkip(buf, col);
} }
/* Arrange cursor */ /* Arrange cursor */
@@ -1032,19 +1062,19 @@ cursorXY(Buffer * buf, int x, int y)
if (buf->cursorX > x) { if (buf->cursorX > x) {
while (buf->cursorX > x) while (buf->cursorX > x)
cursorLeft(buf, COLS / 2); cursorLeft(buf, buf->COLS / 2);
} }
else if (buf->cursorX < x) { else if (buf->cursorX < x) {
while (buf->cursorX < x) { while (buf->cursorX < x) {
oldX = buf->cursorX; oldX = buf->cursorX;
cursorRight(buf, COLS / 2); cursorRight(buf, buf->COLS / 2);
if (oldX == buf->cursorX) if (oldX == buf->cursorX)
break; break;
} }
if (buf->cursorX > x) if (buf->cursorX > x)
cursorLeft(buf, COLS / 2); cursorLeft(buf, buf->COLS / 2);
} }
} }
+2 -2
View File
@@ -1,4 +1,4 @@
/* $Id: etc.c,v 1.4 2001/11/16 22:02:00 ukai Exp $ */ /* $Id: etc.c,v 1.5 2001/11/20 16:46:32 ukai Exp $ */
#include "fm.h" #include "fm.h"
#include <pwd.h> #include <pwd.h>
#include "myctype.h" #include "myctype.h"
@@ -102,7 +102,7 @@ columnSkip(Buffer * buf, int offset)
if (l->width - 1 > maxColumn) if (l->width - 1 > maxColumn)
maxColumn = l->width - 1; maxColumn = l->width - 1;
} }
maxColumn -= COLS - 1; maxColumn -= buf->COLS - 1;
if (column < maxColumn) if (column < maxColumn)
maxColumn = column; maxColumn = column;
if (maxColumn < 0) if (maxColumn < 0)
+1 -24
View File
@@ -1,4 +1,4 @@
/* $Id: file.c,v 1.8 2001/11/20 08:20:56 ukai Exp $ */ /* $Id: file.c,v 1.9 2001/11/20 16:46:32 ukai Exp $ */
#include "fm.h" #include "fm.h"
#include <sys/types.h> #include <sys/types.h>
#include "myctype.h" #include "myctype.h"
@@ -3722,12 +3722,6 @@ HTMLlineproc2body(Buffer * buf, Str (*feed) (), int llimit)
if (++nlines == llimit) if (++nlines == llimit)
break; break;
pos = 0; pos = 0;
if (showLineNum) {
tmp = Sprintf("%4d:", nlines);
for (p = tmp->ptr; *p; p++) {
PPUSH(PC_ASCII, *p);
}
}
#ifdef ENABLE_REMOVE_TRAILINGSPACES #ifdef ENABLE_REMOVE_TRAILINGSPACES
Strremovetrailingspaces(line); Strremovetrailingspaces(line);
#endif #endif
@@ -5154,11 +5148,6 @@ loadBuffer(URLFile * uf, Buffer * newBuf)
pre_lbuf = lineBuf2->ptr[0]; pre_lbuf = lineBuf2->ptr[0];
} }
++nlines; ++nlines;
if (showLineNum) {
Str tmp = Sprintf("%4d:", nlines);
Strcat(tmp, lineBuf2);
lineBuf2 = tmp;
}
#ifdef USE_NNTP #ifdef USE_NNTP
if (uf->scheme == SCM_NEWS) { if (uf->scheme == SCM_NEWS) {
if (Str_news_endline(lineBuf2)) { if (Str_news_endline(lineBuf2)) {
@@ -5254,8 +5243,6 @@ saveBufferDelNum(Buffer * buf, FILE * f, int del)
else else
#endif #endif
tmp = Strnew_charp_n(l->lineBuf, l->len); tmp = Strnew_charp_n(l->lineBuf, l->len);
if (del && l->real_linenumber && (p = strchr(tmp->ptr, ':')) != NULL)
Strdelete(tmp, 0, p - tmp->ptr + 1);
#ifdef JP_CHARSET #ifdef JP_CHARSET
tmp = conv_str(tmp, InnerCode, DisplayCode); tmp = conv_str(tmp, InnerCode, DisplayCode);
#endif #endif
@@ -5434,11 +5421,6 @@ getNextPage(Buffer * buf, int plen)
if (pl != NULL) { if (pl != NULL) {
nlines = pl->real_linenumber; nlines = pl->real_linenumber;
pre_lbuf = *(pl->lineBuf); pre_lbuf = *(pl->lineBuf);
if (showLineNum) {
char *p;
if ((p = strchr(pl->lineBuf, ':')) != NULL)
pre_lbuf = *(p + 1);
}
if (pre_lbuf == '\0') if (pre_lbuf == '\0')
pre_lbuf = '\n'; pre_lbuf = '\n';
} }
@@ -5475,11 +5457,6 @@ getNextPage(Buffer * buf, int plen)
pre_lbuf = lineBuf2->ptr[0]; pre_lbuf = lineBuf2->ptr[0];
} }
++nlines; ++nlines;
if (showLineNum) {
Str tmp = Sprintf("%4d:", nlines);
Strcat(tmp, lineBuf2);
lineBuf2 = tmp;
}
Strchop(lineBuf2); Strchop(lineBuf2);
lineBuf2 = checkType(lineBuf2, propBuffer, lineBuf2 = checkType(lineBuf2, propBuffer,
#ifdef ANSI_COLOR #ifdef ANSI_COLOR
+3 -1
View File
@@ -1,4 +1,4 @@
/* $Id: fm.h,v 1.6 2001/11/20 08:20:56 ukai Exp $ */ /* $Id: fm.h,v 1.7 2001/11/20 16:46:33 ukai Exp $ */
/* /*
* w3m: WWW wo Miru utility * w3m: WWW wo Miru utility
* *
@@ -333,6 +333,8 @@ typedef struct _Buffer {
short cursorY; short cursorY;
short pos; short pos;
short visualpos; short visualpos;
short rootX;
short COLS;
InputStream pagerSource; InputStream pagerSource;
AnchorList *href; AnchorList *href;
AnchorList *name; AnchorList *name;
+17 -16
View File
@@ -1,4 +1,4 @@
/* $Id: main.c,v 1.10 2001/11/20 08:20:56 ukai Exp $ */ /* $Id: main.c,v 1.11 2001/11/20 16:46:33 ukai Exp $ */
#define MAINPROGRAM #define MAINPROGRAM
#include "fm.h" #include "fm.h"
#include <signal.h> #include <signal.h>
@@ -1204,7 +1204,7 @@ ctrCsrH(void)
int offsetx; int offsetx;
if (Currentbuf->firstLine == NULL) if (Currentbuf->firstLine == NULL)
return; return;
offsetx = Currentbuf->cursorX - COLS / 2; offsetx = Currentbuf->cursorX - Currentbuf->COLS / 2;
if (offsetx != 0) { if (offsetx != 0) {
columnSkip(Currentbuf, offsetx); columnSkip(Currentbuf, offsetx);
arrangeCursor(Currentbuf); arrangeCursor(Currentbuf);
@@ -1341,8 +1341,8 @@ static void
shiftvisualpos(Buffer * buf, int shift) shiftvisualpos(Buffer * buf, int shift)
{ {
buf->visualpos -= shift; buf->visualpos -= shift;
if (buf->visualpos >= COLS) if (buf->visualpos >= buf->COLS)
buf->visualpos = COLS - 1; buf->visualpos = buf->COLS - 1;
else if (buf->visualpos < 0) else if (buf->visualpos < 0)
buf->visualpos = 0; buf->visualpos = 0;
arrangeLine(buf); arrangeLine(buf);
@@ -1359,7 +1359,7 @@ shiftl(void)
if (Currentbuf->firstLine == NULL) if (Currentbuf->firstLine == NULL)
return; return;
column = Currentbuf->currentColumn; column = Currentbuf->currentColumn;
columnSkip(Currentbuf, searchKeyNum() * (-COLS + 1) + 1); columnSkip(Currentbuf, searchKeyNum() * (- Currentbuf->COLS + 1) + 1);
shiftvisualpos(Currentbuf, Currentbuf->currentColumn - column); shiftvisualpos(Currentbuf, Currentbuf->currentColumn - column);
displayBuffer(Currentbuf, B_NORMAL); displayBuffer(Currentbuf, B_NORMAL);
} }
@@ -1373,7 +1373,7 @@ shiftr(void)
if (Currentbuf->firstLine == NULL) if (Currentbuf->firstLine == NULL)
return; return;
column = Currentbuf->currentColumn; column = Currentbuf->currentColumn;
columnSkip(Currentbuf, searchKeyNum() * (COLS - 1) - 1); columnSkip(Currentbuf, searchKeyNum() * (Currentbuf->COLS - 1) - 1);
shiftvisualpos(Currentbuf, Currentbuf->currentColumn - column); shiftvisualpos(Currentbuf, Currentbuf->currentColumn - column);
displayBuffer(Currentbuf, B_NORMAL); displayBuffer(Currentbuf, B_NORMAL);
} }
@@ -1632,7 +1632,7 @@ _movL(int n)
void void
movL(void) movL(void)
{ {
_movL(COLS / 2); _movL(Currentbuf->COLS / 2);
} }
void void
@@ -1704,7 +1704,7 @@ _movR(int n)
void void
movR(void) movR(void)
{ {
_movR(COLS / 2); _movR(Currentbuf->COLS / 2);
} }
void void
@@ -2821,7 +2821,7 @@ _followForm(int submit)
if (submit) if (submit)
goto do_submit; goto do_submit;
if (! formChooseOptionByMenu(fi, if (! formChooseOptionByMenu(fi,
Currentbuf->cursorX - Currentbuf->pos + a->start.pos, Currentbuf->cursorX - Currentbuf->pos + a->start.pos + Currentbuf->rootX,
Currentbuf->cursorY)) Currentbuf->cursorY))
break; break;
formUpdateBuffer(a, Currentbuf, fi); formUpdateBuffer(a, Currentbuf, fi);
@@ -3581,9 +3581,9 @@ follow_map(struct parsed_tagarg *arg)
a = retrieveCurrentImg(Currentbuf); a = retrieveCurrentImg(Currentbuf);
if (a != NULL) if (a != NULL)
x = Currentbuf->cursorX - Currentbuf->pos + a->start.pos; x = Currentbuf->cursorX - Currentbuf->pos + a->start.pos + Currentbuf->rootX;
else else
x = Currentbuf->cursorX; x = Currentbuf->cursorX + Currentbuf->rootX;
url = follow_map_menu(Currentbuf, arg, x, Currentbuf->cursorY + 2); url = follow_map_menu(Currentbuf, arg, x, Currentbuf->cursorY + 2);
if (url == NULL || *url == '\0') if (url == NULL || *url == '\0')
return; return;
@@ -4273,18 +4273,18 @@ process_mouse(int btn, int x, int y)
return; return;
} }
if (y == Currentbuf->cursorY && if (y == Currentbuf->cursorY &&
(x == Currentbuf->cursorX (x == Currentbuf->cursorX + Currentbuf->rootX
#ifdef JP_CHARSET #ifdef JP_CHARSET
|| (Currentbuf->currentLine != NULL && || (Currentbuf->currentLine != NULL &&
(Currentbuf->currentLine->propBuf[Currentbuf->pos] & PC_KANJI1) (Currentbuf->currentLine->propBuf[Currentbuf->pos] & PC_KANJI1)
&& x == Currentbuf->cursorX + 1) && x == Currentbuf->cursorX + Currentbuf->rootX + 1)
#endif /* JP_CHARSET */ #endif /* JP_CHARSET */
)) { )) {
followA(); followA();
return; return;
} }
if (x >= Currentbuf->rootX)
cursorXY(Currentbuf, x, y); cursorXY(Currentbuf, x - Currentbuf->rootX, y);
displayBuffer(Currentbuf, B_NORMAL); displayBuffer(Currentbuf, B_NORMAL);
} }
@@ -4294,7 +4294,8 @@ process_mouse(int btn, int x, int y)
break; break;
case MOUSE_BTN3_DOWN: case MOUSE_BTN3_DOWN:
#ifdef MENU #ifdef MENU
cursorXY(Currentbuf, x, y); if (x >= Currentbuf->rootX)
cursorXY(Currentbuf, x - Currentbuf->rootX, y);
onA(); onA();
mainMenu(x, y); mainMenu(x, y);
#endif /* MENU */ #endif /* MENU */
+3 -3
View File
@@ -1219,7 +1219,7 @@ popupMenu(int x, int y, Menu *menu)
{ {
initSelectMenu(); initSelectMenu();
menu->cursorX = Currentbuf->cursorX; menu->cursorX = Currentbuf->cursorX + Currentbuf->rootX;
menu->cursorY = Currentbuf->cursorY; menu->cursorY = Currentbuf->cursorY;
menu->x = x + FRAME_WIDTH + 1; menu->x = x + FRAME_WIDTH + 1;
menu->y = y + 2; menu->y = y + 2;
@@ -1247,7 +1247,7 @@ mainMn(void)
return; return;
menu = w3mMenuList[n].menu; menu = w3mMenuList[n].menu;
} }
popupMenu(Currentbuf->cursorX, Currentbuf->cursorY, menu); popupMenu(Currentbuf->cursorX + Currentbuf->rootX, Currentbuf->cursorY, menu);
} }
/* --- MainMenu (END) --- */ /* --- MainMenu (END) --- */
@@ -1318,7 +1318,7 @@ initSelectMenu(void)
new_option_menu(&SelectMenu, label, &SelectV, smChBuf); new_option_menu(&SelectMenu, label, &SelectV, smChBuf);
SelectMenu.initial = SelectV; SelectMenu.initial = SelectV;
SelectMenu.cursorX = Currentbuf->cursorX; SelectMenu.cursorX = Currentbuf->cursorX + Currentbuf->rootX;
SelectMenu.cursorY = Currentbuf->cursorY; SelectMenu.cursorY = Currentbuf->cursorY;
SelectMenu.keymap['D'] = smDelBuf; SelectMenu.keymap['D'] = smDelBuf;
SelectMenu.item[nitem].type = MENU_NOP; SelectMenu.item[nitem].type = MENU_NOP;