lxsang / PTerm

MIT License
35 stars 8 forks source link

Headless? #49

Closed seandenigris closed 2 years ago

seandenigris commented 2 years ago

Is it possible to use PTerm without the GUI? I'm on GT and would still like to use it from, say, a playground.

I tried:

term := PTerm new xspawn: { '/bin/bash' } , #('-i') env: TerminalEmulator environ.

term asProtocolStack
        push: TerminalEmulatorXterm new;
        install;
        run.

term

but got:

Screen Shot 2022-08-26 at 3 02 32 PM

I guess I could just let the window open in Morphic and ignore it. Although it seems it's not so easy to get ahold of the underlying model. This is the best I could come up with:

term := TerminalEmulator openBash.
term model session tail nextPutAllCr: 'ls'

Is there a better way?

Rinzwind commented 2 years ago

This reminds me of the question on Stack Overflow titled “VT100 screen scraping interface for Smalltalk”. I’m not sure if that’s what you’re looking for, and the internals of TerminalEmulator don’t seem designed to facilitate screen scraping, but I guess you could still create a subclass in which you override ‘openInWorld’ to do nothing (just return ‘self’). Then the following will not show the morph, but will still give you a TerminalEmulatorTextState with the output of the first example command:

term := TerminalEmulatorNoOpen openBash.
term model session tail nextPutAllCr: 'tput setaf 1; printf "%s " Hello; tput setaf 2; printf "%s\n" World; tput sgr0'.
"term model session tail nextPutAllCr: 'exit'."
term tty lineAt: 3
seandenigris commented 2 years ago

I think something like your example might work well. I guess if I find the time I could extract the interface parts from the display parts, but I don't mind starting with something simple. I'll close for now and report any updates here.