mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Disable single character mode in the terminal when exiting flutter_tools (#146534)
This commit is contained in:
parent
aff5477dad
commit
c9d4c749b5
@ -136,6 +136,7 @@ Future<void> main(List<String> args) async {
|
|||||||
// So that we don't animate anything before calling applyFeatureFlags, default
|
// So that we don't animate anything before calling applyFeatureFlags, default
|
||||||
// the animations to disabled in real apps.
|
// the animations to disabled in real apps.
|
||||||
defaultCliAnimationEnabled: false,
|
defaultCliAnimationEnabled: false,
|
||||||
|
shutdownHooks: globals.shutdownHooks,
|
||||||
);
|
);
|
||||||
// runner.run calls "terminal.applyFeatureFlags()"
|
// runner.run calls "terminal.applyFeatureFlags()"
|
||||||
},
|
},
|
||||||
|
@ -7,6 +7,7 @@ import '../features.dart';
|
|||||||
import 'io.dart' as io;
|
import 'io.dart' as io;
|
||||||
import 'logger.dart';
|
import 'logger.dart';
|
||||||
import 'platform.dart';
|
import 'platform.dart';
|
||||||
|
import 'process.dart';
|
||||||
|
|
||||||
enum TerminalColor {
|
enum TerminalColor {
|
||||||
red,
|
red,
|
||||||
@ -164,11 +165,14 @@ class AnsiTerminal implements Terminal {
|
|||||||
required Platform platform,
|
required Platform platform,
|
||||||
DateTime? now, // Time used to determine preferredStyle. Defaults to 0001-01-01 00:00.
|
DateTime? now, // Time used to determine preferredStyle. Defaults to 0001-01-01 00:00.
|
||||||
bool defaultCliAnimationEnabled = true,
|
bool defaultCliAnimationEnabled = true,
|
||||||
|
ShutdownHooks? shutdownHooks,
|
||||||
})
|
})
|
||||||
: _stdio = stdio,
|
: _stdio = stdio,
|
||||||
_platform = platform,
|
_platform = platform,
|
||||||
_now = now ?? DateTime(1),
|
_now = now ?? DateTime(1),
|
||||||
_isCliAnimationEnabled = defaultCliAnimationEnabled;
|
_isCliAnimationEnabled = defaultCliAnimationEnabled {
|
||||||
|
shutdownHooks?.addShutdownHook(() { singleCharMode = false; });
|
||||||
|
}
|
||||||
|
|
||||||
final io.Stdio _stdio;
|
final io.Stdio _stdio;
|
||||||
final Platform _platform;
|
final Platform _platform;
|
||||||
@ -319,7 +323,7 @@ class AnsiTerminal implements Terminal {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final io.Stdin stdin = _stdio.stdin as io.Stdin;
|
final io.Stdin stdin = _stdio.stdin as io.Stdin;
|
||||||
return stdin.lineMode && stdin.echoMode;
|
return !stdin.lineMode && !stdin.echoMode;
|
||||||
}
|
}
|
||||||
@override
|
@override
|
||||||
set singleCharMode(bool value) {
|
set singleCharMode(bool value) {
|
||||||
|
@ -243,6 +243,7 @@ final AnsiTerminal _defaultAnsiTerminal = AnsiTerminal(
|
|||||||
stdio: stdio,
|
stdio: stdio,
|
||||||
platform: platform,
|
platform: platform,
|
||||||
now: DateTime.now(),
|
now: DateTime.now(),
|
||||||
|
shutdownHooks: shutdownHooks,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// The global Stdio wrapper.
|
/// The global Stdio wrapper.
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
import 'package:flutter_tools/src/base/io.dart';
|
import 'package:flutter_tools/src/base/io.dart';
|
||||||
import 'package:flutter_tools/src/base/logger.dart';
|
import 'package:flutter_tools/src/base/logger.dart';
|
||||||
import 'package:flutter_tools/src/base/platform.dart';
|
import 'package:flutter_tools/src/base/platform.dart';
|
||||||
|
import 'package:flutter_tools/src/base/process.dart';
|
||||||
import 'package:flutter_tools/src/base/terminal.dart';
|
import 'package:flutter_tools/src/base/terminal.dart';
|
||||||
import 'package:test/fake.dart';
|
import 'package:test/fake.dart';
|
||||||
|
|
||||||
@ -264,6 +265,18 @@ void main() {
|
|||||||
);
|
);
|
||||||
terminal.singleCharMode = true;
|
terminal.singleCharMode = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWithoutContext('singleCharMode is reset by shutdown hook', () {
|
||||||
|
final ShutdownHooks shutdownHooks = ShutdownHooks();
|
||||||
|
final FakeStdio stdio = FakeStdio();
|
||||||
|
final AnsiTerminal terminal = AnsiTerminal(stdio: stdio, platform: const LocalPlatform(), shutdownHooks: shutdownHooks);
|
||||||
|
stdio.stdinHasTerminal = true;
|
||||||
|
stdio._stdin = FakeStdin();
|
||||||
|
|
||||||
|
terminal.singleCharMode = true;
|
||||||
|
shutdownHooks.runShutdownHooks(BufferLogger.test());
|
||||||
|
expect(terminal.singleCharMode, false);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
late Stream<String> mockStdInStream;
|
late Stream<String> mockStdInStream;
|
||||||
|
Loading…
Reference in New Issue
Block a user