--sort-key flag in the command-line, overriding the

saved setting in .htoprc for the session.
(thanks to Rodolfo Borges)
This commit is contained in:
Hisham Muhammad 2006-08-04 20:54:37 +00:00
parent bf44e233e6
commit b10821aae9
6 changed files with 41 additions and 9 deletions

View File

@ -1,4 +1,10 @@
What's new in version 0.6.4
* --sort-key flag in the command-line, overriding the
saved setting in .htoprc for the session.
(thanks to Rodolfo Borges)
What's new in version 0.6.3
* Performance improvements: uses much less CPU than the

View File

@ -44,6 +44,15 @@ void ColumnsPanel_delete(Object* object) {
free(this);
}
int ColumnsPanel_fieldNameToIndex(const char* name) {
for (int j = 1; j <= LAST_PROCESSFIELD; j++) {
if (String_eq(name, Process_fieldNames[j])) {
return j;
}
}
return 0;
}
void ColumnsPanel_update(Panel* super) {
ColumnsPanel* this = (ColumnsPanel*) super;
int size = Panel_getSize(super);
@ -53,12 +62,9 @@ void ColumnsPanel_update(Panel* super) {
this->settings->pl->fields = (ProcessField*) malloc(sizeof(ProcessField) * (size+1));
for (int i = 0; i < size; i++) {
char* text = ((ListItem*) Panel_get(super, i))->value;
for (int j = 1; j <= LAST_PROCESSFIELD; j++) {
if (String_eq(text, Process_fieldNames[j])) {
this->settings->pl->fields[i] = j;
break;
}
}
int j = ColumnsPanel_fieldNameToIndex(text);
if (j > 0)
this->settings->pl->fields[i] = j;
}
this->settings->pl->fields[size] = 0;
}
@ -83,7 +89,7 @@ HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch) {
case ']':
case '+':
{
if (selected < size - 2)
if (selected < size - 2)
Panel_moveSelectedDown(super);
result = HANDLED;
break;

View File

@ -24,6 +24,8 @@ ColumnsPanel* ColumnsPanel_new(Settings* settings, ScreenManager* scr);
void ColumnsPanel_delete(Object* object);
int ColumnsPanel_fieldNameToIndex(const char* name);
void ColumnsPanel_update(Panel* super);
HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch);

View File

@ -96,7 +96,7 @@ void String_printPointer(void* p) {
printf("%p", p);
}
inline int String_eq(char* s1, char* s2) {
inline int String_eq(const char* s1, const char* s2) {
if (s1 == NULL || s2 == NULL) {
if (s1 == NULL && s2 == NULL)
return 1;

View File

@ -39,7 +39,7 @@ void String_printInt(int i);
void String_printPointer(void* p);
inline int String_eq(char* s1, char* s2);
inline int String_eq(const char* s1, const char* s2);
char** String_split(char* s, char sep);

18
htop.c
View File

@ -46,6 +46,7 @@ void printHelpFlag() {
printf("Released under the GNU GPL.\n\n");
printf("-d DELAY Delay between updates, in tenths of seconds\n\n");
printf("-u USERNAME Show only processes of a given user\n\n");
printf("--sort-key COLUMN Sort by this column (use --sort-key help for a column list)\n\n");
printf("Press F1 inside htop for online help.\n");
printf("See the man page for full information.\n\n");
exit(0);
@ -194,12 +195,25 @@ int main(int argc, char** argv) {
int delay = -1;
bool userOnly = false;
uid_t userId = 0;
int sortKey = 0;
if (argc > 0) {
if (String_eq(argv[1], "--help")) {
printHelpFlag();
} else if (String_eq(argv[1], "--version")) {
printVersionFlag();
} else if (String_eq(argv[1], "--sort-key")) {
if (argc < 2) printHelpFlag();
if (String_eq(argv[2], "help")) {
for (int j = 1; j < LAST_PROCESSFIELD; j++)
printf ("%s\n", Process_fieldNames[j]);
exit(0);
}
sortKey = ColumnsPanel_fieldNameToIndex(argv[2]);
if (sortKey == -1) {
fprintf(stderr, "Error: invalid column \"%s\".\n", argv[2]);
exit(1);
}
} else if (String_eq(argv[1], "-d")) {
if (argc < 2) printHelpFlag();
sscanf(argv[2], "%d", &delay);
@ -237,6 +251,10 @@ int main(int argc, char** argv) {
Header* header = Header_new(pl);
settings = Settings_new(pl, header);
if (sortKey > 0) {
pl->sortKey = sortKey;
pl->treeView = false;
}
int headerHeight = Header_calculateHeight(header);
// FIXME: move delay code to settings