All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [Powertop] [PATCH] tuninig: resize scaling support (v1)
@ 2012-08-24 15:56 Chris Ferron
  0 siblings, 0 replies; 9+ messages in thread
From: Chris Ferron @ 2012-08-24 15:56 UTC (permalink / raw)
  To: powertop

[-- Attachment #1: Type: text/plain, Size: 2519 bytes --]

On 08/23/2012 01:53 PM, Sergey Senozhatsky wrote:
> On (08/23/12 09:57), Chris Ferron wrote:
>> So this may be nice for the tuning tab, but we have an overall issue
>> with other tabs as well.
>> Maybe we should change the controls around, and just move the pad.
>> That way we could scroll all tabs and not have to truncate strings.
>> ?
>> -Chris
>>
> That was the first one in a upcoming series of patches.
> Because we have separate display logic on every tab, I was moving in a
> direction of teaching each tabs honour resize.
>
>
>> Maybe we should change the controls around, and just move the pad.
>> That way we could scroll all tabs and not have to truncate strings.
> Sorry, I'm not sure I got this one, could you please elaborate?
>
> We can't avaoid string truncation (unless we introduce support for horizontal
> scrolling as well) when X becomes smaller than the longest string in tab
> (we actually can just ignore it and print beyond the sceen, but I think the
> common behaviour in that case is to let user notice that text has been truncated
> via ~ for example). I don't know what to do with C, P states tab when we only
> have space for "Package" and "Core", or when half of currently required X space for
> "Frequency stats" tab is available -- dynamic re-arrange looks a bit complex at
> the moment.
>
> As of Y scroll, well, we can come up with a common interface:
> -- for tab w/ cursor
> scrolling happens on every n*Y cursor position, because cursor step is 1.
>
> -- for tab w/o cursor
> scroling happens every cursor step (which is Y in this case).
>
> Schematically, what we need is a common method which will tell the number
> of lines particular tab is going to print, flag that indecates cursor step
> and common method (similar to one that used in tuning tab) to print tab
> content from BEGIN positiothen to END (BEGIN and END depends on current frame).
I will have to take another look this weekend, but if I remember 
correctly. We create a large pad and then place windows on for viewing. 
If we change the controls a bit, I think we can use the arrow keys to 
scroll the viewable window around the pad for all tab windows.

Refresh or a tab change would reset the viewable window. Then we could 
scroll x y.

I think you may be right about truncating strings, but maybe only if the 
string is bigger then the base pad.

Instead of arrow keys navigating tabs, we could use the "TAB" key.

Just a thought
-Chris


>
> 	-ss


^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: [Powertop] [PATCH] tuninig: resize scaling support (v1)
@ 2012-09-11 16:53 Sergey Senozhatsky
  0 siblings, 0 replies; 9+ messages in thread
From: Sergey Senozhatsky @ 2012-09-11 16:53 UTC (permalink / raw)
  To: powertop

[-- Attachment #1: Type: text/plain, Size: 236 bytes --]

On (09/11/12 09:40), Chris Ferron wrote:
> I just sent a patch attachment as "PowerTOP UI navigation
> enhancement". Check it out???
> Sorry for the slow response.
>

sure, no problems. will take a look later this day.


	-ss

^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: [Powertop] [PATCH] tuninig: resize scaling support (v1)
@ 2012-09-11 16:40 Chris Ferron
  0 siblings, 0 replies; 9+ messages in thread
From: Chris Ferron @ 2012-09-11 16:40 UTC (permalink / raw)
  To: powertop

[-- Attachment #1: Type: text/plain, Size: 2069 bytes --]

On 08/23/2012 01:53 PM, Sergey Senozhatsky wrote:
> On (08/23/12 09:57), Chris Ferron wrote:
>> So this may be nice for the tuning tab, but we have an overall issue
>> with other tabs as well.
>> Maybe we should change the controls around, and just move the pad.
>> That way we could scroll all tabs and not have to truncate strings.
>> ?
>> -Chris
>>
> That was the first one in a upcoming series of patches.
> Because we have separate display logic on every tab, I was moving in a
> direction of teaching each tabs honour resize.
>
>
>> Maybe we should change the controls around, and just move the pad.
>> That way we could scroll all tabs and not have to truncate strings.
> Sorry, I'm not sure I got this one, could you please elaborate?
>
> We can't avaoid string truncation (unless we introduce support for horizontal
> scrolling as well) when X becomes smaller than the longest string in tab
> (we actually can just ignore it and print beyond the sceen, but I think the
> common behaviour in that case is to let user notice that text has been truncated
> via ~ for example). I don't know what to do with C, P states tab when we only
> have space for "Package" and "Core", or when half of currently required X space for
> "Frequency stats" tab is available -- dynamic re-arrange looks a bit complex at
> the moment.
>
> As of Y scroll, well, we can come up with a common interface:
> -- for tab w/ cursor
> scrolling happens on every n*Y cursor position, because cursor step is 1.
>
> -- for tab w/o cursor
> scroling happens every cursor step (which is Y in this case).
>
> Schematically, what we need is a common method which will tell the number
> of lines particular tab is going to print, flag that indecates cursor step
> and common method (similar to one that used in tuning tab) to print tab
> content from BEGIN position to END (BEGIN and END depends on current frame).
>
>
> 	-ss
I just sent a patch attachment as "PowerTOP UI navigation enhancement". 
Check it out???
Sorry for the slow response.
-Chris


^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: [Powertop] [PATCH] tuninig: resize scaling support (v1)
@ 2012-08-23 20:53 Sergey Senozhatsky
  0 siblings, 0 replies; 9+ messages in thread
From: Sergey Senozhatsky @ 2012-08-23 20:53 UTC (permalink / raw)
  To: powertop

[-- Attachment #1: Type: text/plain, Size: 1839 bytes --]

On (08/23/12 09:57), Chris Ferron wrote:
> >>
> So this may be nice for the tuning tab, but we have an overall issue
> with other tabs as well.
> Maybe we should change the controls around, and just move the pad.
> That way we could scroll all tabs and not have to truncate strings.
> ?
> -Chris
> 

That was the first one in a upcoming series of patches. 
Because we have separate display logic on every tab, I was moving in a
direction of teaching each tabs honour resize. 


> Maybe we should change the controls around, and just move the pad.
> That way we could scroll all tabs and not have to truncate strings.

Sorry, I'm not sure I got this one, could you please elaborate?

We can't avaoid string truncation (unless we introduce support for horizontal
scrolling as well) when X becomes smaller than the longest string in tab 
(we actually can just ignore it and print beyond the sceen, but I think the
common behaviour in that case is to let user notice that text has been truncated
via ~ for example). I don't know what to do with C, P states tab when we only
have space for "Package" and "Core", or when half of currently required X space for
"Frequency stats" tab is available -- dynamic re-arrange looks a bit complex at
the moment.

As of Y scroll, well, we can come up with a common interface:
-- for tab w/ cursor 
scrolling happens on every n*Y cursor position, because cursor step is 1.

-- for tab w/o cursor
scroling happens every cursor step (which is Y in this case).

Schematically, what we need is a common method which will tell the number
of lines particular tab is going to print, flag that indecates cursor step
and common method (similar to one that used in tuning tab) to print tab
content from BEGIN position to END (BEGIN and END depends on current frame).


	-ss

^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: [Powertop] [PATCH] tuninig: resize scaling support (v1)
@ 2012-08-23 16:57 Chris Ferron
  0 siblings, 0 replies; 9+ messages in thread
From: Chris Ferron @ 2012-08-23 16:57 UTC (permalink / raw)
  To: powertop

[-- Attachment #1: Type: text/plain, Size: 4591 bytes --]

On 08/23/2012 02:12 AM, Sergey Senozhatsky wrote:
> On (08/23/12 01:47), Sergey Senozhatsky wrote:
>> tuninig: resize scaling support v1
>>
>> Initial version of terminal window resize support for tuning tab.
>> Supports both X and Y scalings:
>> -- X scaling: truncation (*)
>> * tunable result and description strings are now stored in dynamic
>> array, limited in size to current window X (mod MAX_LEN).
>>
>> -- Y scaling: paging and scrolling
>>
>>
>> Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky(a)gmail.com>
>>
>> ---
>>
>>   src/tuning/tuning.cpp | 87 +++++++++++++++++++++++++++++++++++----------------
>>   1 file changed, 60 insertions(+), 27 deletions(-)
>>
>> diff --git a/src/tuning/tuning.cpp b/src/tuning/tuning.cpp
>> index 4893597..541e9e0 100644
>> --- a/src/tuning/tuning.cpp
>> +++ b/src/tuning/tuning.cpp
>> @@ -28,7 +28,7 @@
>>   #include <stdio.h>
>>   #include <string.h>
>>   #include <ncurses.h>
>> -
>> +#include <math.h>
>>   
>>   #include "tuning.h"
>>   #include "tuningsysfs.h"
>> @@ -79,48 +79,81 @@ void initialize_tuning(void)
>>   	create_tab("Tunables", _("Tunables"), w, _(" <ESC> Exit | <Enter> Toggle tunable | <r> Window refresh"));
>>   
>>   	init_tuning();
>> -
>>   	w->cursor_max = all_tunables.size() - 1;
>>   }
>>   
>> +#define XINDENT	3
>> +#define YINDENT	4
>> +#define MAX_LEN	4096
>>   
>> +static void redraw_window(WINDOW *win, int begin, int end, int cursor_pos)
>> +{
>> +	int x, y, i;
>> +	getmaxyx(stdscr, y, x);
>> +	
>> +	wclrtoeol(win);
>> +	wmove(win, 1, 0);
>> +	x %= MAX_LEN;
>> +
>> +	for (y = 0, i = begin; i < end; i++, y++) {
>> +		char truncate = 0;
>> +		size_t sz = 0;
>> +		char line[x + 1];
>> +		if ((int)(y) != cursor_pos) {
>> +			wattrset(win, A_NORMAL);
>> +			sz = snprintf(line, x, "   ");
>> +		} else {
>> +			wattrset(win, A_REVERSE);
>> +			sz = snprintf(line, x, ">> ");
>> +		}
>> +		sz += snprintf(line + sz, x, "%s", all_tunables[i]->result_string());
>
> Hm, I guess the correct way is
>
> 	_(all_tunables[i]->result_string())
>
>> +		while (sz < 12)
>> +			sz += snprintf(line + sz, x, " ");
>> +		sz += snprintf(line + sz, x, "%s", all_tunables[i]->description());
> the same
>
> 	_(all_tunables[i]->description())
>
>> +		if ((int)sz > x - XINDENT)
>> +			truncate = 1;
>> +		while ((int)sz < x - XINDENT)
>> +			sz += snprintf(line + sz, x, " ");
>> +		if (truncate)
>> +			sz += snprintf(line + x - XINDENT - 1, x, "~\n");
>> +		else
>> +			sz += snprintf(line + sz, x, "\n");
>> +
>> +		waddnstr(win, line, sz);
>> +	}
>> +}
>>   
>>   static void __tuning_update_display(int cursor_pos)
>>   {
>> +	static int last_frame_nr = 0;
>> +	int x, y, begin, end, frame_nr;
>>   	WINDOW *win;
>> -	unsigned int i;
>> -
>> +
>>   	win = get_ncurses_win("Tunables");
>> -
>>   	if (!win)
>>   		return;
>> +	getmaxyx(stdscr, y, x);
>> +
>> +	y -= YINDENT;
>> +	frame_nr = ceil(cursor_pos / y);
>> +	end = (frame_nr + 1) * y;
>> +	if (end > (int)all_tunables.size())
>> +		end = all_tunables.size();
>> +
>> +	begin = frame_nr * y;
>> +	/* actual cursor position is frame-dependent */
>> +	cursor_pos -= frame_nr * y;
>> +	if (frame_nr != last_frame_nr)
>> +		should_clear = TRUE;
>> +	last_frame_nr = frame_nr;
>>   
>>   	if (should_clear) {
>> -		should_clear = false;
>> +		should_clear = FALSE;
>>   		wclear(win);
>>   	}
>>   
>> -	wmove(win, 2,0);
>> -
>> -	for (i = 0; i < all_tunables.size(); i++) {
>> -		char res[128];
>> -		char desc[4096];
>> -		strcpy(res, all_tunables[i]->result_string());
>> -		strcpy(desc, all_tunables[i]->description());
>> -		while (strlen(res) < 12)
>> -			strcat(res, " ");
>> -
>> -		while (strlen(desc) < 103)
>> -			strcat(desc, " ");
>> -		if ((int)i != cursor_pos) {
>> -			wattrset(win, A_NORMAL);
>> -			wprintw(win, "   ");
>> -		} else {
>> -			wattrset(win, A_REVERSE);
>> -			wprintw(win, ">> ");
>> -		}
>> -		wprintw(win, "%s  %s\n", _(res), _(desc));
>> -	}
>> +	redraw_window(win, begin, end, cursor_pos);
>> +	wnoutrefresh(win);
>>   }
>>   
>>   void tuning_update_display(void)
>>
So this may be nice for the tuning tab, but we have an overall issue 
with other tabs as well.
Maybe we should change the controls around, and just move the pad. That 
way we could scroll all tabs and not have to truncate strings.
?
-Chris

> _______________________________________________
> PowerTop mailing list
> PowerTop(a)lists.01.org
> https://lists.01.org/mailman/listinfo/powertop


^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: [Powertop] [PATCH] tuninig: resize scaling support (v1)
@ 2012-08-23  9:12 Sergey Senozhatsky
  0 siblings, 0 replies; 9+ messages in thread
From: Sergey Senozhatsky @ 2012-08-23  9:12 UTC (permalink / raw)
  To: powertop

[-- Attachment #1: Type: text/plain, Size: 3972 bytes --]

On (08/23/12 01:47), Sergey Senozhatsky wrote:
> tuninig: resize scaling support v1
> 
> Initial version of terminal window resize support for tuning tab.
> Supports both X and Y scalings:
> -- X scaling: truncation (*)
> * tunable result and description strings are now stored in dynamic
> array, limited in size to current window X (mod MAX_LEN).
> 
> -- Y scaling: paging and scrolling
> 
> 
> Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky(a)gmail.com>
> 
> ---
> 
>  src/tuning/tuning.cpp | 87 +++++++++++++++++++++++++++++++++++----------------
>  1 file changed, 60 insertions(+), 27 deletions(-)
> 
> diff --git a/src/tuning/tuning.cpp b/src/tuning/tuning.cpp
> index 4893597..541e9e0 100644
> --- a/src/tuning/tuning.cpp
> +++ b/src/tuning/tuning.cpp
> @@ -28,7 +28,7 @@
>  #include <stdio.h>
>  #include <string.h>
>  #include <ncurses.h>
> -
> +#include <math.h>
>  
>  #include "tuning.h"
>  #include "tuningsysfs.h"
> @@ -79,48 +79,81 @@ void initialize_tuning(void)
>  	create_tab("Tunables", _("Tunables"), w, _(" <ESC> Exit | <Enter> Toggle tunable | <r> Window refresh"));
>  
>  	init_tuning();
> -
>  	w->cursor_max = all_tunables.size() - 1;
>  }
>  
> +#define XINDENT	3
> +#define YINDENT	4
> +#define MAX_LEN	4096
>  
> +static void redraw_window(WINDOW *win, int begin, int end, int cursor_pos)
> +{
> +	int x, y, i;
> +	getmaxyx(stdscr, y, x);
> +	
> +	wclrtoeol(win);
> +	wmove(win, 1, 0);
> +	x %= MAX_LEN;
> +
> +	for (y = 0, i = begin; i < end; i++, y++) {
> +		char truncate = 0;
> +		size_t sz = 0;
> +		char line[x + 1];
> +		if ((int)(y) != cursor_pos) {
> +			wattrset(win, A_NORMAL);
> +			sz = snprintf(line, x, "   ");
> +		} else {
> +			wattrset(win, A_REVERSE);
> +			sz = snprintf(line, x, ">> ");
> +		}
> +		sz += snprintf(line + sz, x, "%s", all_tunables[i]->result_string());


Hm, I guess the correct way is

	_(all_tunables[i]->result_string())

> +		while (sz < 12)
> +			sz += snprintf(line + sz, x, " ");
> +		sz += snprintf(line + sz, x, "%s", all_tunables[i]->description());

the same

	_(all_tunables[i]->description())

> +		if ((int)sz > x - XINDENT)
> +			truncate = 1;
> +		while ((int)sz < x - XINDENT)
> +			sz += snprintf(line + sz, x, " ");
> +		if (truncate)
> +			sz += snprintf(line + x - XINDENT - 1, x, "~\n");
> +		else
> +			sz += snprintf(line + sz, x, "\n");
> +
> +		waddnstr(win, line, sz);
> +	}
> +}
>  
>  static void __tuning_update_display(int cursor_pos)
>  {
> +	static int last_frame_nr = 0;
> +	int x, y, begin, end, frame_nr;
>  	WINDOW *win;
> -	unsigned int i;
> -
> +        
>  	win = get_ncurses_win("Tunables");
> -
>  	if (!win)
>  		return;
> +	getmaxyx(stdscr, y, x);
> +
> +	y -= YINDENT;
> +	frame_nr = ceil(cursor_pos / y);
> +	end = (frame_nr + 1) * y;
> +	if (end > (int)all_tunables.size())
> +		end = all_tunables.size();
> +
> +	begin = frame_nr * y;
> +	/* actual cursor position is frame-dependent */
> +	cursor_pos -= frame_nr * y;
> +	if (frame_nr != last_frame_nr)
> +		should_clear = TRUE;
> +	last_frame_nr = frame_nr;
>  
>  	if (should_clear) {
> -		should_clear = false;
> +		should_clear = FALSE;
>  		wclear(win);
>  	}
>  
> -	wmove(win, 2,0);
> -
> -	for (i = 0; i < all_tunables.size(); i++) {
> -		char res[128];
> -		char desc[4096];
> -		strcpy(res, all_tunables[i]->result_string());
> -		strcpy(desc, all_tunables[i]->description());
> -		while (strlen(res) < 12)
> -			strcat(res, " ");
> -
> -		while (strlen(desc) < 103)
> -			strcat(desc, " ");
> -		if ((int)i != cursor_pos) {
> -			wattrset(win, A_NORMAL);
> -			wprintw(win, "   ");
> -		} else {
> -			wattrset(win, A_REVERSE);
> -			wprintw(win, ">> ");
> -		}
> -		wprintw(win, "%s  %s\n", _(res), _(desc));
> -	}
> +	redraw_window(win, begin, end, cursor_pos);
> +	wnoutrefresh(win);
>  }
>  
>  void tuning_update_display(void)
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: [Powertop] [PATCH] tuninig: resize scaling support (v1)
@ 2012-08-23  8:04 Sergey Senozhatsky
  0 siblings, 0 replies; 9+ messages in thread
From: Sergey Senozhatsky @ 2012-08-23  8:04 UTC (permalink / raw)
  To: powertop

[-- Attachment #1: Type: text/plain, Size: 4943 bytes --]

On (08/23/12 06:22), Magnus Fromreide wrote:
> On Thu, 2012-08-23 at 01:47 +0300, Sergey Senozhatsky wrote:
> > tuninig: resize scaling support v1
> > 
> > Initial version of terminal window resize support for tuning tab.
> > Supports both X and Y scalings:
> > -- X scaling: truncation (*)
> > * tunable result and description strings are now stored in dynamic
> > array, limited in size to current window X (mod MAX_LEN).
> > 
> > -- Y scaling: paging and scrolling
> 
> Have you tested this patch in a locale that are using multibyte
> characters?
> 
> The len argument to snprintf is the number of bytes in the result string
> and strlen also returns the number of bytes in the string.
>

well, line is just a stream of bytes limited in size. it was never
intended to be a stream of characters. at this point we just work
with bytes, it's waddnstr() who should care. the same way as
"strcpy()/strlen()/strcat()-->wprintw()" worked before.

probably, we should truncate carefully, I need to think how. any
input is welcome.

	-ss
 
> /MF
> 
> > 
> > Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky(a)gmail.com>
> > 
> > ---
> > 
> >  src/tuning/tuning.cpp | 87 +++++++++++++++++++++++++++++++++++----------------
> >  1 file changed, 60 insertions(+), 27 deletions(-)
> > 
> > diff --git a/src/tuning/tuning.cpp b/src/tuning/tuning.cpp
> > index 4893597..541e9e0 100644
> > --- a/src/tuning/tuning.cpp
> > +++ b/src/tuning/tuning.cpp
> > @@ -28,7 +28,7 @@
> >  #include <stdio.h>
> >  #include <string.h>
> >  #include <ncurses.h>
> > -
> > +#include <math.h>
> >  
> >  #include "tuning.h"
> >  #include "tuningsysfs.h"
> > @@ -79,48 +79,81 @@ void initialize_tuning(void)
> >  	create_tab("Tunables", _("Tunables"), w, _(" <ESC> Exit | <Enter> Toggle tunable | <r> Window refresh"));
> >  
> >  	init_tuning();
> > -
> >  	w->cursor_max = all_tunables.size() - 1;
> >  }
> >  
> > +#define XINDENT	3
> > +#define YINDENT	4
> > +#define MAX_LEN	4096
> >  
> > +static void redraw_window(WINDOW *win, int begin, int end, int cursor_pos)
> > +{
> > +	int x, y, i;
> > +	getmaxyx(stdscr, y, x);
> > +	
> > +	wclrtoeol(win);
> > +	wmove(win, 1, 0);
> > +	x %= MAX_LEN;
> > +
> > +	for (y = 0, i = begin; i < end; i++, y++) {
> > +		char truncate = 0;
> > +		size_t sz = 0;
> > +		char line[x + 1];
> > +		if ((int)(y) != cursor_pos) {
> > +			wattrset(win, A_NORMAL);
> > +			sz = snprintf(line, x, "   ");
> > +		} else {
> > +			wattrset(win, A_REVERSE);
> > +			sz = snprintf(line, x, ">> ");
> > +		}
> > +		sz += snprintf(line + sz, x, "%s", all_tunables[i]->result_string());
> > +		while (sz < 12)
> > +			sz += snprintf(line + sz, x, " ");
> > +		sz += snprintf(line + sz, x, "%s", all_tunables[i]->description());
> > +		if ((int)sz > x - XINDENT)
> > +			truncate = 1;
> > +		while ((int)sz < x - XINDENT)
> > +			sz += snprintf(line + sz, x, " ");
> > +		if (truncate)
> > +			sz += snprintf(line + x - XINDENT - 1, x, "~\n");
> > +		else
> > +			sz += snprintf(line + sz, x, "\n");
> > +
> > +		waddnstr(win, line, sz);
> > +	}
> > +}
> >  
> >  static void __tuning_update_display(int cursor_pos)
> >  {
> > +	static int last_frame_nr = 0;
> > +	int x, y, begin, end, frame_nr;
> >  	WINDOW *win;
> > -	unsigned int i;
> > -
> > +        
> >  	win = get_ncurses_win("Tunables");
> > -
> >  	if (!win)
> >  		return;
> > +	getmaxyx(stdscr, y, x);
> > +
> > +	y -= YINDENT;
> > +	frame_nr = ceil(cursor_pos / y);
> > +	end = (frame_nr + 1) * y;
> > +	if (end > (int)all_tunables.size())
> > +		end = all_tunables.size();
> > +
> > +	begin = frame_nr * y;
> > +	/* actual cursor position is frame-dependent */
> > +	cursor_pos -= frame_nr * y;
> > +	if (frame_nr != last_frame_nr)
> > +		should_clear = TRUE;
> > +	last_frame_nr = frame_nr;
> >  
> >  	if (should_clear) {
> > -		should_clear = false;
> > +		should_clear = FALSE;
> >  		wclear(win);
> >  	}
> >  
> > -	wmove(win, 2,0);
> > -
> > -	for (i = 0; i < all_tunables.size(); i++) {
> > -		char res[128];
> > -		char desc[4096];
> > -		strcpy(res, all_tunables[i]->result_string());
> > -		strcpy(desc, all_tunables[i]->description());
> > -		while (strlen(res) < 12)
> > -			strcat(res, " ");
> > -
> > -		while (strlen(desc) < 103)
> > -			strcat(desc, " ");
> > -		if ((int)i != cursor_pos) {
> > -			wattrset(win, A_NORMAL);
> > -			wprintw(win, "   ");
> > -		} else {
> > -			wattrset(win, A_REVERSE);
> > -			wprintw(win, ">> ");
> > -		}
> > -		wprintw(win, "%s  %s\n", _(res), _(desc));
> > -	}
> > +	redraw_window(win, begin, end, cursor_pos);
> > +	wnoutrefresh(win);
> >  }
> >  
> >  void tuning_update_display(void)
> > 
> > _______________________________________________
> > PowerTop mailing list
> > PowerTop(a)lists.01.org
> > https://lists.01.org/mailman/listinfo/powertop
> 
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: [Powertop] [PATCH] tuninig: resize scaling support (v1)
@ 2012-08-23  4:22 Magnus Fromreide
  0 siblings, 0 replies; 9+ messages in thread
From: Magnus Fromreide @ 2012-08-23  4:22 UTC (permalink / raw)
  To: powertop

[-- Attachment #1: Type: text/plain, Size: 4234 bytes --]

On Thu, 2012-08-23 at 01:47 +0300, Sergey Senozhatsky wrote:
> tuninig: resize scaling support v1
> 
> Initial version of terminal window resize support for tuning tab.
> Supports both X and Y scalings:
> -- X scaling: truncation (*)
> * tunable result and description strings are now stored in dynamic
> array, limited in size to current window X (mod MAX_LEN).
> 
> -- Y scaling: paging and scrolling

Have you tested this patch in a locale that are using multibyte
characters?

The len argument to snprintf is the number of bytes in the result string
and strlen also returns the number of bytes in the string.

/MF

> 
> Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky(a)gmail.com>
> 
> ---
> 
>  src/tuning/tuning.cpp | 87 +++++++++++++++++++++++++++++++++++----------------
>  1 file changed, 60 insertions(+), 27 deletions(-)
> 
> diff --git a/src/tuning/tuning.cpp b/src/tuning/tuning.cpp
> index 4893597..541e9e0 100644
> --- a/src/tuning/tuning.cpp
> +++ b/src/tuning/tuning.cpp
> @@ -28,7 +28,7 @@
>  #include <stdio.h>
>  #include <string.h>
>  #include <ncurses.h>
> -
> +#include <math.h>
>  
>  #include "tuning.h"
>  #include "tuningsysfs.h"
> @@ -79,48 +79,81 @@ void initialize_tuning(void)
>  	create_tab("Tunables", _("Tunables"), w, _(" <ESC> Exit | <Enter> Toggle tunable | <r> Window refresh"));
>  
>  	init_tuning();
> -
>  	w->cursor_max = all_tunables.size() - 1;
>  }
>  
> +#define XINDENT	3
> +#define YINDENT	4
> +#define MAX_LEN	4096
>  
> +static void redraw_window(WINDOW *win, int begin, int end, int cursor_pos)
> +{
> +	int x, y, i;
> +	getmaxyx(stdscr, y, x);
> +	
> +	wclrtoeol(win);
> +	wmove(win, 1, 0);
> +	x %= MAX_LEN;
> +
> +	for (y = 0, i = begin; i < end; i++, y++) {
> +		char truncate = 0;
> +		size_t sz = 0;
> +		char line[x + 1];
> +		if ((int)(y) != cursor_pos) {
> +			wattrset(win, A_NORMAL);
> +			sz = snprintf(line, x, "   ");
> +		} else {
> +			wattrset(win, A_REVERSE);
> +			sz = snprintf(line, x, ">> ");
> +		}
> +		sz += snprintf(line + sz, x, "%s", all_tunables[i]->result_string());
> +		while (sz < 12)
> +			sz += snprintf(line + sz, x, " ");
> +		sz += snprintf(line + sz, x, "%s", all_tunables[i]->description());
> +		if ((int)sz > x - XINDENT)
> +			truncate = 1;
> +		while ((int)sz < x - XINDENT)
> +			sz += snprintf(line + sz, x, " ");
> +		if (truncate)
> +			sz += snprintf(line + x - XINDENT - 1, x, "~\n");
> +		else
> +			sz += snprintf(line + sz, x, "\n");
> +
> +		waddnstr(win, line, sz);
> +	}
> +}
>  
>  static void __tuning_update_display(int cursor_pos)
>  {
> +	static int last_frame_nr = 0;
> +	int x, y, begin, end, frame_nr;
>  	WINDOW *win;
> -	unsigned int i;
> -
> +        
>  	win = get_ncurses_win("Tunables");
> -
>  	if (!win)
>  		return;
> +	getmaxyx(stdscr, y, x);
> +
> +	y -= YINDENT;
> +	frame_nr = ceil(cursor_pos / y);
> +	end = (frame_nr + 1) * y;
> +	if (end > (int)all_tunables.size())
> +		end = all_tunables.size();
> +
> +	begin = frame_nr * y;
> +	/* actual cursor position is frame-dependent */
> +	cursor_pos -= frame_nr * y;
> +	if (frame_nr != last_frame_nr)
> +		should_clear = TRUE;
> +	last_frame_nr = frame_nr;
>  
>  	if (should_clear) {
> -		should_clear = false;
> +		should_clear = FALSE;
>  		wclear(win);
>  	}
>  
> -	wmove(win, 2,0);
> -
> -	for (i = 0; i < all_tunables.size(); i++) {
> -		char res[128];
> -		char desc[4096];
> -		strcpy(res, all_tunables[i]->result_string());
> -		strcpy(desc, all_tunables[i]->description());
> -		while (strlen(res) < 12)
> -			strcat(res, " ");
> -
> -		while (strlen(desc) < 103)
> -			strcat(desc, " ");
> -		if ((int)i != cursor_pos) {
> -			wattrset(win, A_NORMAL);
> -			wprintw(win, "   ");
> -		} else {
> -			wattrset(win, A_REVERSE);
> -			wprintw(win, ">> ");
> -		}
> -		wprintw(win, "%s  %s\n", _(res), _(desc));
> -	}
> +	redraw_window(win, begin, end, cursor_pos);
> +	wnoutrefresh(win);
>  }
>  
>  void tuning_update_display(void)
> 
> _______________________________________________
> PowerTop mailing list
> PowerTop(a)lists.01.org
> https://lists.01.org/mailman/listinfo/powertop



^ permalink raw reply	[flat|nested] 9+ messages in thread
* [Powertop] [PATCH] tuninig: resize scaling support (v1)
@ 2012-08-22 22:47 Sergey Senozhatsky
  0 siblings, 0 replies; 9+ messages in thread
From: Sergey Senozhatsky @ 2012-08-22 22:47 UTC (permalink / raw)
  To: powertop

[-- Attachment #1: Type: text/plain, Size: 3514 bytes --]

tuninig: resize scaling support v1

Initial version of terminal window resize support for tuning tab.
Supports both X and Y scalings:
-- X scaling: truncation (*)
* tunable result and description strings are now stored in dynamic
array, limited in size to current window X (mod MAX_LEN).

-- Y scaling: paging and scrolling


Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky(a)gmail.com>

---

 src/tuning/tuning.cpp | 87 +++++++++++++++++++++++++++++++++++----------------
 1 file changed, 60 insertions(+), 27 deletions(-)

diff --git a/src/tuning/tuning.cpp b/src/tuning/tuning.cpp
index 4893597..541e9e0 100644
--- a/src/tuning/tuning.cpp
+++ b/src/tuning/tuning.cpp
@@ -28,7 +28,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <ncurses.h>
-
+#include <math.h>
 
 #include "tuning.h"
 #include "tuningsysfs.h"
@@ -79,48 +79,81 @@ void initialize_tuning(void)
 	create_tab("Tunables", _("Tunables"), w, _(" <ESC> Exit | <Enter> Toggle tunable | <r> Window refresh"));
 
 	init_tuning();
-
 	w->cursor_max = all_tunables.size() - 1;
 }
 
+#define XINDENT	3
+#define YINDENT	4
+#define MAX_LEN	4096
 
+static void redraw_window(WINDOW *win, int begin, int end, int cursor_pos)
+{
+	int x, y, i;
+	getmaxyx(stdscr, y, x);
+	
+	wclrtoeol(win);
+	wmove(win, 1, 0);
+	x %= MAX_LEN;
+
+	for (y = 0, i = begin; i < end; i++, y++) {
+		char truncate = 0;
+		size_t sz = 0;
+		char line[x + 1];
+		if ((int)(y) != cursor_pos) {
+			wattrset(win, A_NORMAL);
+			sz = snprintf(line, x, "   ");
+		} else {
+			wattrset(win, A_REVERSE);
+			sz = snprintf(line, x, ">> ");
+		}
+		sz += snprintf(line + sz, x, "%s", all_tunables[i]->result_string());
+		while (sz < 12)
+			sz += snprintf(line + sz, x, " ");
+		sz += snprintf(line + sz, x, "%s", all_tunables[i]->description());
+		if ((int)sz > x - XINDENT)
+			truncate = 1;
+		while ((int)sz < x - XINDENT)
+			sz += snprintf(line + sz, x, " ");
+		if (truncate)
+			sz += snprintf(line + x - XINDENT - 1, x, "~\n");
+		else
+			sz += snprintf(line + sz, x, "\n");
+
+		waddnstr(win, line, sz);
+	}
+}
 
 static void __tuning_update_display(int cursor_pos)
 {
+	static int last_frame_nr = 0;
+	int x, y, begin, end, frame_nr;
 	WINDOW *win;
-	unsigned int i;
-
+        
 	win = get_ncurses_win("Tunables");
-
 	if (!win)
 		return;
+	getmaxyx(stdscr, y, x);
+
+	y -= YINDENT;
+	frame_nr = ceil(cursor_pos / y);
+	end = (frame_nr + 1) * y;
+	if (end > (int)all_tunables.size())
+		end = all_tunables.size();
+
+	begin = frame_nr * y;
+	/* actual cursor position is frame-dependent */
+	cursor_pos -= frame_nr * y;
+	if (frame_nr != last_frame_nr)
+		should_clear = TRUE;
+	last_frame_nr = frame_nr;
 
 	if (should_clear) {
-		should_clear = false;
+		should_clear = FALSE;
 		wclear(win);
 	}
 
-	wmove(win, 2,0);
-
-	for (i = 0; i < all_tunables.size(); i++) {
-		char res[128];
-		char desc[4096];
-		strcpy(res, all_tunables[i]->result_string());
-		strcpy(desc, all_tunables[i]->description());
-		while (strlen(res) < 12)
-			strcat(res, " ");
-
-		while (strlen(desc) < 103)
-			strcat(desc, " ");
-		if ((int)i != cursor_pos) {
-			wattrset(win, A_NORMAL);
-			wprintw(win, "   ");
-		} else {
-			wattrset(win, A_REVERSE);
-			wprintw(win, ">> ");
-		}
-		wprintw(win, "%s  %s\n", _(res), _(desc));
-	}
+	redraw_window(win, begin, end, cursor_pos);
+	wnoutrefresh(win);
 }
 
 void tuning_update_display(void)


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2012-09-11 16:53 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-24 15:56 [Powertop] [PATCH] tuninig: resize scaling support (v1) Chris Ferron
  -- strict thread matches above, loose matches on Subject: below --
2012-09-11 16:53 Sergey Senozhatsky
2012-09-11 16:40 Chris Ferron
2012-08-23 20:53 Sergey Senozhatsky
2012-08-23 16:57 Chris Ferron
2012-08-23  9:12 Sergey Senozhatsky
2012-08-23  8:04 Sergey Senozhatsky
2012-08-23  4:22 Magnus Fromreide
2012-08-22 22:47 Sergey Senozhatsky

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.