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

adds check if the TerminalIsolate has already been started #77

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
2 changes: 1 addition & 1 deletion example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:name="${applicationName}"
android:label="example"
android:icon="@mipmap/ic_launcher">
<activity
Expand Down
53 changes: 41 additions & 12 deletions example/lib/isolate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:xterm/flutter.dart';
import 'package:xterm/isolate.dart';
import 'package:xterm/theme/terminal_theme.dart';
import 'package:xterm/theme/terminal_themes.dart';
import 'package:xterm/xterm.dart';

void main() {
Expand All @@ -18,13 +20,23 @@ class MyApp extends StatelessWidget {
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(),
home: MyHomePage(
theme: TerminalThemes.defaultTheme,
terminalOpacity: 0.8,
),
);
}
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key}) : super(key: key);
MyHomePage({
Key? key,
required this.theme,
required this.terminalOpacity,
}) : super(key: key);

final TerminalTheme theme;
final double terminalOpacity;

@override
_MyHomePageState createState() => _MyHomePageState();
Expand Down Expand Up @@ -86,24 +98,41 @@ class FakeTerminalBackend extends TerminalBackend {
}

class _MyHomePageState extends State<MyHomePage> {
final terminal = TerminalIsolate(
backend: FakeTerminalBackend(),
maxLines: 10000,
);
TerminalIsolate? terminal;

Future<TerminalIsolate> _ensureTerminalStarted() async {
if (terminal == null) {
terminal = TerminalIsolate(
backend: FakeTerminalBackend(),
maxLines: 10000,
theme: widget.theme,
);
}

@override
void initState() {
super.initState();
terminal.start();
if (!terminal!.isReady) {
await terminal!.start();
}
return terminal!;
}

void onInput(String input) {}

@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: TerminalView(terminal: terminal),
body: FutureBuilder(
future: _ensureTerminalStarted(),
builder: (context, snapshot) {
return SafeArea(
child: snapshot.hasData
? TerminalView(terminal: snapshot.data as TerminalIsolate)
: Container(
constraints: const BoxConstraints.expand(),
color: Color(widget.theme.background)
.withOpacity(widget.terminalOpacity),
),
);
},
),
);
}
Expand Down
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class MyApp extends StatelessWidget {
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key}) : super(key: key);
MyHomePage({Key? key}) : super(key: key);

@override
_MyHomePageState createState() => _MyHomePageState();
Expand Down
21 changes: 11 additions & 10 deletions example/lib/ssh.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'dart:async';
import 'dart:convert';
import 'dart:typed_data';

import 'package:dartssh/client.dart';
import 'package:dartssh2/dartssh2.dart';
import 'package:flutter/material.dart';
import 'package:xterm/flutter.dart';
import 'package:xterm/xterm.dart';
Expand Down Expand Up @@ -29,14 +30,14 @@ class MyApp extends StatelessWidget {
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key}) : super(key: key);
MyHomePage({Key? key}) : super(key: key);

@override
_MyHomePageState createState() => _MyHomePageState();
}

class SSHTerminalBackend extends TerminalBackend {
SSHClient client;
late SSHClient client;

String _host;
String _username;
Expand All @@ -63,13 +64,13 @@ class SSHTerminalBackend extends TerminalBackend {
onWrite('connecting $_host...');
client = SSHClient(
hostport: Uri.parse(_host),
login: _username,
username: _username,
print: print,
termWidth: 80,
termHeight: 25,
termvar: 'xterm-256color',
getPassword: () => utf8.encode(_password),
response: (transport, data) {
onPasswordRequest: () => _password,
response: (data) {
_sshOutput.add(data);
},
success: () {
Expand All @@ -92,12 +93,12 @@ class SSHTerminalBackend extends TerminalBackend {

@override
void write(String input) {
client?.sendChannelData(utf8.encode(input));
client.sendChannelData(Uint8List.fromList(utf8.encode(input)));
}

@override
void terminate() {
client?.disconnect('terminate');
client.disconnect('terminate');
}

@override
Expand All @@ -107,8 +108,8 @@ class SSHTerminalBackend extends TerminalBackend {
}

class _MyHomePageState extends State<MyHomePage> {
Terminal terminal;
SSHTerminalBackend backend;
late Terminal terminal;
late SSHTerminalBackend backend;

@override
void initState() {
Expand Down
80 changes: 53 additions & 27 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
args:
dependency: transitive
description:
name: args
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.0"
asn1lib:
dependency: transitive
description:
name: asn1lib
url: "https://pub.dartlang.org"
source: hosted
version: "0.5.15"
version: "1.0.3"
async:
dependency: transitive
description:
Expand Down Expand Up @@ -64,15 +71,22 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
dartssh:
dart_console:
dependency: transitive
description:
name: dart_console
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
dartssh2:
dependency: "direct main"
description:
path: "."
ref: HEAD
resolved-ref: "1c2244db550a56e2d53754864b8ce3da525a4b7d"
url: "https://github.com/TerminalStudio/dartssh"
resolved-ref: "3316b252ace4948f64812b7e5eca11f466d3f62d"
url: "https://github.com/TerminalStudio/dartssh2"
source: git
version: "1.0.4+4"
version: "1.2.0-pre"
equatable:
dependency: transitive
description:
Expand All @@ -87,13 +101,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
fixnum:
ffi:
dependency: transitive
description:
name: fixnum
name: ffi
url: "https://pub.dartlang.org"
source: hosted
version: "0.10.11"
version: "1.1.2"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -110,21 +124,35 @@ packages:
name: http
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.2"
version: "0.13.4"
http_parser:
dependency: transitive
description:
name: http_parser
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.4"
version: "4.0.0"
js:
dependency: transitive
description:
name: js
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.3"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.11"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.2"
meta:
dependency: transitive
description:
Expand All @@ -139,13 +167,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
pedantic:
pinenacl:
dependency: transitive
description:
name: pedantic
name: pinenacl
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.2"
version: "0.3.3"
platform_info:
dependency: transitive
description:
Expand All @@ -159,7 +187,7 @@ packages:
name: pointycastle
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
version: "3.4.0"
quiver:
dependency: transitive
description:
Expand Down Expand Up @@ -213,16 +241,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.3"
tweetnacl:
dependency: transitive
description:
path: "."
ref: HEAD
resolved-ref: "028b09a31805c648df1db695f7a58f9fcd4099d9"
url: "https://github.com/TerminalStudio/tweetnacl-dart"
source: git
version: "0.3.2"
version: "0.4.8"
typed_data:
dependency: transitive
description:
Expand All @@ -236,14 +255,21 @@ packages:
name: validators
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0+1"
version: "3.0.0"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.1.1"
win32:
dependency: transitive
description:
name: win32
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.3"
xterm:
dependency: "direct main"
description:
Expand All @@ -252,5 +278,5 @@ packages:
source: path
version: "2.5.0-pre"
sdks:
dart: ">=2.12.0 <3.0.0"
dart: ">=2.14.0 <3.0.0"
flutter: ">=2.0.0"
6 changes: 3 additions & 3 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1

environment:
sdk: ">=2.7.0 <3.0.0"
sdk: ">=2.12.0 <3.0.0"

dependencies:
xterm:
path: ../

dartssh:
dartssh2:
git:
url: https://github.com/TerminalStudio/dartssh
url: https://github.com/TerminalStudio/dartssh2

flutter:
sdk: flutter
Expand Down
Loading