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

Side by Side Diff: sky/examples/terminal/terminal_file_impl.dart

Issue 1038813005: Move terminal example from //sky/examples to //examples (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 8 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 unified diff | Download patch
« no previous file with comments | « sky/examples/terminal/terminal_display.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 import 'dart:async';
6 import 'dart:core';
7 import 'package:mojo/public/dart/core.dart';
8 import 'package:mojo/services/files/public/interfaces/file.mojom.dart' as files;
9 import 'package:mojo/services/files/public/interfaces/types.mojom.dart' as files ;
10
11 import 'terminal_display.dart';
12
13 // This implements a |mojo.files.File| that acts like a (pseudo)terminal. Bytes
14 // written to the |File| will be read by this implementation and passed on to
15 // the (Dart) |TerminalDisplay| (using |putChar()|). A read from the |File| will
16 // be completed if/when |TerminalDisplay| makes a byte available (via
17 // |getChar()|).
18 // TODO(vtl): This implementation is very incomplete.
19 class TerminalFileImpl implements files.File {
20 final files.FileStub stub;
21 final TerminalDisplay _display;
22
23 TerminalFileImpl(this._display) : stub = new files.FileStub.unbound() {
24 stub.impl = this;
25 }
26
27 // |files.File| implementation:
28
29 @override
30 Future close(Function responseFactory) async {
31 // TODO(vtl): We should probably do more than just say OK.
32 return responseFactory(files.Error_OK);
33 }
34
35 @override
36 Future read(int numBytesToRead, int offset, int whence,
37 Function responseFactory) async {
38 if (numBytesToRead < 0) {
39 return responseFactory(files.Error_INVALID_ARGUMENT, null);
40 }
41
42 // TODO(vtl): Error if |offset|/|whence| not appropriate.
43
44 if (numBytesToRead == 0) {
45 return responseFactory(files.Error_OK, []);
46 }
47
48 return responseFactory(files.Error_OK, [await _display.getChar()]);
49 }
50
51 @override
52 Future write(List<int> bytesToWrite, int offset, int whence,
53 Function responseFactory) async {
54 // TODO(vtl): Error if |offset|/|whence| not appropriate.
55
56 for (var c in bytesToWrite) {
57 _display.putChar(c);
58 }
59 return responseFactory(files.Error_OK, bytesToWrite.length);
60 }
61
62 @override
63 Future readToStream(MojoDataPipeProducer source, int offset, int whence,
64 int numBytesToRead, Function responseFactory) async {
65 // TODO(vtl)
66 return responseFactory(files.Error_UNIMPLEMENTED);
67 }
68
69 @override
70 Future writeFromStream(MojoDataPipeConsumer sink, int offset, int whence,
71 Function responseFactory) async {
72 // TODO(vtl)
73 return responseFactory(files.Error_UNIMPLEMENTED);
74 }
75
76 @override
77 Future tell(Function responseFactory) async {
78 // TODO(vtl)
79 return responseFactory(files.Error_UNIMPLEMENTED, 0);
80 }
81
82 @override
83 Future seek(int offset, int whence, Function responseFactory) async {
84 // TODO(vtl)
85 return responseFactory(files.Error_UNIMPLEMENTED, 0);
86 }
87
88 @override
89 Future stat(Function responseFactory) async {
90 // TODO(vtl)
91 return responseFactory(files.Error_UNIMPLEMENTED, null);
92 }
93
94 @override
95 Future truncate(int size, Function responseFactory) async {
96 // TODO(vtl)
97 return responseFactory(files.Error_UNIMPLEMENTED);
98 }
99
100 @override
101 Future touch(files.TimespecOrNow atime, files.TimespecOrNow mtime,
102 Function responseFactory) async {
103 // TODO(vtl)
104 return responseFactory(files.Error_UNIMPLEMENTED);
105 }
106
107 @override
108 Future dup(Object file, Function responseFactory) async {
109 // TODO(vtl)
110 return responseFactory(files.Error_UNIMPLEMENTED);
111 }
112
113 @override
114 Future reopen(Object file, int openFlags, Function responseFactory) async {
115 // TODO(vtl)
116 return responseFactory(files.Error_UNIMPLEMENTED);
117 }
118
119 @override
120 Future asBuffer(Function responseFactory) async {
121 // TODO(vtl)
122 return responseFactory(files.Error_UNIMPLEMENTED, null);
123 }
124 }
OLDNEW
« 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