Skip to content

Commit

Permalink
AddUsbManagerOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
victor7w7r committed Mar 27, 2024
1 parent 03fbe33 commit 172ca4a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 25 deletions.
21 changes: 9 additions & 12 deletions usb_manager/bin/usb_manager.dart
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
import 'dart:async' show unawaited;
import 'dart:io' show exit;

import 'package:console/console.dart' show Chooser;
import 'package:cli_menu/cli_menu.dart' show Menu;
import 'package:fpdart/fpdart.dart' show IO;
import 'package:usb_manager/usb_manager.dart';

import 'package:zerothreesix_dart/zerothreesix_dart.dart';

import 'package:usb_manager/usb_manager.dart';

void _menu() {
cyan(lang(11));
IO(
Chooser<String>(
[lang(13), lang(14), lang(15), lang(16)],
message: lang(12),
).chooseSync,
).map((final sel) {
if (sel == lang(13)) {
Menu([lang(13), lang(14), lang(15), lang(16)]).choose,
).map((final op) {
if (op.value == lang(13)) {
clear();
unawaited(usblistener(Action.mount, _menu));
} else if (sel == lang(14)) {
} else if (op.value == lang(14)) {
clear();
unawaited(usblistener(Action.unmount, _menu));
} else if (sel == lang(15)) {
} else if (op.value == lang(15)) {
clear();
unawaited(usblistener(Action.off, _menu));
} else if (sel == lang(16)) {
} else if (op.value == lang(16)) {
clear();
exit(0);
}
Expand Down
17 changes: 7 additions & 10 deletions usb_manager/lib/usblistener.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:io' show stdin;

import 'package:console/console.dart' show Chooser;
import 'package:cli_menu/cli_menu.dart' show Menu;
import 'package:fpdart/fpdart.dart' show IO;
import 'package:zerothreesix_dart/zerothreesix_dart.dart';

Expand Down Expand Up @@ -96,24 +96,21 @@ Future<void> usblistener(
spinAction.cancel();

IO(
Chooser<String>(
action == Action.off ? argspoweroff : args,
message: lang(12),
).chooseSync,
).map((final sel) {
if (sel == lang(25)) {
Menu(action == Action.off ? argspoweroff : args).choose,
).map((final op) {
if (op.value == lang(25)) {
clear();
call();
return;
} else {
clear();
switch (action) {
case Action.mount:
usbAction(sel, true, call);
usbAction(op.value, true, call);
case Action.unmount:
usbAction(sel, false, call);
usbAction(op.value, false, call);
case Action.off:
powerOff(sel, call);
powerOff(op.value, call);
}
}
}).run();
Expand Down
4 changes: 2 additions & 2 deletions usb_manager/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ packages:
source: hosted
version: "1.3.0"
cli_menu:
dependency: transitive
dependency: "direct main"
description:
name: cli_menu
sha256: "8e2ad533d6fa657bf944d943b948862f2c0cfcf1fa6568be9b65eef5573394bf"
Expand All @@ -34,7 +34,7 @@ packages:
source: hosted
version: "1.1.1"
console:
dependency: "direct main"
dependency: transitive
description:
name: console
sha256: e04e7824384c5b39389acdd6dc7d33f3efe6b232f6f16d7626f194f6a01ad69a
Expand Down
2 changes: 1 addition & 1 deletion usb_manager/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ environment:
sdk: '>=3.3.2 <4.0.0'

dependencies:
console: ^4.1.0
cli_menu: ^0.4.0+1
fpdart: ^1.1.0
zerothreesix_dart: ^0.1.3

Expand Down

0 comments on commit 172ca4a

Please sign in to comment.