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

iOS offline Linux - tty forwarding to xterm.js #172

Closed
jaromaz opened this issue Oct 11, 2017 · 15 comments
Closed

iOS offline Linux - tty forwarding to xterm.js #172

jaromaz opened this issue Oct 11, 2017 · 15 comments

Comments

@jaromaz
Copy link

jaromaz commented Oct 11, 2017

I managed to run Linux 3 offline on iOS by using your v86 Project and the web server included in GoCoEdit app. Unfortunately, keyboard operation is not working properly. However, it is working properly at https://xtermjs.org. Can you redirect the tty to xterm.js instead of textarea?

@czenzel
Copy link

czenzel commented Oct 13, 2017

If I get some free time I will take a look at this, but I believe you can hide the textarea using CSS 3 and then redirect the serial output to the xtermjs. You would have to hook the serial interface API which I think is documented under the project. This would mean the kernel would have to have serial TTY support built in along with the kernel flags at boot indicating to use a serial console.

@smallpotato000
Copy link

smallpotato000 commented Oct 13, 2017

I managed to run FreeDOS offline on iOS by using v86 and DraftCode.
Edit debug.txt:
<div id="screen_container" style="display: none" contenteditable="true">
to make keyboard working...
However is it very slow, about 500kIPS on iPhoneSE.
I have no idea if DraftCode use a slow JavaScript engine, because v86 runs much faster (tens of MIPS) in Firefox.

@smallpotato000
Copy link

smallpotato000 commented Oct 13, 2017

20171013135602

the keyboard works.
Btw v86 runs much faster in GoCoEdit than in DraftCode.

Repository owner deleted a comment Oct 13, 2017
@copy
Copy link
Owner

copy commented Oct 13, 2017

If I get some free time I will take a look at this, but I believe you can hide the textarea using CSS 3 and then redirect the serial output to the xtermjs.

This is a good idea. It would also be nice to have this feature for the keyboard input (#105), which would entail porting the keyboard handling from xtermjs to keyboard.js.

@jaromaz
Copy link
Author

jaromaz commented Oct 14, 2017

Btw v86 runs much faster in GoCoEdit than in DraftCode.

You can use any browser with GoCoEdit - v86 is the fastest performing in Chrome.

contenteditable="true"

I used this attribute before I wrote my first post. Problem is that characters can only be written in lowercase letters and the some vim shortcuts are not supported. I use a bluetooth keyboard and have tested that in conjunction with xterm.js these problems do not occur. The perfect solution (after loading the system) would be to open xterm. js in the full window.

This could be a very interesting and comprehensive solution, because Apple does not allow for virtualization in its store.

@czenzel
Copy link

czenzel commented Oct 15, 2017

Hi @copy, I am looking into it now. I am feeling better after some sick time I needed. I will try to visit as much of this as possible tonight and try to get a sample on GitHub later this week. I am thinking that redirecting the serial output/input is the best route with the appropriate kernel; however, I will look at the screen output and keyboard redirect. However, as always work comes first (just got a new job).

Update: It might be easy to create a separate add-on to xterm.js similar to their web socket ones such as https://github.com/sourcelair/xterm.js/blob/v3/src/addons/terminado/terminado.js and instead hook it to the existing API functions. Thoughts?

@copy
Copy link
Owner

copy commented Oct 17, 2017

Update: It might be easy to create a separate add-on to xterm.js similar to their web socket ones such as https://github.com/sourcelair/xterm.js/blob/v3/src/addons/terminado/terminado.js and instead hook it to the existing API functions. Thoughts?

Sounds good.

@jaromaz
Copy link
Author

jaromaz commented Oct 27, 2017

Any new info?

@czenzel
Copy link

czenzel commented Oct 29, 2017

Hi @jaromaz, Sorry not at this time. I have been super busy at work.

@copy
Copy link
Owner

copy commented Nov 9, 2017

I pushed a fix for the phone keyboard, I'll make a release tonight.

Integration of xterm for the terminal would still be nice, I'll leave this issue open for that.

@humphd
Copy link

humphd commented Jun 7, 2018

I might be missing something, but the following seems to work perfectly with xterm.js:

<!doctype html>
<title>Serial example with xterm.js</title>

<!-- run `npm install xterm` first to get these -->
<link rel="stylesheet" href="../node_modules/xterm/dist/xterm.css" />
<script src="../node_modules/xterm/dist/xterm.js"></script>

<!-- display for xterm.js -->
<div id="terminal"></div>

<script src="../build/libv86.js"></script>
<script>
"use strict";

window.onload = () => {
    var emulator = new V86Starter({
        bios: {
            url: "../bios/seabios.bin",
        },
        vga_bios: {
            url: "../bios/vgabios.bin",
        },
        cdrom: {
            url: "../images/linux.iso",
        },
        autostart: true,
        disable_keyboard: true
    });

    var term = window.term = new Terminal();
    term.open(document.getElementById('terminal'));

    // Wire input events from xterm.js -> ttyS0
    term.on('key', key => emulator.serial0_send(key));
    // Wire output events from ttyS0 -> xterm.js
    emulator.add_listener("serial0-output-char", (char) => term.write(char));
};
</script>

screen shot 2018-06-06 at 8 16 57 pm

@humphd
Copy link

humphd commented Jun 13, 2018

Continuing the discussion from #210, now that I have xterm.js connected to ttyS0, and trying to figure out a good way to deal with autoresizing.

In Linux I can change the terminal size with stty rows 80 cols 40, and then tell xterm.js to term.resize(80,40). But there is no clean way (that I can see) to do this automatically--doing it over a network protocol vs. serial would accomplish this, but I don't think that would be easy (correct me if I'm wrong).

So I need a way to manage this. One thought would be to have 2 serial connections (or hijack the existing console) to use the second connection in order to send stty resize info whenever the client terminal size changes. I could then do something like send SIGWINCH to the terminal to tell it that it needs to resize.

Anyone got advice here? How should I handle this? Using xterm.js + ttyS0 is so close to perfect, I'd like to not reinvent the wheel for this one thing.

@copy
Copy link
Owner

copy commented Jun 13, 2018

Anyone got advice here? How should I handle this? Using xterm.js + ttyS0 is so close to perfect, I'd like to not reinvent the wheel for this one thing.

I would try xterm.js's auto-resizing plugin, combined with one of these hacks. From a quick glance, xterm.js supports these ANSI escapes, so something like this should work:

res() {

  old=$(stty -g)
  stty raw -echo min 0 time 5

  printf '\0337\033[r\033[999;999H\033[6n\0338' > /dev/tty
  IFS='[;R' read -r _ rows cols _ < /dev/tty

  stty "$old"

  # echo "cols:$cols"
  # echo "rows:$rows"
  stty cols "$cols" rows "$rows"
}
trap res DEBUG

@humphd
Copy link

humphd commented Jun 15, 2018

Busybox doesn't seem to work with this hack. I'll have to do some more research.

Also, the xterm fit addon doesn't really address this. It's more for having the widget fill the space, but still honours the rows/cols.

@copy
Copy link
Owner

copy commented Jan 4, 2021

There's xterm.js support now, see #203 (comment).

@copy copy closed this as completed Jan 4, 2021
Repository owner deleted a comment from hello-smile6 Jan 5, 2022
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

No branches or pull requests

5 participants