Browse Source

➕ add ssh example

xuty 5 years ago
parent
commit
ca3f642864

+ 6 - 0
README.md

@@ -86,6 +86,12 @@ terminal.write('Hello, world!');
 
 **Done!**
 
+### Example
+
+**[ssh example](https://github.com/TerminalStudio/xterm.dart/blob/master/example/lib/main.dart)**
+
+<img width="400px" src="https://raw.githubusercontent.com/TerminalStudio/xterm.dart/master/media/example-ssh.png">
+
 ### License
 
 This project is licensed under an MIT license.

+ 18 - 0
example/android/app/src/main/res/values-night/styles.xml

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
+    <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
+        <!-- Show a splash screen on the activity. Automatically removed when
+             Flutter draws its first frame -->
+        <item name="android:windowBackground">@drawable/launch_background</item>
+    </style>
+    <!-- Theme applied to the Android Window as soon as the process has started.
+         This theme determines the color of the Android Window while your
+         Flutter UI initializes, as well as behind your Flutter UI while its
+         running.
+         
+         This Theme is only used starting with V2 of Flutter's Android embedding. -->
+    <style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
+        <item name="android:windowBackground">?android:colorBackground</item>
+    </style>
+</resources>

+ 87 - 0
example/lib/ssh.dart

@@ -0,0 +1,87 @@
+import 'dart:convert';
+
+import 'package:dartssh/client.dart';
+import 'package:flutter/material.dart';
+import 'package:xterm/flutter.dart';
+import 'package:xterm/xterm.dart';
+
+const host = 'ssh://localhost:22';
+const username = 'xuty';
+const password = '123123';
+
+void main() {
+  runApp(MyApp());
+}
+
+class MyApp extends StatelessWidget {
+  @override
+  Widget build(BuildContext context) {
+    return MaterialApp(
+      title: 'xterm.dart demo',
+      theme: ThemeData(
+        primarySwatch: Colors.blue,
+        visualDensity: VisualDensity.adaptivePlatformDensity,
+      ),
+      home: MyHomePage(),
+    );
+  }
+}
+
+class MyHomePage extends StatefulWidget {
+  MyHomePage({Key key}) : super(key: key);
+
+  @override
+  _MyHomePageState createState() => _MyHomePageState();
+}
+
+class _MyHomePageState extends State<MyHomePage> {
+  Terminal terminal;
+  SSHClient client;
+
+  @override
+  void initState() {
+    super.initState();
+    terminal = Terminal(onInput: onInput);
+    connect();
+  }
+
+  void connect() {
+    terminal.write('connecting $host...');
+    client = SSHClient(
+      hostport: Uri.parse(host),
+      login: username,
+      print: print,
+      termWidth: 80,
+      termHeight: 25,
+      termvar: 'xterm-256color',
+      getPassword: () => utf8.encode(password),
+      response: (transport, data) {
+        terminal.write(data);
+      },
+      success: () {
+        terminal.write('connected.\n');
+      },
+      disconnected: () {
+        terminal.write('disconnected.');
+      },
+    );
+  }
+
+  void onInput(String input) {
+    client?.sendChannelData(utf8.encode(input));
+  }
+
+  @override
+  Widget build(BuildContext context) {
+    return Scaffold(
+      body: SafeArea(
+        child: TerminalView(
+          terminal: terminal,
+          onResize: (width, height) {
+            client?.setTerminalWindowSize(width, height);
+          },
+        ),
+      ),
+    );
+  }
+}

+ 12 - 0
example/macos/Runner/DebugProfile.entitlements

@@ -4,8 +4,20 @@
 <dict>
 	<key>com.apple.security.app-sandbox</key>
 	<true/>
+	<key>com.apple.security.assets.movies.read-write</key>
+	<true/>
+	<key>com.apple.security.assets.music.read-write</key>
+	<true/>
+	<key>com.apple.security.assets.pictures.read-write</key>
+	<true/>
 	<key>com.apple.security.cs.allow-jit</key>
 	<true/>
+	<key>com.apple.security.files.downloads.read-write</key>
+	<true/>
+	<key>com.apple.security.files.user-selected.read-write</key>
+	<true/>
+	<key>com.apple.security.network.client</key>
+	<true/>
 	<key>com.apple.security.network.server</key>
 	<true/>
 </dict>

+ 14 - 0
example/macos/Runner/Release.entitlements

@@ -4,5 +4,19 @@
 <dict>
 	<key>com.apple.security.app-sandbox</key>
 	<true/>
+	<key>com.apple.security.assets.movies.read-write</key>
+	<true/>
+	<key>com.apple.security.assets.music.read-write</key>
+	<true/>
+	<key>com.apple.security.assets.pictures.read-write</key>
+	<true/>
+	<key>com.apple.security.files.downloads.read-write</key>
+	<true/>
+	<key>com.apple.security.files.user-selected.read-write</key>
+	<true/>
+	<key>com.apple.security.network.client</key>
+	<true/>
+	<key>com.apple.security.network.server</key>
+	<true/>
 </dict>
 </plist>

+ 63 - 0
example/pubspec.lock

@@ -1,6 +1,13 @@
 # Generated by pub
 # See https://dart.dev/tools/pub/glossary#lockfile
 packages:
+  asn1lib:
+    dependency: transitive
+    description:
+      name: asn1lib
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "0.5.15"
   async:
     dependency: transitive
     description:
@@ -57,6 +64,13 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "0.1.3"
+  dartssh:
+    dependency: "direct main"
+    description:
+      name: dartssh
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "1.0.3+3"
   fake_async:
     dependency: transitive
     description:
@@ -64,6 +78,13 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "1.1.0-nullsafety"
+  fixnum:
+    dependency: transitive
+    description:
+      name: fixnum
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "0.10.11"
   flutter:
     dependency: "direct main"
     description: flutter
@@ -74,6 +95,20 @@ packages:
     description: flutter
     source: sdk
     version: "0.0.0"
+  http:
+    dependency: transitive
+    description:
+      name: http
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "0.12.2"
+  http_parser:
+    dependency: transitive
+    description:
+      name: http_parser
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "3.1.4"
   matcher:
     dependency: transitive
     description:
@@ -95,6 +130,20 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "1.8.0-nullsafety"
+  pedantic:
+    dependency: transitive
+    description:
+      name: pedantic
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "1.9.2"
+  pointycastle:
+    dependency: transitive
+    description:
+      name: pointycastle
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "1.0.2"
   quiver:
     dependency: transitive
     description:
@@ -149,6 +198,13 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "0.2.19-nullsafety"
+  tweetnacl:
+    dependency: transitive
+    description:
+      name: tweetnacl
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "0.3.2"
   typed_data:
     dependency: transitive
     description:
@@ -156,6 +212,13 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "1.3.0-nullsafety.2"
+  validators:
+    dependency: transitive
+    description:
+      name: validators
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "2.0.0+1"
   vector_math:
     dependency: transitive
     description:

+ 2 - 0
example/pubspec.yaml

@@ -23,6 +23,8 @@ environment:
 dependencies:
   xterm:
     path: ../
+
+  dartssh: ^1.0.3+3
     
   flutter:
     sdk: flutter

BIN
media/example-ssh.png