Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
016ca1a0
Unverified
Commit
016ca1a0
authored
Oct 23, 2019
by
Jonah Williams
Committed by
GitHub
Oct 23, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Catch io.StdinException from failure to set stdin echo/line mode (#43225)
parent
79a985f9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
11 deletions
+56
-11
io.dart
packages/flutter_tools/lib/src/base/io.dart
+32
-1
terminal.dart
packages/flutter_tools/lib/src/base/terminal.dart
+11
-10
terminal_test.dart
.../flutter_tools/test/general.shard/base/terminal_test.dart
+13
-0
No files found.
packages/flutter_tools/lib/src/base/io.dart
View file @
016ca1a0
...
...
@@ -27,7 +27,7 @@
/// in `dart:io` can sometimes be hard to use in tests.
import
'dart:async'
;
import
'dart:io'
as
io
show
exit
,
IOSink
,
Process
,
ProcessInfo
,
ProcessSignal
,
stderr
,
stdin
,
Stdout
,
stdout
;
stderr
,
stdin
,
Std
in
,
StdinException
,
Std
out
,
stdout
;
import
'package:meta/meta.dart'
;
...
...
@@ -181,6 +181,36 @@ class Stdio {
io
.
IOSink
get
stderr
=>
io
.
stderr
;
bool
get
hasTerminal
=>
io
.
stdout
.
hasTerminal
;
static
bool
_stdinHasTerminal
;
/// Determines whether there is a terminal attached.
///
/// [io.Stdin.hasTerminal] only covers a subset of cases. In this check the
/// echoMode is toggled on and off to catch cases where the tool running in
/// a docker container thinks there is an attached terminal. This can cause
/// runtime errors such as "inappropriate ioctl for device" if not handled.
bool
get
stdinHasTerminal
{
if
(
_stdinHasTerminal
!=
null
)
{
return
_stdinHasTerminal
;
}
if
(
stdin
is
!
io
.
Stdin
)
{
return
_stdinHasTerminal
=
false
;
}
final
io
.
Stdin
ioStdin
=
stdin
;
if
(!
ioStdin
.
hasTerminal
)
{
return
_stdinHasTerminal
=
false
;
}
try
{
final
bool
currentEchoMode
=
ioStdin
.
echoMode
;
ioStdin
.
echoMode
=
!
currentEchoMode
;
ioStdin
.
echoMode
=
currentEchoMode
;
}
on
io
.
StdinException
{
return
_stdinHasTerminal
=
false
;
}
return
_stdinHasTerminal
=
true
;
}
int
get
terminalColumns
=>
hasTerminal
?
io
.
stdout
.
terminalColumns
:
null
;
int
get
terminalLines
=>
hasTerminal
?
io
.
stdout
.
terminalLines
:
null
;
bool
get
supportsAnsiEscapes
=>
hasTerminal
&&
io
.
stdout
.
supportsAnsiEscapes
;
...
...
@@ -190,6 +220,7 @@ Stdio get stdio => context.get<Stdio>() ?? const Stdio();
io
.
Stdout
get
stdout
=>
stdio
.
stdout
;
Stream
<
List
<
int
>>
get
stdin
=>
stdio
.
stdin
;
io
.
IOSink
get
stderr
=>
stdio
.
stderr
;
bool
get
stdinHasTerminal
=>
stdio
.
stdinHasTerminal
;
/// An overridable version of io.ProcessInfo.
abstract
class
ProcessInfo
{
...
...
packages/flutter_tools/lib/src/base/terminal.dart
View file @
016ca1a0
...
...
@@ -155,16 +155,17 @@ class AnsiTerminal {
String
clearScreen
()
=>
supportsColor
?
clear
:
'
\n\n
'
;
set
singleCharMode
(
bool
value
)
{
final
Stream
<
List
<
int
>>
stdin
=
io
.
stdin
;
if
(
stdin
is
io
.
Stdin
&&
stdin
.
hasTerminal
)
{
// The order of setting lineMode and echoMode is important on Windows.
if
(
value
)
{
stdin
.
echoMode
=
false
;
stdin
.
lineMode
=
false
;
}
else
{
stdin
.
lineMode
=
true
;
stdin
.
echoMode
=
true
;
}
if
(!
io
.
stdinHasTerminal
)
{
return
;
}
final
io
.
Stdin
stdin
=
io
.
stdin
;
// The order of setting lineMode and echoMode is important on Windows.
if
(
value
)
{
stdin
.
echoMode
=
false
;
stdin
.
lineMode
=
false
;
}
else
{
stdin
.
lineMode
=
true
;
stdin
.
echoMode
=
true
;
}
}
...
...
packages/flutter_tools/test/general.shard/base/terminal_test.dart
View file @
016ca1a0
...
...
@@ -4,9 +4,11 @@
import
'dart:async'
;
import
'package:flutter_tools/src/base/io.dart'
;
import
'package:flutter_tools/src/base/platform.dart'
;
import
'package:flutter_tools/src/base/terminal.dart'
;
import
'package:flutter_tools/src/globals.dart'
;
import
'package:mockito/mockito.dart'
;
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
...
...
@@ -167,6 +169,15 @@ void main() {
'Please choose something:
\n
'
'
\n
'
);
});
testUsingContext
(
'Does not set single char mode when a terminal is not attached'
,
()
{
when
(
stdio
.
stdin
).
thenThrow
(
StateError
(
'This should not be called'
));
when
(
stdio
.
stdinHasTerminal
).
thenReturn
(
false
);
terminal
.
singleCharMode
=
true
;
},
overrides:
<
Type
,
Generator
>{
Stdio:
()
=>
MockStdio
(),
});
});
}
...
...
@@ -178,3 +189,5 @@ class TestTerminal extends AnsiTerminal {
return
mockStdInStream
;
}
}
class
MockStdio
extends
Mock
implements
Stdio
{}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment