mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-03 16:46:18 +00:00 
			
		
		
		
	Align index numbers in trees, from David Mandelberg, GitHub issue 4360.
This commit is contained in:
		
							
								
								
									
										20
									
								
								mode-tree.c
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								mode-tree.c
									
									
									
									
									
								
							@@ -66,6 +66,7 @@ struct mode_tree_data {
 | 
				
			|||||||
	u_int			  line_size;
 | 
						u_int			  line_size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	u_int			  depth;
 | 
						u_int			  depth;
 | 
				
			||||||
 | 
						u_int			  maxdepth;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	u_int			  width;
 | 
						u_int			  width;
 | 
				
			||||||
	u_int			  height;
 | 
						u_int			  height;
 | 
				
			||||||
@@ -196,6 +197,8 @@ mode_tree_build_lines(struct mode_tree_data *mtd,
 | 
				
			|||||||
	int			 flat = 1;
 | 
						int			 flat = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mtd->depth = depth;
 | 
						mtd->depth = depth;
 | 
				
			||||||
 | 
						if (depth > mtd->maxdepth)
 | 
				
			||||||
 | 
							mtd->maxdepth = depth;
 | 
				
			||||||
	TAILQ_FOREACH(mti, mtl, entry) {
 | 
						TAILQ_FOREACH(mti, mtl, entry) {
 | 
				
			||||||
		mtd->line_list = xreallocarray(mtd->line_list,
 | 
							mtd->line_list = xreallocarray(mtd->line_list,
 | 
				
			||||||
		    mtd->line_size + 1, sizeof *mtd->line_list);
 | 
							    mtd->line_size + 1, sizeof *mtd->line_list);
 | 
				
			||||||
@@ -528,6 +531,7 @@ mode_tree_build(struct mode_tree_data *mtd)
 | 
				
			|||||||
	TAILQ_INIT(&mtd->saved);
 | 
						TAILQ_INIT(&mtd->saved);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mode_tree_clear_lines(mtd);
 | 
						mode_tree_clear_lines(mtd);
 | 
				
			||||||
 | 
						mtd->maxdepth = 0;
 | 
				
			||||||
	mode_tree_build_lines(mtd, &mtd->children, 0);
 | 
						mode_tree_build_lines(mtd, &mtd->children, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (mtd->line_list != NULL && tag == UINT64_MAX)
 | 
						if (mtd->line_list != NULL && tag == UINT64_MAX)
 | 
				
			||||||
@@ -658,7 +662,7 @@ mode_tree_draw(struct mode_tree_data *mtd)
 | 
				
			|||||||
	char			*text, *start, *key;
 | 
						char			*text, *start, *key;
 | 
				
			||||||
	const char		*tag, *symbol;
 | 
						const char		*tag, *symbol;
 | 
				
			||||||
	size_t			 size, n;
 | 
						size_t			 size, n;
 | 
				
			||||||
	int			 keylen, pad;
 | 
						int			 keylen, pad, namelen[mtd->maxdepth + 1];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (mtd->line_size == 0)
 | 
						if (mtd->line_size == 0)
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
@@ -682,6 +686,15 @@ mode_tree_draw(struct mode_tree_data *mtd)
 | 
				
			|||||||
			keylen = mti->keylen + 3;
 | 
								keylen = mti->keylen + 3;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for (i = 0; i < mtd->maxdepth + 1; i++)
 | 
				
			||||||
 | 
							namelen[i] = 0;
 | 
				
			||||||
 | 
						for (i = 0; i < mtd->line_size; i++) {
 | 
				
			||||||
 | 
							line = &mtd->line_list[i];
 | 
				
			||||||
 | 
							mti = line->item;
 | 
				
			||||||
 | 
							if ((int)strlen(mti->name) > namelen[line->depth])
 | 
				
			||||||
 | 
								namelen[line->depth] = strlen(mti->name);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (i = 0; i < mtd->line_size; i++) {
 | 
						for (i = 0; i < mtd->line_size; i++) {
 | 
				
			||||||
		if (i < mtd->offset)
 | 
							if (i < mtd->offset)
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
@@ -731,8 +744,9 @@ mode_tree_draw(struct mode_tree_data *mtd)
 | 
				
			|||||||
			tag = "*";
 | 
								tag = "*";
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
			tag = "";
 | 
								tag = "";
 | 
				
			||||||
		xasprintf(&text, "%-*s%s%s%s%s", keylen, key, start, mti->name,
 | 
							xasprintf(&text, "%-*s%s%*s%s%s", keylen, key, start,
 | 
				
			||||||
		    tag, (mti->text != NULL) ? ": " : "" );
 | 
							    namelen[line->depth], mti->name, tag,
 | 
				
			||||||
 | 
							    (mti->text != NULL) ? ": " : "" );
 | 
				
			||||||
		width = utf8_cstrwidth(text);
 | 
							width = utf8_cstrwidth(text);
 | 
				
			||||||
		if (width > w)
 | 
							if (width > w)
 | 
				
			||||||
			width = w;
 | 
								width = w;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user