Browse Source

[bim] scroll padding and hilighted eol spaces

K. Lange 4 years ago
parent
commit
b99b17c967
1 changed files with 29 additions and 4 deletions
  1. 29 4
      apps/bim.c

+ 29 - 4
apps/bim.c

@@ -178,6 +178,8 @@ struct {
 	int can_bright;
 	int history_enabled;
 	int can_title;
+
+	int cursor_padding;
 } global_config = {
 	0, /* term_width */
 	0, /* term_height */
@@ -197,6 +199,7 @@ struct {
 	1,
 	1,
 	1,
+	4, /* cursor padding */
 };
 
 void redraw_line(int j, int x);
@@ -987,6 +990,7 @@ static int syn_make_extended(line_t * line, int i, int c, int last, int * out_le
 
 static char * syn_bimrc_keywords[] = {
 	"theme",
+	"padding",
 	NULL,
 };
 
@@ -2077,6 +2081,11 @@ void render_line(line_t * line, int width, int offset) {
 				_set_colors(COLOR_ALT_FG, COLOR_ALT_BG);
 				printf("[U+%06x]", c.codepoint);
 				_set_colors(last_color ? last_color : COLOR_FG, COLOR_BG);
+			} else if (c.codepoint == ' ' && i == line->actual - 1) {
+				/* Special case: space at end of line */
+				set_colors(COLOR_ALT_FG, COLOR_ALT_BG);
+				printf("·");
+				set_colors(COLOR_FG, COLOR_BG);
 			} else {
 				/* Normal characters get output */
 				char tmp[7]; /* Max six bytes, use 7 to ensure last is always nil */
@@ -2464,13 +2473,13 @@ void place_cursor_actual(void) {
 
 	int needs_redraw = 0;
 
-	while (y < 2) {
+	while (y < 2 + global_config.cursor_padding && env->offset > 0) {
 		y++;
 		env->offset--;
 		needs_redraw = 1;
 	}
 
-	while (y > global_config.term_height - global_config.bottom_size) {
+	while (y > global_config.term_height - global_config.bottom_size - global_config.cursor_padding) {
 		y--;
 		env->offset++;
 		needs_redraw = 1;
@@ -2927,7 +2936,7 @@ void cursor_down(void) {
 		}
 
 		/* If we've scrolled past the bottom of the screen, scroll the screen */
-		if (env->line_no > env->offset + global_config.term_height - global_config.bottom_size - 1) {
+		if (env->line_no > env->offset + global_config.term_height - global_config.bottom_size - 1 - global_config.cursor_padding) {
 			env->offset += 1;
 
 			/* Tell terminal to scroll */
@@ -2996,7 +3005,8 @@ void cursor_up(void) {
 			redraw = 1;
 		}
 
-		if (env->line_no <= env->offset) {
+		int e = (env->offset == 0) ? env->offset : env->offset + global_config.cursor_padding;
+		if (env->line_no <= e) {
 			env->offset -= 1;
 
 			/* Tell terminal to scroll */
@@ -3330,6 +3340,13 @@ void process_command(char * cmd) {
 			global_config.yank_count = 0;
 			redraw_statusbar();
 		}
+	} else if (!strcmp(argv[0], "padding")) {
+		if (argc < 2) {
+			render_status_message("padding=%d", global_config.cursor_padding);
+		} else {
+			global_config.cursor_padding = atoi(argv[1]);
+			place_cursor_actual();
+		}
 	} else if (isdigit(*argv[0])) {
 		/* Go to line number */
 		goto_line(atoi(argv[0]));
@@ -3407,6 +3424,7 @@ void command_tab_complete(char * buffer) {
 		add_candidate("clearyank");
 		add_candidate("indent");
 		add_candidate("noindent");
+		add_candidate("padding");
 		goto _accept_candidate;
 	}
 
@@ -4175,6 +4193,7 @@ void undo_history(void) {
 		recalculate_syntax(env->lines[i],i);
 	}
 	place_cursor_actual();
+	update_title();
 	redraw_all();
 	render_commandline_message("%d character%s, %d line%s changed",
 			count_chars, (count_chars == 1) ? "" : "s",
@@ -4302,6 +4321,7 @@ void redo_history(void) {
 		recalculate_syntax(env->lines[i],i);
 	}
 	place_cursor_actual();
+	update_title();
 	redraw_all();
 	render_commandline_message("%d character%s, %d line%s changed",
 			count_chars, (count_chars == 1) ? "" : "s",
@@ -5436,6 +5456,11 @@ void load_bimrc(void) {
 		if (!strcmp(l,"history")) {
 			global_config.history_enabled = 1;
 		}
+		
+		/* padding= */
+		if (!strcmp(l,"padding") && value) {
+			global_config.cursor_padding = atoi(value);
+		}
 	}
 
 	fclose(bimrc);