se

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

default_status_bar.h (1527B)


      1 #include <math.h>
      2 
      3 extern struct window_buffer* focused_window;
      4 
      5 static int default_status_bar_callback(int* write_again, struct window_buffer* buf, int minx, int maxx, int cx, int cy, char line[LINE_MAX_LEN], struct glyph* g);
      6 
      7 static const struct extension default_status_bar = {
      8 	.wb_write_status_bar = default_status_bar_callback
      9 };
     10 
     11 int
     12 default_status_bar_callback(int* write_again, struct window_buffer* buf, int minx, int maxx, int cx, int cy, char line[LINE_MAX_LEN], struct glyph* g)
     13 {
     14 	static int count = 0;
     15 	if (!buf) {
     16 		count = 0;
     17 		return 0;
     18 	}
     19 
     20 	struct file_buffer* fb = get_fb(buf);
     21 	switch (count) {
     22 		const char* name;
     23 		int percent;
     24 	case 0:
     25 		if (fb->mode & FB_SEARCH_BLOCKING_IDLE) {
     26 			int before;
     27 			int search_count = fb_count_string_instances(fb, fb->search_term, focused_window->cursor_offset, &before);
     28 			snprintf(line, LINE_MAX_LEN, " %d/%d", before, search_count);
     29 		}
     30 		break;
     31 	case 1:
     32 		snprintf(line, LINE_MAX_LEN, " %dk ", fb->len/1000);
     33 		break;
     34 	case 2:
     35 		g->fg = path_color;
     36 		char* path = file_path_get_path(fb->file_path);
     37 		snprintf(line, LINE_MAX_LEN, "%s", path);
     38 		free(path);
     39 		break;
     40 	case 3:
     41 		name = strrchr(fb->file_path, '/')+1;
     42 		if (name)
     43 			snprintf(line, LINE_MAX_LEN, "%s", name);
     44 		break;
     45 	case 4:
     46 		percent = ceilf(((float)(buf->cursor_offset)/(float)fb->len)*100.0f);
     47 		LIMIT(percent, 0, 100);
     48 		snprintf(line, LINE_MAX_LEN, "  %d:%d %d%%" , cy+1, cx, percent);
     49 		break;
     50 	case 5:
     51 		count = 0;
     52 		*write_again = 0;
     53 		return 0;
     54 	}
     55 	count++;
     56 	*write_again = 1;
     57 	return 0;
     58 }