| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This is a terminal client (i.e., a "raw" |mojo.terminal.Terminal| -- e.g., | 5 // This is a terminal client (i.e., a "raw" |mojo.terminal.Terminal| -- e.g., |
| 6 // moterm -- can be asked to talk to this) that prompts the user for a native | 6 // moterm -- can be asked to talk to this) that prompts the user for a native |
| 7 // (Linux) binary to run and then does so (via mojo:native_support). | 7 // (Linux) binary to run and then does so (via mojo:native_support). |
| 8 // | 8 // |
| 9 // E.g., first run mojo:moterm_example_app (embedded by a window manager). Then, | 9 // E.g., first run mojo:moterm_example_app (embedded by a window manager). Then, |
| 10 // at the prompt, enter "mojo:native_run_app". At the next prompt, enter "bash" | 10 // at the prompt, enter "mojo:native_run_app". At the next prompt, enter "bash" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 : terminal_(terminal.Pass()), | 45 : terminal_(terminal.Pass()), |
| 46 native_support_process_(native_support_process) { | 46 native_support_process_(native_support_process) { |
| 47 terminal_.set_connection_error_handler([this]() { delete this; }); | 47 terminal_.set_connection_error_handler([this]() { delete this; }); |
| 48 Start(); | 48 Start(); |
| 49 } | 49 } |
| 50 ~TerminalConnection() {} | 50 ~TerminalConnection() {} |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 void Write(const char* s, mojo::files::File::WriteCallback callback) { | 53 void Write(const char* s, mojo::files::File::WriteCallback callback) { |
| 54 size_t length = strlen(s); | 54 size_t length = strlen(s); |
| 55 mojo::Array<uint8_t> a(length); | 55 auto a = mojo::Array<uint8_t>::New(length); |
| 56 memcpy(&a[0], s, length); | 56 memcpy(&a[0], s, length); |
| 57 terminal_->Write(a.Pass(), 0, mojo::files::Whence::FROM_CURRENT, callback); | 57 terminal_->Write(a.Pass(), 0, mojo::files::Whence::FROM_CURRENT, callback); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void Start() { | 60 void Start() { |
| 61 // TODO(vtl): Check canonical mode (via ioctl) first (or before |Read()|). | 61 // TODO(vtl): Check canonical mode (via ioctl) first (or before |Read()|). |
| 62 | 62 |
| 63 const char kPrompt[] = "\x1b[0mNative program to run?\n>>> "; | 63 const char kPrompt[] = "\x1b[0mNative program to run?\n>>> "; |
| 64 Write(kPrompt, [this](mojo::files::Error error, uint32_t) { | 64 Write(kPrompt, [this](mojo::files::Error error, uint32_t) { |
| 65 this->DidWritePrompt(error); | 65 this->DidWritePrompt(error); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 mojo::ApplicationImpl* application_impl_; | 242 mojo::ApplicationImpl* application_impl_; |
| 243 native_support::ProcessPtr native_support_process_; | 243 native_support::ProcessPtr native_support_process_; |
| 244 | 244 |
| 245 DISALLOW_COPY_AND_ASSIGN(NativeRunApp); | 245 DISALLOW_COPY_AND_ASSIGN(NativeRunApp); |
| 246 }; | 246 }; |
| 247 | 247 |
| 248 MojoResult MojoMain(MojoHandle application_request) { | 248 MojoResult MojoMain(MojoHandle application_request) { |
| 249 mojo::ApplicationRunnerChromium runner(new NativeRunApp()); | 249 mojo::ApplicationRunnerChromium runner(new NativeRunApp()); |
| 250 return runner.Run(application_request); | 250 return runner.Run(application_request); |
| 251 } | 251 } |
| OLD | NEW |