Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(493)

Unified Diff: sky/examples/terminal/terminal_file_impl.dart

Issue 999193002: Add a simple prototype "terminal" example. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: review comments Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/examples/terminal/terminal_display.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/examples/terminal/terminal_file_impl.dart
diff --git a/sky/examples/terminal/terminal_file_impl.dart b/sky/examples/terminal/terminal_file_impl.dart
new file mode 100644
index 0000000000000000000000000000000000000000..34b48c84fc3c79be71da1f006bb1a1c04e1ce379
--- /dev/null
+++ b/sky/examples/terminal/terminal_file_impl.dart
@@ -0,0 +1,124 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+import 'dart:async';
+import 'dart:core';
+import 'mojo:core';
+import 'package:services/files/file.mojom.dart' as files;
+import 'package:services/files/types.mojom.dart' as files;
+
+import 'terminal_display.dart';
+
+// This implements a |mojo.files.File| that acts like a (pseudo)terminal. Bytes
+// written to the |File| will be read by this implementation and passed on to
+// the (Dart) |TerminalDisplay| (using |putChar()|). A read from the |File| will
+// be completed if/when |TerminalDisplay| makes a byte available (via
+// |getChar()|).
+// TODO(vtl): This implementation is very incomplete.
+class TerminalFileImpl implements files.File {
+ final files.FileStub stub;
+ final TerminalDisplay _display;
+
+ TerminalFileImpl(this._display) : stub = new files.FileStub.unbound() {
+ stub.impl = this;
+ }
+
+ // |files.File| implementation:
+
+ @override
+ Future close(Function responseFactory) async {
+ // TODO(vtl): We should probably do more than just say OK.
+ return responseFactory(files.Error_OK);
+ }
+
+ @override
+ Future read(int numBytesToRead, int offset, int whence,
+ Function responseFactory) async {
+ if (numBytesToRead < 0) {
+ return responseFactory(files.Error_INVALID_ARGUMENT, null);
+ }
+
+ // TODO(vtl): Error if |offset|/|whence| not appropriate.
+
+ if (numBytesToRead == 0) {
+ return responseFactory(files.Error_OK, []);
+ }
+
+ return responseFactory(files.Error_OK, [await _display.getChar()]);
+ }
+
+ @override
+ Future write(List<int> bytesToWrite, int offset, int whence,
+ Function responseFactory) async {
+ // TODO(vtl): Error if |offset|/|whence| not appropriate.
+
+ for (var c in bytesToWrite) {
+ _display.putChar(c);
+ }
+ return responseFactory(files.Error_OK, bytesToWrite.length);
+ }
+
+ @override
+ Future readToStream(MojoDataPipeProducer source, int offset, int whence,
+ int numBytesToRead, Function responseFactory) async {
+ // TODO(vtl)
+ return responseFactory(files.Error_UNIMPLEMENTED);
+ }
+
+ @override
+ Future writeFromStream(MojoDataPipeConsumer sink, int offset, int whence,
+ Function responseFactory) async {
+ // TODO(vtl)
+ return responseFactory(files.Error_UNIMPLEMENTED);
+ }
+
+ @override
+ Future tell(Function responseFactory) async {
+ // TODO(vtl)
+ return responseFactory(files.Error_UNIMPLEMENTED, 0);
+ }
+
+ @override
+ Future seek(int offset, int whence, Function responseFactory) async {
+ // TODO(vtl)
+ return responseFactory(files.Error_UNIMPLEMENTED, 0);
+ }
+
+ @override
+ Future stat(Function responseFactory) async {
+ // TODO(vtl)
+ return responseFactory(files.Error_UNIMPLEMENTED, null);
+ }
+
+ @override
+ Future truncate(int size, Function responseFactory) async {
+ // TODO(vtl)
+ return responseFactory(files.Error_UNIMPLEMENTED);
+ }
+
+ @override
+ Future touch(files.TimespecOrNow atime, files.TimespecOrNow mtime,
+ Function responseFactory) async {
+ // TODO(vtl)
+ return responseFactory(files.Error_UNIMPLEMENTED);
+ }
+
+ @override
+ Future dup(Object file, Function responseFactory) async {
+ // TODO(vtl)
+ return responseFactory(files.Error_UNIMPLEMENTED);
+ }
+
+ @override
+ Future reopen(Object file, int openFlags, Function responseFactory) async {
+ // TODO(vtl)
+ return responseFactory(files.Error_UNIMPLEMENTED);
+ }
+
+ @override
+ Future asBuffer(Function responseFactory) async {
+ // TODO(vtl)
+ return responseFactory(files.Error_UNIMPLEMENTED, null);
+ }
+}
« no previous file with comments | « sky/examples/terminal/terminal_display.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698