about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-08-25 14:17:30 -0400
committerJune McEnroe <june@causal.agency>2018-08-25 14:55:41 -0400
commit2c3b387d77ce5ee0fb9dd81eb3d435816a0d9b6c (patch)
tree4937f271627b173f8a4705baf3f0364d411217e6
parentFix key code handling (diff)
downloadtorus-2c3b387d77ce5ee0fb9dd81eb3d435816a0d9b6c.tar.gz
torus-2c3b387d77ce5ee0fb9dd81eb3d435816a0d9b6c.zip
Add line mode
Diffstat (limited to '')
-rw-r--r--client.c119
1 files changed, 103 insertions, 16 deletions
diff --git a/client.c b/client.c
index 09f29ed..1552861 100644
--- a/client.c
+++ b/client.c
@@ -267,6 +267,7 @@ static struct {
 		MODE_INSERT,
 		MODE_REPLACE,
 		MODE_DRAW,
+		MODE_LINE,
 	} mode;
 	uint8_t color;
 	uint8_t shift;
@@ -286,6 +287,11 @@ static struct {
 	uint8_t len;
 } insert;
 
+static void modeNormal(void) {
+	curs_set(1);
+	move(cellY, cellX);
+	input.mode = MODE_NORMAL;
+}
 static void modeHelp(void) {
 	curs_set(0);
 	drawTile(HELP);
@@ -296,18 +302,6 @@ static void modeMap(void) {
 	clientMap();
 	input.mode = MODE_MAP;
 }
-static void modeNormal(void) {
-	curs_set(1);
-	move(cellY, cellX);
-	input.mode = MODE_NORMAL;
-}
-static void modeDraw(void) {
-	input.draw = 0;
-	input.mode = MODE_DRAW;
-}
-static void modeReplace(void) {
-	input.mode = MODE_REPLACE;
-}
 static void modeDirection(void) {
 	input.mode = MODE_DIRECTION;
 }
@@ -317,6 +311,16 @@ static void modeInsert(int8_t dx, int8_t dy) {
 	insert.len = 0;
 	input.mode = MODE_INSERT;
 }
+static void modeReplace(void) {
+	input.mode = MODE_REPLACE;
+}
+static void modeDraw(void) {
+	input.draw = 0;
+	input.mode = MODE_DRAW;
+}
+static void modeLine(void) {
+	input.mode = MODE_LINE;
+}
 
 static void colorFg(uint8_t fg) {
 	input.color = (input.color & 0x78) | (fg & 0x07);
@@ -457,11 +461,12 @@ static void inputNormal(bool keyCode, wchar_t ch) {
 
 		break; case '?': modeHelp();
 		break; case 'm': modeMap();
-		break; case 'R': modeDraw();
-		break; case 'r': modeReplace(); cellCopy();
 		break; case 'I': modeDirection();
 		break; case 'i': modeInsert(1, 0);
 		break; case 'a': modeInsert(1, 0); clientMove(1, 0);
+		break; case 'r': modeReplace(); cellCopy();
+		break; case 'R': modeDraw();
+		break; case '.': modeLine();
 	}
 }
 
@@ -554,6 +559,87 @@ static void inputDraw(bool keyCode, wchar_t ch) {
 	clientPut(input.color, input.draw);
 }
 
+static uint8_t lineCell(uint8_t cell, int8_t dx, int8_t dy) {
+	if (dx < 0) {
+		switch (CP437[cell]) {
+			default:   return inputCell(L'→');
+			case L'←': return inputCell(L'─'); case L'─': return 0;
+			case L'↑': return inputCell(L'┐'); case L'┐': return 0;
+			case L'↓': return inputCell(L'┘'); case L'┘': return 0;
+			case L'│': return inputCell(L'┤'); case L'┤': return 0;
+			case L'└': return inputCell(L'┴'); case L'┴': return 0;
+			case L'┌': return inputCell(L'┬'); case L'┬': return 0;
+			case L'├': return inputCell(L'┼'); case L'┼': return 0;
+		}
+	} else if (dx > 0) {
+		switch (CP437[cell]) {
+			default:   return inputCell(L'←');
+			case L'→': return inputCell(L'─'); case L'─': return 0;
+			case L'↑': return inputCell(L'┌'); case L'┌': return 0;
+			case L'↓': return inputCell(L'└'); case L'└': return 0;
+			case L'│': return inputCell(L'├'); case L'├': return 0;
+			case L'┘': return inputCell(L'┴'); case L'┴': return 0;
+			case L'┐': return inputCell(L'┬'); case L'┬': return 0;
+			case L'┤': return inputCell(L'┼'); case L'┼': return 0;
+		}
+	} else if (dy < 0) {
+		switch (CP437[cell]) {
+			default:   return inputCell(L'↓');
+			case L'↑': return inputCell(L'│'); case L'│': return 0;
+			case L'←': return inputCell(L'└'); case L'└': return 0;
+			case L'→': return inputCell(L'┘'); case L'┘': return 0;
+			case L'─': return inputCell(L'┴'); case L'┴': return 0;
+			case L'┌': return inputCell(L'├'); case L'├': return 0;
+			case L'┐': return inputCell(L'┤'); case L'┤': return 0;
+			case L'┬': return inputCell(L'┼'); case L'┼': return 0;
+		}
+	} else if (dy > 0) {
+		switch (CP437[cell]) {
+			default:   return inputCell(L'↑');
+			case L'↓': return inputCell(L'│'); case L'│': return 0;
+			case L'←': return inputCell(L'┌'); case L'┌': return 0;
+			case L'→': return inputCell(L'┐'); case L'┐': return 0;
+			case L'─': return inputCell(L'┬'); case L'┬': return 0;
+			case L'└': return inputCell(L'├'); case L'├': return 0;
+			case L'┘': return inputCell(L'┤'); case L'┤': return 0;
+			case L'┴': return inputCell(L'┼'); case L'┼': return 0;
+		}
+	}
+	return 0;
+}
+
+static void inputLine(bool keyCode, wchar_t ch) {
+	int8_t dx = 0;
+	int8_t dy = 0;
+	if (keyCode) {
+		switch (ch) {
+			break; case KEY_LEFT:  dx = -1;
+			break; case KEY_RIGHT: dx =  1;
+			break; case KEY_UP:    dy = -1;
+			break; case KEY_DOWN:  dy =  1;
+			break; default: return;
+		}
+	} else {
+		switch (ch) {
+			break; case ESC: modeNormal(); return;
+			break; case 'h': dx = -1;
+			break; case 'l': dx =  1;
+			break; case 'k': dy = -1;
+			break; case 'j': dy =  1;
+			break; default: return;
+		}
+	}
+	if ((uint8_t)(cellX + dx) >= CELL_COLS) return;
+	if ((uint8_t)(cellY + dy) >= CELL_ROWS) return;
+
+	uint8_t leave = lineCell(tile.cells[cellY][cellX], dx, dy);
+	uint8_t enter = lineCell(tile.cells[cellY + dy][cellX + dx], -dx, -dy);
+
+	if (leave) clientPut(input.color, leave);
+	clientMove(dx, dy);
+	if (enter) clientPut(input.color, enter);
+}
+
 static void readInput(void) {
 	wint_t ch;
 	bool keyCode = (KEY_CODE_YES == get_wch(&ch));
@@ -561,10 +647,11 @@ static void readInput(void) {
 		break; case MODE_NORMAL:    inputNormal(keyCode, ch);
 		break; case MODE_HELP:      inputHelp(keyCode, ch);
 		break; case MODE_MAP:       inputMap(keyCode, ch);
-		break; case MODE_DRAW:      inputDraw(keyCode, ch);
-		break; case MODE_REPLACE:   inputReplace(keyCode, ch);
 		break; case MODE_DIRECTION: inputDirection(keyCode, ch);
 		break; case MODE_INSERT:    inputInsert(keyCode, ch);
+		break; case MODE_REPLACE:   inputReplace(keyCode, ch);
+		break; case MODE_DRAW:      inputDraw(keyCode, ch);
+		break; case MODE_LINE:      inputLine(keyCode, ch);
 	}
 }
 
r'>2015-08-12ui-log: fix double countingJohn Keeping This crept in while rebasing the previous commit onto an updated upstream. Signed-off-by: John Keeping <john@keeping.me.uk> 2015-08-12log: allow users to follow a fileJohn Keeping Teach the "log" UI to behave in the same way as "git log --follow", when given a suitable instruction by the user. The default behaviour remains to show the log without following renames, but the follow behaviour can be activated by following a link in the page header. Follow is not the default because outputting merges in follow mode is tricky ("git log --follow" will not show merges). We also disable the graph in follow mode because the commit graph is not simplified so we end up with frequent gaps in the graph and many lines that do not connect with any commits we're actually showing. We also teach the "diff" and "commit" UIs to respect the follow flag on URLs, causing the single-file version of these UIs to detect renames. This feature is needed only for commits that rename the path we're interested in. For commits before the file has been renamed (i.e. that appear later in the log list) we change the file path in the links from the log to point to the old name; this means that links to commits always limit by the path known to that commit. If we didn't do this we would need to walk down the log diff'ing every commit whenever we want to show a commit. The drawback is that the "Log" link in the top bar of such a page links to the log limited by the old name, so it will only show pre-rename commits. I consider this a reasonable trade-off since the "Back" button still works and the log matches the path displayed in the top bar. Since following renames requires running diff on every commit we consider, I've added a knob to the configuration file to globally enable/disable this feature. Note that we may consider a large number of commits the revision walking machinery no longer performs any path limitation so we have to examine every commit until we find a page full of commits that affect the target path or something related to it. Suggested-by: René Neumann <necoro@necoro.eu> Signed-off-by: John Keeping <john@keeping.me.uk> 2015-08-12shared: make cgit_diff_tree_cb publicJohn Keeping This will allow us to use this nice wrapper function elsewhere, avoiding dealing with the diff queue when we only need to inspect a filepair. Signed-off-by: John Keeping <john@keeping.me.uk> 2015-08-12t0110: Chain together using &&Jason A. Donenfeld 2015-08-12about: always ensure page has a trailing slashJason A. Donenfeld Otherwise we can't easily embed links to other /about/ pages. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> 2015-08-12filters: apply HTML escapingLazaros Koromilas http://www.w3.org/International/questions/qa-escapes#use 2015-08-12git: update to v2.5.0Christian Hesse Update to git version v2.5.0. * Upstream commit 5455ee0573a22bb793a7083d593ae1ace909cd4c (Merge branch 'bc/object-id') changed API: for_each_ref() callback functions were taught to name the objects not with "unsigned char sha1[20]" but with "struct object_id". * Upstream commit dcf692625ac569fefbe52269061230f4fde10e47 (path.c: make get_pathname() call sites return const char *) Signed-off-by: Christian Hesse <mail@eworm.de> 2015-08-12Fix processing of repo.hide and repo.ignoreDaniel Reichelt