new & opt.

- new: support suspend and WOL #172
- opt.: `execWithPwd` when cancel
- opt.: extentions
This commit is contained in:
lollipopkit
2023-09-25 18:51:14 +08:00
parent df84aeb8b2
commit 4d06a52e99
45 changed files with 251 additions and 176 deletions

View File

@@ -56,7 +56,7 @@ extension DialogX on BuildContext {
void showSnippetDialog(
void Function(Snippet s) onSelected,
) {
if (Providers.snippet.snippets.isEmpty) {
if (Pros.snippet.snippets.isEmpty) {
showRoundDialog(
child: Text(l10n.noSavedSnippet),
actions: [
@@ -76,12 +76,12 @@ extension DialogX on BuildContext {
return;
}
var snippet = Providers.snippet.snippets.first;
var snippet = Pros.snippet.snippets.first;
showRoundDialog(
title: Text(l10n.choose),
child: Picker(
items: Providers.snippet.snippets.map((e) => Text(e.name)).toList(),
onSelected: (idx) => snippet = Providers.snippet.snippets[idx],
items: Pros.snippet.snippets.map((e) => Text(e.name)).toList(),
onSelected: (idx) => snippet = Pros.snippet.snippets[idx],
),
actions: [
TextButton(

View File

@@ -74,9 +74,11 @@ extension SSHClientX on SSHClient {
if (context == null) return;
final pwd = await context.showPwdDialog(user);
if (pwd == null || pwd.isEmpty) {
return;
// Add ctrl + c to exit.
sink.add('\x03'.uint8List);
} else {
sink.add('$pwd\n'.uint8List);
}
sink.add('$pwd\n'.uint8List);
}
},
onStdout: onStdout,

View File

@@ -14,52 +14,5 @@ extension StringX on String {
return Color(val);
}
int get i => int.parse(this);
Uri get uri {
return Uri.parse(this);
}
Widget omitStartStr({
TextStyle? style,
TextOverflow? overflow,
int? maxLines,
}) {
return LayoutBuilder(builder: (context, size) {
bool exceeded = false;
int len = 0;
for (; !exceeded && len < length; len++) {
// Build the textspan
var span = TextSpan(
text: 'A' * 7 + substring(length - len),
style: style ?? Theme.of(context).textTheme.bodyMedium,
);
// Use a textpainter to determine if it will exceed max lines
var tp = TextPainter(
maxLines: maxLines ?? 1,
textDirection: TextDirection.ltr,
text: span,
);
// trigger it to layout
tp.layout(maxWidth: size.maxWidth);
// whether the text overflowed or not
exceeded = tp.didExceedMaxLines;
}
return Text(
(exceeded ? '...' : '') + substring(length - len),
overflow: overflow ?? TextOverflow.fade,
softWrap: false,
maxLines: maxLines ?? 1,
style: style,
);
});
}
String get withLangExport => 'export LANG=en_US.UTF-8 && $this';
Uint8List get uint8List => Uint8List.fromList(utf8.encode(this));
}