[svn-commits] trunk r33576 - /trunk/build_tools/menuselect_curses.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Sun Jun 11 15:11:39 MST 2006


Author: russell
Date: Sun Jun 11 17:11:38 2006
New Revision: 33576

URL: http://svn.digium.com/view/asterisk?rev=33576&view=rev
Log:
optimize the display of the module selection menus by only clearing the screen
and starting over if a selection has changed or the menu needs to be scrolled.
For moving the cursor up and down the menu, it works a lot faster now.

Modified:
    trunk/build_tools/menuselect_curses.c

Modified: trunk/build_tools/menuselect_curses.c
URL: http://svn.digium.com/view/asterisk/trunk/build_tools/menuselect_curses.c?rev=33576&r1=33575&r2=33576&view=diff
==============================================================================
--- trunk/build_tools/menuselect_curses.c (original)
+++ trunk/build_tools/menuselect_curses.c Sun Jun 11 17:11:38 2006
@@ -67,7 +67,7 @@
 void winch_handler(int sig);
 void show_help(WINDOW *win);
 void draw_main_menu(WINDOW *menu, int curopt);
-void draw_category_menu(WINDOW *menu, struct category *cat, int start, int end, int curopt);
+void draw_category_menu(WINDOW *menu, struct category *cat, int start, int end, int curopt, int changed);
 int run_category_menu(WINDOW *menu, int cat_num);
 int run_category_menu(WINDOW *menu, int cat_num);
 void draw_title_window(WINDOW *title);
@@ -122,18 +122,72 @@
 	wrefresh(menu);
 }
 
-void draw_category_menu(WINDOW *menu, struct category *cat, int start, int end, int curopt)
+void display_mem_info(WINDOW *menu, struct member *mem, int start, int end)
+{
+	char buf[64];
+	struct depend *dep;
+	struct conflict *con;
+
+	wmove(menu, end - start + 2, max_x / 2 - 16);
+	wclrtoeol(menu);
+	wmove(menu, end - start + 3, max_x / 2 - 16);
+	wclrtoeol(menu);
+	wmove(menu, end - start + 4, max_x / 2 - 16);
+	wclrtoeol(menu);
+
+	if (mem->displayname) {
+		wmove(menu, end - start + 2, max_x / 2 - 16);
+		waddstr(menu, mem->displayname);
+	}
+	if (!AST_LIST_EMPTY(&mem->deps)) {
+		wmove(menu, end - start + 3, max_x / 2 - 16);
+		strcpy(buf, "Depends on: ");
+		AST_LIST_TRAVERSE(&mem->deps, dep, list) {
+			strncat(buf, dep->name, sizeof(buf) - strlen(buf) - 1);
+			if (AST_LIST_NEXT(dep, list))
+				strncat(buf, ", ", sizeof(buf) - strlen(buf) - 1);
+		}
+		waddstr(menu, buf);
+	}
+	if (!AST_LIST_EMPTY(&mem->conflicts)) {
+		wmove(menu, end - start + 4, max_x / 2 - 16);
+		strcpy(buf, "Conflicts with: ");
+		AST_LIST_TRAVERSE(&mem->conflicts, con, list) {
+			strncat(buf, con->name, sizeof(buf) - strlen(buf) - 1);
+			if (AST_LIST_NEXT(con, list))
+				strncat(buf, ", ", sizeof(buf) - strlen(buf) - 1);
+		}
+		waddstr(menu, buf);
+	}
+
+}
+
+void draw_category_menu(WINDOW *menu, struct category *cat, int start, int end, int curopt, int changed)
 {
 	int i = 0;
 	int j = 0;
-	struct member *mem, *curmem = NULL;
-	struct depend *dep;
-	struct conflict *con;
+	struct member *mem;
 	char buf[64];
 	const char *desc = NULL;
 
+	if (!changed) {
+		/* If all we have to do is move the cursor, 
+		 * then don't clear the screen and start over */
+		AST_LIST_TRAVERSE(&cat->members, mem, list) {
+			i++;
+			if (curopt + 1 == i) {
+				display_mem_info(menu, mem, start, end);
+				break;
+			}
+		}
+		wmove(menu, curopt - start, max_x / 2 - 9);
+		wrefresh(menu);
+		return;
+	}
+
 	wclear(menu);
 
+	i = 0;
 	AST_LIST_TRAVERSE(&cat->members, mem, list) {
 		if (i < start) {
 			i++;
@@ -148,38 +202,13 @@
 		waddstr(menu, buf);
 		
 		if (curopt + 1 == i)
-			curmem = mem;
+			display_mem_info(menu, mem, start, end);
 
 		if (i == end)
 			break;
 	}
 
-	if (curmem->displayname) {
-		wmove(menu, end - start + 2, max_x / 2 - 16);
-		waddstr(menu, curmem->displayname);
-	}
-	if (!AST_LIST_EMPTY(&curmem->deps)) {
-		wmove(menu, end - start + 3, max_x / 2 - 16);
-		strcpy(buf, "Depends on: ");
-		AST_LIST_TRAVERSE(&curmem->deps, dep, list) {
-			strncat(buf, dep->name, sizeof(buf) - strlen(buf) - 1);
-			if (AST_LIST_NEXT(dep, list))
-				strncat(buf, ", ", sizeof(buf) - strlen(buf) - 1);
-		}
-		waddstr(menu, buf);
-	}
-	if (!AST_LIST_EMPTY(&curmem->conflicts)) {
-		wmove(menu, end - start + 4, max_x / 2 - 16);
-		strcpy(buf, "Conflicts with: ");
-		AST_LIST_TRAVERSE(&curmem->conflicts, con, list) {
-			strncat(buf, con->name, sizeof(buf) - strlen(buf) - 1);
-			if (AST_LIST_NEXT(con, list))
-				strncat(buf, ", ", sizeof(buf) - strlen(buf) - 1);
-		}
-		waddstr(menu, buf);
-	}
 	wmove(menu, curopt - start, max_x / 2 - 9);
-
 	wrefresh(menu);
 }
 
@@ -192,6 +221,7 @@
 	int c;
 	int curopt = 0;
 	int maxopt;
+	int changed = 1;
 
 	AST_LIST_TRAVERSE(&categories, cat, list) {
 		if (i++ == cat_num)
@@ -202,9 +232,10 @@
 
 	maxopt = count_members(cat) - 1;
 
-	draw_category_menu(menu, cat, start, end, curopt);
+	draw_category_menu(menu, cat, start, end, curopt, changed);
 
 	while ((c = getch())) {
+		changed = 0;
 		switch (c) {
 		case KEY_UP:
 			if (curopt > 0) {
@@ -212,6 +243,7 @@
 				if (curopt < start) {
 					start--;
 					end--;
+					changed = 1;
 				}
 			}
 			break;
@@ -221,6 +253,7 @@
 				if (curopt > end - 1) {
 					start++;
 					end++;
+					changed = 1;
 				}
 			}
 			break;
@@ -238,6 +271,7 @@
 		case '\n':
 		case ' ':
 			toggle_enabled(cat, curopt);
+			changed = 1;
 			break;
 		case 'h':
 		case 'H':
@@ -245,15 +279,17 @@
 			break;
 		case KEY_F(7):
 			set_all(cat, 0);
+			changed = 1;
 			break;
 		case KEY_F(8):
 			set_all(cat, 1);
+			changed = 1;
 		default:
 			break;	
 		}
 		if (c == 'x' || c == 'X' || c == 'Q' || c == 'q')
 			break;	
-		draw_category_menu(menu, cat, start, end, curopt);
+		draw_category_menu(menu, cat, start, end, curopt, changed);
 	}
 
 	wrefresh(menu);



More information about the svn-commits mailing list