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

Input output guide #144

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Input output guide #144

wants to merge 4 commits into from

Conversation

AtibQur
Copy link
Contributor

@AtibQur AtibQur commented Oct 14, 2024

No description provided.

@@ -0,0 +1,49 @@
---
title: input and output CheerpX
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
title: input and output CheerpX
title: Input and output

@@ -0,0 +1,49 @@
---
title: input and output CheerpX
description: Summarization on how to get data in and out of CheerpX VM
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description: Summarization on how to get data in and out of CheerpX VM
description: Techniques for getting data in and out of CheerpX virtual machine


## CheerpX console input and output

CheerpX provides two options for handling console input and output: the `built-in` console and a `custom` console. The purpose of these consoles are to interact with the running application, execute commands and, view output. The custom console allows you to create an interface that fits the specific needs of your application.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer italics to code for built-in and custom. We should only use the code markers for names which corresponds to APIs


## CheerpX console input and output

CheerpX provides two options for handling console input and output: the `built-in` console and a `custom` console. The purpose of these consoles are to interact with the running application, execute commands and, view output. The custom console allows you to create an interface that fits the specific needs of your application.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CheerpX provides two options for handling console input and output: the `built-in` console and a `custom` console. The purpose of these consoles are to interact with the running application, execute commands and, view output. The custom console allows you to create an interface that fits the specific needs of your application.
CheerpX provides two options for handling console input and output: the `built-in` console and a `custom` console. The purpose of the console is to interact with the running application via standard input and output..


**Built-in console**

The CheerpX VM comes with a `built-in` console that mimics traditional console behavior. The `built-in` console in CheerpX allows for standard input and output operations, similar to typical command-line environments. You can use standard I/O functions like printf and scanf within your C/C++ programs.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The CheerpX VM comes with a `built-in` console that mimics traditional console behavior. The `built-in` console in CheerpX allows for standard input and output operations, similar to typical command-line environments. You can use standard I/O functions like printf and scanf within your C/C++ programs.
CheerpX comes with a _built-in_ console that mimics traditional console behavior. The _built-in_ console in CheerpX allows for standard input and output operations, similar to typical command-line environments. You can use standard I/O functions like printf and scanf within your C/C++ programs.


For more information, visit the [CheerpX console].

**Custom console**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be ### titles?


**Custom console**

CheerpX also supports a `custom` console that allows developers to capture output programmatically. This feature enables you to accumulate program output into a JavaScript string. You can implement your `custom` logging mechanism to redirect the output to a variable, which can be manipulated or displayed as needed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CheerpX also supports a `custom` console that allows developers to capture output programmatically. This feature enables you to accumulate program output into a JavaScript string. You can implement your `custom` logging mechanism to redirect the output to a variable, which can be manipulated or displayed as needed.
CheerpX also supports a `custom` console that allows developers to capture output, and provide input, programmatically. This feature is useful to integrate with a more complete terminal implementation such as xterm.js [TODO ADD LINK TO LIB]. We use xterm.js ourselves for our public WebVM environment.
Another possible use for the custom console it accumulating program output into a JavaScript string. You can achieve this with the following snippet [ADD CODE, this is not documented elsewhere]


`IDBDevice` provides a persistent, read-write filesystem using the browser’s IndexedDB. It’s ideal for storing data that should persist between sessions. You can use the `readFileAsBlob` method to read files from an IDBDevice as Blob objects.

You can copy files from various filesystems into the `IDBDevice`. This allows you to make these files accesible.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
You can copy files from various filesystems into the `IDBDevice`. This allows you to make these files accesible.
If the file you want to read is not yet in an `IDBDevice`, you can copy files by running commands inside the virtual machine to make them accessible. [ADD AN EXAMPLE, e.g. using `cp` via `cx.run`]


## Accessing JS Data in the Filesystem via DataDevice

The `DataDevice` in CheerpX allows access to JavaScript data in the filesystem. This device can interact with data stored in memory or other JavaScript objects. It is particularly useful for transferring data between JavaScript and the compiled C/C++ code.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The `DataDevice` in CheerpX allows access to JavaScript data in the filesystem. This device can interact with data stored in memory or other JavaScript objects. It is particularly useful for transferring data between JavaScript and the compiled C/C++ code.
The `DataDevice` in CheerpX allows access to JavaScript data from the filesystem. This device can read-only access to `Uint8Array`s and JavaScript `Strings`s. It is particularly useful for transferring data from JavaScript to processes running in CheerpX.


Currently, CheerpX doesn't directly support capturing stdout from running programs. Therefore, The IDBDevice allows you to use `.readFileAsBlob()` for capturing stdout after redirecting stdout to a file in `bash`. You can then read this file as a Blob.

For more information on capturing stdout, see [Frequently Asked Questions].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the whole answer outside of the FAQ, this document is a much better place for it. Also integrated it with the previously mentioned solution of using a custom console.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants