Replies: 4 comments 6 replies
-
There is no easy way to do this, because you need a terminal emulator to parse the bytes and compute the the model for the display, in order to apply that to a You could use wezterm's In addition, there is no canned transform from the |
Beta Was this translation helpful? Give feedback.
-
I think I have roughly the same question: I want to spawn a shell and running in a pty and get what is currently on screen as a string (or some sort of buffer). Using import select
import ptyprocess
import pyte
screen = pyte.Screen(80, 8) # 80x8 terminal size
stream = pyte.Stream(screen)
process = ptyprocess.PtyProcessUnicode.spawn(["zsh"])
process.write("ls -l\n")
while True:
if process.isalive() and process.fd in select.select([process.fd], [], [], 0)[0]:
output = process.read(1024)
stream.feed(output)
cursor_position = screen.cursor
for y, line in enumerate(screen.display):
if y == cursor_position.y:
line = line[: cursor_position.x] + "█" + line[cursor_position.x + 1 :]
print(f"{y}: {line}")
print("---") That is, if I create this as
I was hoping to do the equivalent in Rust, though I assume the answer is the same as the one for @rgwood-dd, which is I need to use the |
Beta Was this translation helpful? Give feedback.
-
Reading https://github.com/wez/wezterm/blob/30345b36d8a00fed347e4df5dadd83915a7693fb/term/README.md, I get the impression I could approximate the above by using |
Beta Was this translation helpful? Give feedback.
-
This seems to work, though it's possible there's a race condition since I'm only checking after invoking In the example, [dependencies]
wezterm-term = { git = "https://github.com/wez/wezterm", rev = "30345b36d8a00fed347e4df5dadd83915a7693fb" } Test for change to local echo: let mut reader = pair.master.try_clone_reader()?;
let mut term: wezterm_term::Terminal = create_term(*rows as usize, *cols as usize);
let mut buf = [0_u8; 1024];
loop {
let n = reader.read(&mut buf)?;
term.advance_bytes(&buf[..n]);
// Poll until local echo is disabled before handing over the terminal,
// as we use that as a heuristic to determine when the shell is ready
// for user input:
// https://github.com/wez/wezterm/discussions/5217
let termios = pair
.master
.get_termios()
.ok_or_else(|| anyhow!("failed to read termios"))?;
let is_echo = termios
.local_flags
.contains(nix::sys::termios::LocalFlags::ECHO);
if !is_echo {
// The terminal is ready.
break;
}
} |
Beta Was this translation helpful? Give feedback.
-
What Operating System(s) are you running on?
macOS
Which Wayland compositor or X11 Window manager(s) are you using?
No response
WezTerm version
wezterm 20240203-110809-5046fc22
Ask your question!
Hi! I am trying to do the following with the help of the excellent
termwiz
crate:Surface
(so I can do interesting things with it)I'm able to do 1 with
portable-pty
and 2 with aParser
, but I'm struggling with 3. Specifically: the main way of interacting withSurface
is applyingChange
structs to it, but I don't haveChange
structs - I have the stream of raw bytes, and a stream ofAction
s from the parser.I could probably roll my own code to convert
Action
s toChange
s, but I suspect I'm probably missing an easier way. Given raw output from a pty, is there an easy way to apply that output to aSurface
?Beta Was this translation helpful? Give feedback.
All reactions