summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--chat.h11
-rw-r--r--edit.c11
-rw-r--r--format.c8
-rw-r--r--ui.c50
4 files changed, 41 insertions, 39 deletions
diff --git a/chat.h b/chat.h
index 50f5c87..6295ce6 100644
--- a/chat.h
+++ b/chat.h
@@ -86,15 +86,12 @@ enum {
 struct Format {
 	const wchar_t *str;
 	size_t len;
-	bool bold;
-	bool italic;
-	bool underline;
-	bool reverse;
-	int fg;
-	int bg;
+	bool split;
+	bool bold, italic, underline, reverse;
+	int fg, bg;
 };
 void formatReset(struct Format *format);
-bool formatParse(struct Format *format, const wchar_t *stop);
+bool formatParse(struct Format *format, const wchar_t *split);
 
 void handle(char *line);
 void input(struct Tag tag, char *line);
diff --git a/edit.c b/edit.c
index 5aca61f..38ee843 100644
--- a/edit.c
+++ b/edit.c
@@ -33,17 +33,10 @@ static struct {
 	.end = line.buf,
 };
 
-// XXX: editTail must always be called after editHead.
-static wchar_t tail;
 const wchar_t *editHead(void) {
-	tail = *line.ptr;
-	*line.ptr = L'\0';
 	return line.buf;
 }
 const wchar_t *editTail(void) {
-	if (tail) *line.ptr = tail;
-	*line.end = L'\0';
-	tail = L'\0';
 	return line.ptr;
 }
 
@@ -180,10 +173,12 @@ void edit(struct Tag tag, enum Edit op, wchar_t ch) {
 
 		break; case EditKillBackWord: reject(); killBackWord();
 		break; case EditKillForeWord: reject(); killForeWord();
-		break; case EditKillLine:      reject(); line.end = line.ptr;
+		break; case EditKillLine:     reject(); line.end = line.ptr;
 
 		break; case EditComplete: complete(tag);
 
 		break; case EditEnter: accept(); enter(tag);
 	}
+
+	*line.end = L'\0';
 }
diff --git a/format.c b/format.c
index 800388b..30b287e 100644
--- a/format.c
+++ b/format.c
@@ -64,10 +64,11 @@ static const wchar_t Stops[] = {
 	L'\0',
 };
 
-bool formatParse(struct Format *format, const wchar_t *stop) {
+bool formatParse(struct Format *format, const wchar_t *split) {
 	format->str += format->len;
 	if (!format->str[0]) return false;
 
+	const wchar_t *init = format->str;
 	switch (format->str[0]) {
 		break; case IRCBold:      format->str++; format->bold ^= true;
 		break; case IRCItalic:    format->str++; format->italic ^= true;
@@ -76,14 +77,15 @@ bool formatParse(struct Format *format, const wchar_t *stop) {
 		break; case IRCColor:     format->str++; parseColor(format);
 		break; case IRCReset:     format->str++; formatReset(format);
 	}
+	format->split = (split >= init && split <= format->str);
 
 	if (format->str[0] == L' ') {
 		format->len = 1 + wcscspn(&format->str[1], Stops);
 	} else {
 		format->len = wcscspn(format->str, Stops);
 	}
-	if (stop && stop > format->str && stop < &format->str[format->len]) {
-		format->len = stop - format->str;
+	if (split > format->str && split < &format->str[format->len]) {
+		format->len = split - format->str;
 	}
 	return true;
 }
diff --git a/ui.c b/ui.c
index 90a75af..72fed6a 100644
--- a/ui.c
+++ b/ui.c
@@ -239,10 +239,25 @@ static const short IRCColors[] = {
 	[IRCLightGray]  = 0 + COLOR_WHITE,
 };
 
-static int addIRC(WINDOW *win, const wchar_t *str) {
-	int lines = 0;
+static void addFormat(WINDOW *win, const struct Format *format) {
+	attr_t attr = A_NORMAL;
+	if (format->bold)      attr |= A_BOLD;
+	if (format->italic)    attr |= A_ITALIC;
+	if (format->underline) attr |= A_UNDERLINE;
+	if (format->reverse)   attr |= A_REVERSE;
+
+	short pair = -1;
+	if (format->fg >= 0) pair = IRCColors[format->fg];
+	if (format->bg >= 0) pair |= IRCColors[format->bg] << 4;
+
+	wattr_set(win, attr | attr8(pair), 1 + pair8(pair), NULL);
+	waddnwstr(win, format->str, format->len);
+}
+
+static int addWrap(WINDOW *win, const wchar_t *str) {
 	struct Format format = { .str = str };
 	formatReset(&format);
+	int lines = 0;
 	while (formatParse(&format, NULL)) {
 		int _, x, xMax;
 		getyx(win, _, x);
@@ -255,19 +270,7 @@ static int addIRC(WINDOW *win, const wchar_t *str) {
 			waddch(win, '\n');
 			lines++;
 		}
-
-		attr_t attr = A_NORMAL;
-		if (format.bold)      attr |= A_BOLD;
-		if (format.italic)    attr |= A_ITALIC;
-		if (format.underline) attr |= A_UNDERLINE;
-		if (format.reverse)   attr |= A_REVERSE;
-
-		short pair = -1;
-		if (format.fg >= 0) pair = IRCColors[format.fg];
-		if (format.bg >= 0) pair |= IRCColors[format.bg] << 4;
-
-		wattr_set(win, attr | attr8(pair), 1 + pair8(pair), NULL);
-		waddnwstr(win, format.str, format.len);
+		addFormat(win, &format);
 	}
 	return lines;
 }
@@ -293,7 +296,7 @@ static void uiStatus(void) {
 		if (len < 0) err(EX_OSERR, "aswprintf");
 		if (view->unread == 1) str[unread] = L'\0';
 
-		addIRC(ui.status, count ? str : &str[1]);
+		addWrap(ui.status, count ? str : &str[1]);
 		free(str);
 		count++;
 	}
@@ -360,7 +363,7 @@ void uiTopic(struct Tag tag, const char *topic) {
 	wchar_t *wcs = ambstowcs(topic);
 	if (!wcs) err(EX_DATAERR, "ambstowcs");
 	wmove(view->topic, 0, 0);
-	addIRC(view->topic, wcs);
+	addWrap(view->topic, wcs);
 	wclrtoeol(view->topic);
 	free(wcs);
 }
@@ -380,7 +383,7 @@ void uiLog(struct Tag tag, enum UIHeat heat, const wchar_t *line) {
 		}
 		uiStatus();
 	}
-	lines += addIRC(view->log, line);
+	lines += addWrap(view->log, line);
 	if (view->scroll != LogLines) view->scroll -= lines;
 }
 
@@ -545,9 +548,14 @@ void uiRead(void) {
 
 	int y, x;
 	wmove(ui.input, 0, 0);
-	addIRC(ui.input, editHead());
-	getyx(ui.input, y, x);
-	addIRC(ui.input, editTail());
+
+	struct Format format = { .str = editHead() };
+	formatReset(&format);
+	while (formatParse(&format, editTail())) {
+		if (format.split) getyx(ui.input, y, x);
+		addFormat(ui.input, &format);
+	}
+
 	wclrtoeol(ui.input);
 	wmove(ui.input, y, x);
 }
ke this: #/bin/sh sed -re 's|\b([0-9a-fA-F]{6,40})\b|<a href="./?id=\1">\1</a>|g' Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-07-31ui-tree: add support for source-filter optionLars Hjemli This new option is used to specify an external command which will be executed when displaying blob content in the tree view. Blob content will be written to STDIN of the filter and STDOUT from the filter will be included verbatim in the html output from cgit. The file name of the blob will be passed as the only argument to the filter command. Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-07-31ui-snapshot: use cgit_{open|close}_filter() to execute compressorsLars Hjemli This simplifies the code in ui-snapshot.c and makes the test-suite verify the new filter-functions. Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-07-31Add generic filter/plugin infrastructureLars Hjemli The functions cgit_open_filter() and cgit_close_filter() can be used to execute filters on the output stream from cgit. Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-07-25Add support for mime type registration and lookupLars Hjemli This patch makes it possible to register mappings from filename extension to mime type in cgitrc and use this mapping when returning blob content in `plain` view. The reason for adding this mapping to cgitrc (as opposed to parsing something like /etc/mime.types) is to allow quick lookup of a limited number of filename extensions (/etc/mime-types on my machine currently contains over 700 entries). NB: A nice addition to this patch would be to parse /etc/mime.types when `plain` view is requested for a file with an extension for which there is no mapping registered in cgitrc. Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-07-25cgit.h: keep config flags sortedLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-07-25cgitrc.5.txt: document 'embedded' and 'noheader'Lars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-07-25Add support for 'noheader' optionLars Hjemli This option can be used to disable the standard cgit page header, which might be useful in combination with the 'embedded' option. Suggested-by: Mark Constable <markc@renta.net> Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-07-25cgitrc.5.txt: document 'head-include'Lars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-07-25ui-blob: return 'application/octet-stream' for binary blobsLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-07-25ui-plain: Return 'application/octet-stream' for binary files.Remko Tronçon Signed-off-by: Remko Tronçon <git@el-tramo.be> Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-06-11use cgit_httpscheme() for atom feedDiego Ongaro 2009-06-11add cgit_httpscheme() -> http:// or https://Diego Ongaro 2009-06-07Return http statuscode 404 on unknown branchLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-06-07Add head-include configuration option.Mark Lodato This patch adds an option to the configuration file, "head-include", which works just like "header" or "footer", except the content is put into the HTML's <head> tag. 2009-03-15CGIT 0.8.2.1Lars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-03-15Fix doc-related glitches in Makefile and .gitignoreLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-03-15ui-snapshot: avoid segfault when no filename is specifiedLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-03-15fix segfault when displaying empty blobsEric Wong When size is zero, subtracting one from it turns it into ULONG_MAX which causes an out-of-bounds access on buf. Signed-off-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-02-19Add support for HEAD requestsLars Hjemli This is a quick 'n dirty hack which makes cgit honor HEAD requests. Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-02-19Add support for ETag in 'plain' viewLars Hjemli When downloading a blob identified by its path, the client might want to know if the blob has been modified since a previous download of the same path. To this end, an ETag containing the blob SHA1 seems to be ideal. Todo: add support for HEAD requests... Suggested-by: Owen Taylor <otaylor@redhat.com> Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-02-12ui-tree: escape ascii-text properly in hexdump viewLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-02-12Makefile: add doc-related targetsLars Hjemli