I need help with how bash works, terminals work, and the vte crate

Source code here https://github.com/teln0/termui

Hello everyone :wave:

I'm trying to create a terminal emulator inside a terminal (maybe you saw my reddit post ?). For now I managed to run a bash inside a pseudoterminal, and communicate with it through a file descriptor. Everything works fine, except for when I reach the end of a line in my pseudoterminal, the cursor kinda glitches out "loops" on the current line (in a very weird way). So my first though was : maybe I my terminal emulator didn't support some escape sequence that bash used when reaching the end of the line ? I'm using the vte crate to parse output from the terminal, so I though I just needed to write the correct handlers. But then I have a few problems.

1st : I can't seem to understand the difference between

  • execute( &mut self, byte: u8)
  • csi_dispatch( &mut self, params: &[i64], intermediates: &[u8], ignore: bool, action: char) btw I don't know what intermediates is.
  • esc_dispatch(&mut self, intermediates: &[u8], ignore: bool, byte: u8) still don't know what intermediates is.

from here https://docs.rs/vte/0.8.0/vte/trait.Perform.html

I know Csi stands for Control Sequence Introducer and Esc for Escape, and that control sequences are kind of a subset of escape sequences (https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences).

2nd : When bash reaches the end of a line, I know :

  • execute( &mut self, byte: u8) is called with byte as :
    • '\r' : ok, I go back to the beginning of the line
    • '\n' : ok, I add 1 to the y cursor
  • esc_dispatch(&mut self, intermediates: &[u8], ignore: bool, byte: u8) is called with byte as 60 (corresponding char is '<'). I have no idea what does '<' correspond to and what to do, but I think the problem lies here.

So the main question is : what does bash do when it reaches an end of line, and how should I react to it ?

Can anyone help me ? I've been stuck on this for a whole day now !

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.