about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-08-23 00:06:11 -0400
committerJune McEnroe <june@causal.agency>2018-08-23 00:06:11 -0400
commit6ea0eebad7d11a8d7faf740d02436f500b4700f8 (patch)
tree6f444612bf0efad40112998024db3e61dc7c10bf
parentAdd ssh:// links to index.html (diff)
downloadtorus-6ea0eebad7d11a8d7faf740d02436f500b4700f8.tar.gz
torus-6ea0eebad7d11a8d7faf740d02436f500b4700f8.zip
Support CP437 in merge
-rw-r--r--merge.c68
1 files changed, 40 insertions, 28 deletions
diff --git a/merge.c b/merge.c
index ea1326e..ba9d4f3 100644
--- a/merge.c
+++ b/merge.c
@@ -14,15 +14,24 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#define _XOPEN_SOURCE_EXTENDED
+
 #include <curses.h>
 #include <err.h>
 #include <fcntl.h>
+#include <locale.h>
 #include <stdio.h>
 #include <sysexits.h>
+#include <wchar.h>
 
 #include "torus.h"
 
-static void colorPairs(void) {
+static void curse(void) {
+	setlocale(LC_CTYPE, "");
+
+	initscr();
+	start_color();
+
 	assume_default_colors(0, 0);
 	if (COLORS >= 16) {
 		for (short pair = 1; pair < 0x80; ++pair) {
@@ -33,22 +42,40 @@ static void colorPairs(void) {
 			init_pair(pair, pair & 007, (pair & 070) >> 3);
 		}
 	}
+
+	color_set(COLOR_WHITE, NULL);
+	mvhline(CELL_ROWS, 0, 0, CELL_COLS);
+	mvhline(CELL_ROWS * 2 + 1, 0, 0, CELL_COLS);
+	mvvline(0, CELL_COLS, 0, CELL_ROWS * 2 + 1);
+	mvaddch(CELL_ROWS, CELL_COLS, ACS_RTEE);
+	mvaddch(CELL_ROWS * 2 + 1, CELL_COLS, ACS_LRCORNER);
+	color_set(0, NULL);
+
+	cbreak();
+	noecho();
+	keypad(stdscr, true);
+	set_escdelay(100);
 }
 
-static chtype colorAttr(uint8_t color) {
-	if (COLORS >= 16) return COLOR_PAIR(color);
-	chtype bold = (color & COLOR_BRIGHT) ? A_BOLD : A_NORMAL;
-	short pair = (color & 0x70) >> 1 | (color & 0x07);
-	return bold | COLOR_PAIR(pair);
+static attr_t colorAttr(uint8_t color) {
+	if (COLORS >= 16) return A_NORMAL;
+	return (color & COLOR_BRIGHT) ? A_BOLD : A_NORMAL;
+}
+static short colorPair(uint8_t color) {
+	if (COLORS >= 16) return color;
+	return (color & 0x70) >> 1 | (color & 0x07);
 }
 
 static void drawTile(int offsetY, const struct Tile *tile) {
-	for (uint8_t y = 0; y < CELL_ROWS; ++y) {
-		for (uint8_t x = 0; x < CELL_COLS; ++x) {
-			uint8_t color = tile->colors[y][x];
-			char cell = tile->cells[y][x];
-
-			mvaddch(offsetY + y, x, colorAttr(color) | cell);
+	for (uint8_t cellY = 0; cellY < CELL_ROWS; ++cellY) {
+		for (uint8_t cellX = 0; cellX < CELL_COLS; ++cellX) {
+			uint8_t color = tile->colors[cellY][cellX];
+			uint8_t cell = tile->cells[cellY][cellX];
+
+			cchar_t cch;
+			wchar_t wch[] = { CP437[cell], L'\0' };
+			setcchar(&cch, wch, colorAttr(color), colorPair(color), NULL);
+			mvadd_wch(offsetY + cellY, cellX, &cch);
 		}
 	}
 }
@@ -65,22 +92,7 @@ int main(int argc, char *argv[]) {
 	FILE *fileC = fopen(argv[3], "w");
 	if (!fileC) err(EX_CANTCREAT, "%s", argv[3]);
 
-	initscr();
-	cbreak();
-	noecho();
-	keypad(stdscr, true);
-	set_escdelay(100);
-
-	start_color();
-	colorPairs();
-
-	attrset(colorAttr(COLOR_WHITE));
-	mvhline(CELL_ROWS, 0, 0, CELL_COLS);
-	mvhline(CELL_ROWS * 2 + 1, 0, 0, CELL_COLS);
-	mvvline(0, CELL_COLS, 0, CELL_ROWS * 2 + 1);
-	mvaddch(CELL_ROWS, CELL_COLS, ACS_RTEE);
-	mvaddch(CELL_ROWS * 2 + 1, CELL_COLS, ACS_LRCORNER);
-	attrset(A_NORMAL);
+	curse();
 
 	struct Tile tileA, tileB;
 	for (;;) {
n>Generate HTML with hi -n -f html -o anchorJune McEnroe Running hi twice to insert stuff between the head and the content is a bit of a hack but oh well. 2019-02-17Add hi -f html -o anchor for line number linksJune McEnroe 2019-02-17Simplify temp trap in upJune McEnroe 2019-02-17Add line numbers to hiJune McEnroe Renames previous -n option to -m to stay consistent with cat -n. Prefixing lines with line numbers affects where the first tab indent ends up relative to the text above it. Not sure if it's worth fixing somehow. 2019-02-17Always split spans after newlinesJune McEnroe Simplifies ANSI and IRC output code, and prepares for line numbered output. 2019-02-15Color format specifiers light cyan in vimJune McEnroe 2019-02-15Highlight Interp as yellowJune McEnroe 2019-02-15Highlight strings in sh command substitutionsJune McEnroe 2019-02-15Add nmap gpJune McEnroe 2019-02-14Avoid newline when copying URL to pasteboardJune McEnroe 2019-02-13Add forgotten "sixth" book of H2G2June McEnroeks referes to the tagged objects, using the tag name as filename for download. This can be used to add shortcuts for release tarballs, documentation and other blobs stored in the object database, especially blobs that are not reachable during cloning. Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-05-11Makefile: add support for building w.o. preinstalled gitLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-05-11Tag release v0.3Lars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-05-11Update README with submodule build infoLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-05-11Add submodule links in tree listingLars Hjemli When a submodule occurs in a tree, generate a link to show the module/commit. The link is specified as a sprintf string in /etc/cgitrc, using parameters 'module-link' and 'repo.module-link'. This should probably be extended with repo.module-link.$path. Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-05-11Add submodules.sh and use it during buildsLars Hjemli This adds a shell script which can be be used to initialize, list and update submodules in a git repository. It reads the file .gitmodules to find a mapping between submodule path and repository url for the initial clone of all submodules. The script is used during cgit builds to enable automatic download and checkout of the git git repository. Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-05-11Added git as a submoduleLars Hjemli This commit adds the subdirectory 'git' as a submodule containing the git git repository, but doesn't add support for automatically cloning the submodule. Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-05-09Add support for downloading single blobsLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-05-08ui-view: show pathname if specified in querystringLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-05-08Update to libgit 1.5.2-rc2Lars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-02-21Layout updateLars Hjemli 2007-02-08Make snapshot feature configurableLars Hjemli Snapshots can now be enabled/disabled by default for all repositories in cgitrc with param "snapshots". Additionally, any repo can override the default setting with param "repo.snapshots". By default, no snapshotting is enabled. Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-02-08Add support for snapshotsLars Hjemli Make a link from the commit viewer to a snapshot of the corresponding tree. Currently only zip-format is supported. Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-02-05cgit v0.2Lars Hjemli Main changes since v0.1: -list tags in repo summary -allow search in log-view -read repository paths from cgitrc Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-02-05Add support for prefix and gitsrc arguments to 'make'Lars Hjemli This should improve the installation a little, especially since the new options are mentioned in the README. Also, add a make-rule to build the git binaries if necessary + a dependency between cgit and libgit.a. Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-02-04Update cgitrc templateLars Hjemli Make the descriptions more helpfull. Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-02-04Add support for lightweight tagsLars Hjemli There is nothing bad about a tag that has no tag-object, but the old code didn't handle such tags correctly. Fix it. Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-02-04Read repo-info from /etc/cgitrcLars Hjemli This makes cgit read all repo-info from the configfile, instead of scanning for possible git-dirs below a common root path. This is primarily done to get better security (separate physical path from logical repo-name). In /etc/cgitrc each repo is registered with the following keys: repo.url repo.name repo.path repo.desc repo.owner Note: *Required keys are repo.url and repo.path, all others are optional *Each occurrence of repo.url starts a new repository registration *Default value for repo.name is taken from repo.url *The value of repo.url cannot contain characters with special meaning for urls (i.e. one of /?%&), while repo.name can contain anything. Example: repo.url=cgit-pub repo.name=cgit/public repo.path=/pub/git/cgit repo.desc=My public cgit repo repo.owner=Lars Hjemli repo.url=cgit-priv repo.name=cgit/private repo.path=/home/larsh/src/cgit/.git repo.desc=My private cgit repo repo.owner=Lars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-02-04Do not die if tag has no messageLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-02-03Fix search for non-virtual urlsLars Hjemli When cgit don't use virtual urls, the current repo and page url parameters must be included in the search form as hidden input fields. Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-01-28Update README with install/config informationLars Hjemli