Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
htop
Commits
ca6b9238
Commit
ca6b9238
authored
Nov 03, 2011
by
Hisham Muhammad
Browse files
Support for UTF-8 tree drawing
(thanks to Bin Guo)
parent
b45b9e2b
Changes
5
Show whitespace changes
Inline
Side-by-side
ChangeLog
View file @
ca6b9238
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
What's new in version 0.9.1
What's new in version 0.9.1
* Switch from PLPA, which is now deprecated, to HWLOC.
* Switch from PLPA, which is now deprecated, to HWLOC.
* Support for UTF-8 tree drawing
(thanks to Bin Guo)
* Option for counting CPUs from zero
* Option for counting CPUs from zero
(thanks to Sean Noonan)
(thanks to Sean Noonan)
* Meters update in every screen (no longer halting while on Setup, etc.)
* Meters update in every screen (no longer halting while on Setup, etc.)
...
...
Process.c
View file @
ca6b9238
...
@@ -387,21 +387,26 @@ static void Process_writeField(Process* this, RichString* str, ProcessField fiel
...
@@ -387,21 +387,26 @@ static void Process_writeField(Process* this, RichString* str, ProcessField fiel
}
else
{
}
else
{
char
*
buf
=
buffer
;
char
*
buf
=
buffer
;
int
maxIndent
=
0
;
int
maxIndent
=
0
;
const
char
**
treeStr
=
this
->
pl
->
treeStr
;
bool
lastItem
=
(
this
->
indent
<
0
);
int
indent
=
(
this
->
indent
<
0
?
-
this
->
indent
:
this
->
indent
);
if
(
treeStr
==
NULL
)
treeStr
=
ProcessList_treeStrAscii
;
for
(
int
i
=
0
;
i
<
32
;
i
++
)
for
(
int
i
=
0
;
i
<
32
;
i
++
)
if
(
this
->
indent
&
(
1
<<
i
))
if
(
indent
&
(
1
<<
i
))
maxIndent
=
i
+
1
;
maxIndent
=
i
+
1
;
for
(
int
i
=
0
;
i
<
maxIndent
-
1
;
i
++
)
{
for
(
int
i
=
0
;
i
<
maxIndent
-
1
;
i
++
)
{
if
(
this
->
indent
&
(
1
<<
i
))
int
written
;
snprintf
(
buf
,
n
,
" | "
);
if
(
indent
&
(
1
<<
i
))
written
=
snprintf
(
buf
,
n
,
"%s "
,
treeStr
[
TREE_STR_VERT
]);
else
else
snprintf
(
buf
,
n
,
"
"
);
written
=
snprintf
(
buf
,
n
,
" "
);
buf
+=
4
;
buf
+=
written
;
n
-=
4
;
n
-=
written
;
}
}
if
(
this
->
pl
->
direction
==
1
)
const
char
*
draw
=
treeStr
[
lastItem
?
(
this
->
pl
->
direction
==
1
?
TREE_STR_BEND
:
TREE_STR_TEND
)
:
TREE_STR_RTEE
];
snprintf
(
buf
,
n
,
" `%s "
,
this
->
showChildren
?
"-"
:
"+"
);
snprintf
(
buf
,
n
,
"%s%s "
,
draw
,
this
->
showChildren
?
treeStr
[
TREE_STR_SHUT
]
:
treeStr
[
TREE_STR_OPEN
]
);
else
snprintf
(
buf
,
n
,
" ,%s "
,
this
->
showChildren
?
"-"
:
"+"
);
RichString_append
(
str
,
CRT_colors
[
PROCESS_TREE
],
buffer
);
RichString_append
(
str
,
CRT_colors
[
PROCESS_TREE
],
buffer
);
Process_writeCommand
(
this
,
attr
,
baseattr
,
str
);
Process_writeCommand
(
this
,
attr
,
baseattr
,
str
);
return
;
return
;
...
...
ProcessList.c
View file @
ca6b9238
...
@@ -57,9 +57,23 @@ in the source distribution for its full text.
...
@@ -57,9 +57,23 @@ in the source distribution for its full text.
#ifndef ProcessList_cpuId
#ifndef ProcessList_cpuId
#define ProcessList_cpuId(pl, cpu) ((pl)->countCPUsFromZero ? (cpu) : (cpu)+1)
#define ProcessList_cpuId(pl, cpu) ((pl)->countCPUsFromZero ? (cpu) : (cpu)+1)
#endif
#endif
}*/
/*{
typedef enum TreeStr_ {
TREE_STR_HORZ,
TREE_STR_VERT,
TREE_STR_RTEE,
TREE_STR_BEND,
TREE_STR_TEND,
TREE_STR_OPEN,
TREE_STR_SHUT,
TREE_STR_COUNT
} TreeStr;
typedef enum TreeType_ {
TREE_TYPE_AUTO,
TREE_TYPE_ASCII,
TREE_TYPE_UTF8,
} TreeType;
typedef struct CPUData_ {
typedef struct CPUData_ {
unsigned long long int totalTime;
unsigned long long int totalTime;
...
@@ -132,12 +146,34 @@ typedef struct ProcessList_ {
...
@@ -132,12 +146,34 @@ typedef struct ProcessList_ {
bool highlightThreads;
bool highlightThreads;
bool detailedCPUTime;
bool detailedCPUTime;
bool countCPUsFromZero;
bool countCPUsFromZero;
const char **treeStr;
} ProcessList;
} ProcessList;
}*/
}*/
static
ProcessField
defaultHeaders
[]
=
{
PID
,
USER
,
PRIORITY
,
NICE
,
M_SIZE
,
M_RESIDENT
,
M_SHARE
,
STATE
,
PERCENT_CPU
,
PERCENT_MEM
,
TIME
,
COMM
,
0
};
static
ProcessField
defaultHeaders
[]
=
{
PID
,
USER
,
PRIORITY
,
NICE
,
M_SIZE
,
M_RESIDENT
,
M_SHARE
,
STATE
,
PERCENT_CPU
,
PERCENT_MEM
,
TIME
,
COMM
,
0
};
const
char
*
ProcessList_treeStrAscii
[
TREE_STR_COUNT
]
=
{
"-"
,
// TREE_STR_HORZ
"|"
,
// TREE_STR_VERT
"`"
,
// TREE_STR_RTEE
"`"
,
// TREE_STR_BEND
","
,
// TREE_STR_TEND
"+"
,
// TREE_STR_OPEN
"-"
,
// TREE_STR_SHUT
};
const
char
*
ProcessList_treeStrUtf8
[
TREE_STR_COUNT
]
=
{
"
\xe2\x94\x80
"
,
// TREE_STR_HORZ ─
"
\xe2\x94\x82
"
,
// TREE_STR_VERT │
"
\xe2\x94\x9c
"
,
// TREE_STR_RTEE ├
"
\xe2\x94\x94
"
,
// TREE_STR_BEND └
"
\xe2\x94\x8c
"
,
// TREE_STR_TEND ┌
"+"
,
// TREE_STR_OPEN +
"
\xe2\x94\x80
"
,
// TREE_STR_SHUT ─
};
ProcessList
*
ProcessList_new
(
UsersTable
*
usersTable
)
{
ProcessList
*
ProcessList_new
(
UsersTable
*
usersTable
)
{
ProcessList
*
this
;
ProcessList
*
this
;
this
=
calloc
(
sizeof
(
ProcessList
),
1
);
this
=
calloc
(
sizeof
(
ProcessList
),
1
);
...
@@ -194,6 +230,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable) {
...
@@ -194,6 +230,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable) {
this
->
highlightMegabytes
=
false
;
this
->
highlightMegabytes
=
false
;
this
->
detailedCPUTime
=
false
;
this
->
detailedCPUTime
=
false
;
this
->
countCPUsFromZero
=
false
;
this
->
countCPUsFromZero
=
false
;
this
->
treeStr
=
NULL
;
return
this
;
return
this
;
}
}
...
@@ -282,6 +319,9 @@ static void ProcessList_buildTree(ProcessList* this, pid_t pid, int level, int i
...
@@ -282,6 +319,9 @@ static void ProcessList_buildTree(ProcessList* this, pid_t pid, int level, int i
assert
(
this
->
processes2
->
items
==
s
+
1
);
(
void
)
s
;
assert
(
this
->
processes2
->
items
==
s
+
1
);
(
void
)
s
;
int
nextIndent
=
indent
|
(
1
<<
level
);
int
nextIndent
=
indent
|
(
1
<<
level
);
ProcessList_buildTree
(
this
,
process
->
pid
,
level
+
1
,
(
i
<
size
-
1
)
?
nextIndent
:
indent
,
direction
,
show
?
process
->
showChildren
:
false
);
ProcessList_buildTree
(
this
,
process
->
pid
,
level
+
1
,
(
i
<
size
-
1
)
?
nextIndent
:
indent
,
direction
,
show
?
process
->
showChildren
:
false
);
if
(
i
==
size
-
1
)
process
->
indent
=
-
nextIndent
;
else
process
->
indent
=
nextIndent
;
process
->
indent
=
nextIndent
;
}
}
Vector_delete
(
children
);
Vector_delete
(
children
);
...
...
ProcessList.h
View file @
ca6b9238
...
@@ -60,6 +60,22 @@ in the source distribution for its full text.
...
@@ -60,6 +60,22 @@ in the source distribution for its full text.
#define ProcessList_cpuId(pl, cpu) ((pl)->countCPUsFromZero ? (cpu) : (cpu)+1)
#define ProcessList_cpuId(pl, cpu) ((pl)->countCPUsFromZero ? (cpu) : (cpu)+1)
#endif
#endif
typedef
enum
TreeStr_
{
TREE_STR_HORZ
,
TREE_STR_VERT
,
TREE_STR_RTEE
,
TREE_STR_BEND
,
TREE_STR_TEND
,
TREE_STR_OPEN
,
TREE_STR_SHUT
,
TREE_STR_COUNT
}
TreeStr
;
typedef
enum
TreeType_
{
TREE_TYPE_AUTO
,
TREE_TYPE_ASCII
,
TREE_TYPE_UTF8
,
}
TreeType
;
typedef
struct
CPUData_
{
typedef
struct
CPUData_
{
unsigned
long
long
int
totalTime
;
unsigned
long
long
int
totalTime
;
...
@@ -132,9 +148,15 @@ typedef struct ProcessList_ {
...
@@ -132,9 +148,15 @@ typedef struct ProcessList_ {
bool
highlightThreads
;
bool
highlightThreads
;
bool
detailedCPUTime
;
bool
detailedCPUTime
;
bool
countCPUsFromZero
;
bool
countCPUsFromZero
;
const
char
**
treeStr
;
}
ProcessList
;
}
ProcessList
;
extern
const
char
*
ProcessList_treeStrAscii
[
TREE_STR_COUNT
];
extern
const
char
*
ProcessList_treeStrUtf8
[
TREE_STR_COUNT
];
ProcessList
*
ProcessList_new
(
UsersTable
*
usersTable
);
ProcessList
*
ProcessList_new
(
UsersTable
*
usersTable
);
void
ProcessList_delete
(
ProcessList
*
this
);
void
ProcessList_delete
(
ProcessList
*
this
);
...
...
htop.c
View file @
ca6b9238
...
@@ -263,6 +263,7 @@ int main(int argc, char** argv) {
...
@@ -263,6 +263,7 @@ int main(int argc, char** argv) {
bool
userOnly
=
false
;
bool
userOnly
=
false
;
uid_t
userId
=
0
;
uid_t
userId
=
0
;
int
usecolors
=
1
;
int
usecolors
=
1
;
TreeType
treeType
=
TREE_TYPE_AUTO
;
int
opt
,
opti
=
0
;
int
opt
,
opti
=
0
;
static
struct
option
long_opts
[]
=
static
struct
option
long_opts
[]
=
...
@@ -281,8 +282,10 @@ int main(int argc, char** argv) {
...
@@ -281,8 +282,10 @@ int main(int argc, char** argv) {
char
*
lc_ctype
=
getenv
(
"LC_CTYPE"
);
char
*
lc_ctype
=
getenv
(
"LC_CTYPE"
);
if
(
lc_ctype
!=
NULL
)
if
(
lc_ctype
!=
NULL
)
setlocale
(
LC_CTYPE
,
lc_ctype
);
setlocale
(
LC_CTYPE
,
lc_ctype
);
else
if
((
lc_ctype
=
getenv
(
"LC_ALL"
)))
setlocale
(
LC_CTYPE
,
lc_ctype
);
else
else
setlocale
(
LC_CTYPE
,
getenv
(
"LC_ALL"
)
);
setlocale
(
LC_CTYPE
,
""
);
/* Parse arguments */
/* Parse arguments */
while
((
opt
=
getopt_long
(
argc
,
argv
,
"hvCs:d:u:"
,
long_opts
,
&
opti
)))
{
while
((
opt
=
getopt_long
(
argc
,
argv
,
"hvCs:d:u:"
,
long_opts
,
&
opti
)))
{
...
@@ -362,6 +365,34 @@ int main(int argc, char** argv) {
...
@@ -362,6 +365,34 @@ int main(int argc, char** argv) {
if
(
!
usecolors
)
if
(
!
usecolors
)
settings
->
colorScheme
=
COLORSCHEME_MONOCHROME
;
settings
->
colorScheme
=
COLORSCHEME_MONOCHROME
;
if
(
treeType
==
TREE_TYPE_AUTO
)
{
#ifdef HAVE_LIBNCURSESW
char
*
locale
=
setlocale
(
LC_ALL
,
NULL
);
if
(
locale
==
NULL
||
locale
[
0
]
==
'\0'
)
locale
=
setlocale
(
LC_CTYPE
,
NULL
);
if
(
locale
!=
NULL
&&
(
strstr
(
locale
,
"UTF-8"
)
||
strstr
(
locale
,
"utf-8"
)
||
strstr
(
locale
,
"UTF8"
)
||
strstr
(
locale
,
"utf8"
)))
treeType
=
TREE_TYPE_UTF8
;
else
treeType
=
TREE_TYPE_ASCII
;
#else
treeType
=
TREE_TYPE_ASCII
;
#endif
}
switch
(
treeType
)
{
default:
case
TREE_TYPE_ASCII
:
pl
->
treeStr
=
ProcessList_treeStrAscii
;
break
;
case
TREE_TYPE_UTF8
:
pl
->
treeStr
=
ProcessList_treeStrUtf8
;
break
;
}
CRT_init
(
settings
->
delay
,
settings
->
colorScheme
);
CRT_init
(
settings
->
delay
,
settings
->
colorScheme
);
panel
=
Panel_new
(
0
,
headerHeight
,
COLS
,
LINES
-
headerHeight
-
2
,
PROCESS_CLASS
,
false
,
NULL
);
panel
=
Panel_new
(
0
,
headerHeight
,
COLS
,
LINES
-
headerHeight
-
2
,
PROCESS_CLASS
,
false
,
NULL
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment