opt.: shell_func only get useful mem data

This commit is contained in:
lollipopkit
2023-10-13 12:48:54 +08:00
parent 7388ad4524
commit a2bb4f1287
11 changed files with 43 additions and 52 deletions

View File

@@ -1,13 +1,11 @@
class Memory {
final int total;
final int free;
final int cache;
final int avail;
const Memory({
required this.total,
required this.free,
required this.cache,
required this.avail,
});
@@ -46,16 +44,6 @@ Memory parseMem(String raw) {
'0',
) ??
0;
final cached = int.tryParse(
items
.firstWhere(
(e) => e?.group(1) == 'Cached:',
orElse: () => null,
)
?.group(2) ??
'0',
) ??
0;
final available = int.tryParse(
items
.firstWhere(
@@ -70,7 +58,6 @@ Memory parseMem(String raw) {
return Memory(
total: total,
free: free,
cache: cached,
avail: available,
);
}

View File

@@ -20,12 +20,14 @@ enum SystemType {
return null;
}
bool isSegmentsLenMatch(int len) {
bool isSegmentsLenMatch(int len) => len == segmentsLen;
int get segmentsLen {
switch (this) {
case SystemType.linux:
return len == StatusCmdType.values.length;
return StatusCmdType.values.length;
case SystemType.bsd:
return len == BSDStatusCmdType.values.length;
return BSDStatusCmdType.values.length;
}
}
}