new & opt

new: `net` total in & out bytes
opt: i18n for `ssh`
opt: disk path ignore
This commit is contained in:
lollipopkit
2023-02-02 13:11:21 +08:00
parent 469b9fe8cd
commit c479d18714
10 changed files with 103 additions and 72 deletions

View File

@@ -1,3 +1,5 @@
import '../../res/misc.dart';
class DiskInfo {
/*
{
@@ -26,3 +28,24 @@ class DiskInfo {
this.avail,
);
}
List<DiskInfo> parseDisk(String raw) {
final list = <DiskInfo>[];
final items = raw.split('\n');
items.removeAt(0);
for (var item in items) {
if (item.isEmpty) {
continue;
}
final vals = item.split(numReg);
list.add(DiskInfo(
vals[0],
vals[5],
int.parse(vals[4].replaceFirst('%', '')),
vals[2],
vals[1],
vals[3],
));
}
return list;
}

View File

@@ -36,6 +36,13 @@ class NetSpeed {
return buildStandardOutput(speedInBytesPerSecond);
}
String totalIn({String? device}) {
if (_old[0].device == '' || _now[0].device == '') return '0kb';
final idx = deviceIdx(device);
final totalInBytes = _now[idx].bytesIn;
return totalInBytes.toInt().convertBytes;
}
String speedOut({String? device}) {
if (_old[0].device == '' || _now[0].device == '') return '0kb/s';
final idx = deviceIdx(device);
@@ -44,6 +51,13 @@ class NetSpeed {
return buildStandardOutput(speedOutBytesPerSecond);
}
String totalOut({String? device}) {
if (_old[0].device == '' || _now[0].device == '') return '0kb';
final idx = deviceIdx(device);
final totalOutBytes = _now[idx].bytesOut;
return totalOutBytes.toInt().convertBytes;
}
int deviceIdx(String? device) {
if (device != null) {
for (var item in _now) {
@@ -55,10 +69,15 @@ class NetSpeed {
return 0;
}
String buildStandardOutput(double speed) =>
'${speed.convertBytes.toLowerCase()}/s';
String buildStandardOutput(double speed) => '${speed.convertBytes}/s';
}
/// [raw] example:
/// Inter-| Receive | Transmit
/// face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
/// lo: 45929941 269112 0 0 0 0 0 0 45929941 269112 0 0 0 0 0 0
/// eth0: 48481023 505772 0 0 0 0 0 0 36002262 202307 0 0 0 0 0 0
/// 1635752901
List<NetSpeedPart> parseNetSpeed(String raw) {
final split = raw.split('\n');
if (split.length < 4) {

View File

@@ -1,4 +1,5 @@
import '../../../core/extension/stringx.dart';
import '../../res/misc.dart';
///
/// Code generated by jsonToDartModel https://ashamp.github.io/jsonToDartModel/
@@ -42,8 +43,6 @@ class TcpStatus {
}
}
final numReg = RegExp(r'\s{1,}');
TcpStatus? parseTcp(String raw) {
final lines = raw.split('\n');
final idx = lines.lastWhere((element) => element.startsWith('Tcp:'),