Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose readOnly flag of CustomTextEdit in TerminalView #123

Merged
merged 2 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/src/terminal_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class TerminalView extends StatefulWidget {
this.alwaysShowCursor = false,
this.deleteDetection = false,
this.shortcuts,
this.readOnly = false,
}) : super(key: key);

/// The underlying terminal that this widget renders.
Expand Down Expand Up @@ -115,6 +116,9 @@ class TerminalView extends StatefulWidget {
/// of the terminal If not provided, [defaultTerminalShortcuts] will be used.
final Map<ShortcutActivator, Intent>? shortcuts;

/// True if no input should send to the terminal.
final bool readOnly;

@override
State<TerminalView> createState() => TerminalViewState();
}
Expand Down Expand Up @@ -219,6 +223,7 @@ class TerminalViewState extends State<TerminalView> {
}
},
onKey: _onKeyEvent,
readOnly: widget.readOnly,
child: child,
);

Expand Down
44 changes: 44 additions & 0 deletions test/src/terminal_view_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import 'package:xterm/xterm.dart';
import '../_fixture/_fixture.dart';

void main() {
final binding = TestWidgetsFlutterBinding.ensureInitialized();

testWidgets(
'Golden test',
(WidgetTester tester) async {
Expand All @@ -27,4 +29,46 @@ void main() {
},
skip: !Platform.isMacOS,
);

group('TerminalView.readOnly', () {
testWidgets('works', (WidgetTester tester) async {
final terminalOutput = <String>[];
final terminal = Terminal(onOutput: terminalOutput.add);

await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: TerminalView(terminal, readOnly: true, autofocus: true),
),
));

// https://github.com/flutter/flutter/issues/11181#issuecomment-314936646
await tester.tap(find.byType(TerminalView));
await tester.pump(Duration(seconds: 1));

binding.testTextInput.enterText('ls -al');
await binding.idle();

expect(terminalOutput.join(), isEmpty);
});

testWidgets('does not block input when false', (WidgetTester tester) async {
final terminalOutput = <String>[];
final terminal = Terminal(onOutput: terminalOutput.add);

await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: TerminalView(terminal, readOnly: false, autofocus: true),
),
));

// https://github.com/flutter/flutter/issues/11181#issuecomment-314936646
await tester.tap(find.byType(TerminalView));
await tester.pump(Duration(seconds: 1));

binding.testTextInput.enterText('ls -al');
await binding.idle();

expect(terminalOutput.join(), 'ls -al');
});
});
}