All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Ferron <chris.e.ferron at linux.intel.com>
To: powertop@lists.01.org
Subject: Re: [Powertop] [PATCH] tuninig: resize scaling support (v1)
Date: Thu, 23 Aug 2012 09:57:43 -0700	[thread overview]
Message-ID: <50366107.5080509@linux.intel.com> (raw)
In-Reply-To: 20120823091245.GA3065@swordfish.minsk.epam.com

[-- 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


             reply	other threads:[~2012-08-23 16:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-23 16:57 Chris Ferron [this message]
  -- strict thread matches above, loose matches on Subject: below --
2012-09-11 16:53 [Powertop] [PATCH] tuninig: resize scaling support (v1) Sergey Senozhatsky
2012-09-11 16:40 Chris Ferron
2012-08-24 15:56 Chris Ferron
2012-08-23 20:53 Sergey Senozhatsky
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50366107.5080509@linux.intel.com \
    --to=powertop@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.