Terminal emulator in Kivy app

981 views
Skip to first unread message

blarghmatey

unread,
Nov 30, 2012, 11:08:42 PM11/30/12
to kivy-...@googlegroups.com
I'm working on a program where I would like to be able to embed a terminal emulator into Kivy. So far I have managed to enter commands into a text input and show the responses in a label. When I tried to do something a little more interactive like a Python prompt it locked up.

I'm wondering if I should consider using a canvas and overlaying the terminal on that somehow? As to the text input, I'm fine with using a text input but working straight in the terminal would be nice as well. Perhaps if I use the terminal as a texture on the canvas?

Any suggestions would be greatly appreciated.

skeezix

unread,
Nov 30, 2012, 11:21:53 PM11/30/12
to kivy-...@googlegroups.com
On Fri, 30 Nov 2012, blarghmatey wrote:

# I'm working on a program where I would like to be able to embed a terminal emulator into Kivy. So far I have managed to enter commands into a text input and show the responses in a label. When I tried to do something a little more
# interactive like a Python prompt it locked up.
# I'm wondering if I should consider using a canvas and overlaying the terminal on that somehow? As to the text input, I'm fine with using a text input but working straight in the terminal would be nice as well. Perhaps if I use the
# terminal as a texture on the canvas?
# Any suggestions would be greatly appreciated.

I'm doing it on canvas myself ;)

The real trick with terminasl emulation is of course the terminal
emulation .. handling vt100 or ANSI or C64 displays, whatever you're
aiming for; the display is not too bad.. I cheaped it out, did an 80x40
display, with each cell being its own little Rectangle with a texture on
it; you could also do one big rectangle with a tesxture on it and render
to that.. or perhaps one per line, or any number of ways of doing it.

I only briefly did shell terminal (for laughs), and veered another
direction (using it for something else) so my code is fairly specific ..
but its certainly doable, anyway.

(I'll probably toss mine out entirely and use something like the
bbcode-supporting widgets kivy has, so as to get easy colour and bolding
and such, since my needs are fairly limited.)

jeff

--
If everyone would put barbecue sauce on their food, there would be no war.

Akshay Arora

unread,
Dec 1, 2012, 7:01:31 AM12/1/12
to kivy-...@googlegroups.com
Oh nice, @skeezix could you post the code/the approach you took? Emulating the whole terminal sounds interesting.
I would be very interested in looking at how you went about it.

I only tried a simple command interaction by running commands through subprocess.popen.
http://github.com/akshayaurora/kivy kivy_console branch

@blarghmatey, you would need to use threads so as to ensure kivy's eventloop doesn't lockup. Keep in mind to do all
GUI operations in Kivy's main thread. Caling a function in your thread through Clock.schedule_* should execute it in the main thread.


--



Akshay Arora

unread,
Dec 1, 2012, 7:16:01 AM12/1/12
to kivy-...@googlegroups.com
Just realized I only linked to the repo and not the actual file, here is the actual fie concerned that houses the code https://github.com/akshayaurora/kivy/blob/kivy_console/kivy/uix/kivyconsole.py

blarghmatey

unread,
Dec 1, 2012, 8:39:18 AM12/1/12
to kivy-...@googlegroups.com
@skeezix, which widgets are you referring to when you say they support bb-code. I would be interested in understanding more about that.

Thank you for your help. @qua-non, you as well. Your sample code will be very useful.

Akshay Arora

unread,
Dec 1, 2012, 9:30:30 AM12/1/12
to kivy-...@googlegroups.com
Label itself supports markup, http://kivy.org/docs/api-kivy.uix.label.html#module-kivy.uix.label
Then there is RstDocument is an easy-to-read, what-you-see-is-what-you-get plaintext markup syntax and parser system http://kivy.org/docs/api-kivy.uix.rst.html
There is also CodeInput that is basically a TextInput that highlights text defined by a lexer written for pygments.

On Sat, Dec 1, 2012 at 7:09 PM, blarghmatey <blarg...@gmail.com> wrote:
@skeezix, which widgets are you referring to when you say they support bb-code. I would be interested in understanding more about that.

Thank you for your help. @qua-non, you as well. Your sample code will be very useful.

--



blarghmatey

unread,
Dec 1, 2012, 11:10:27 AM12/1/12
to kivy-...@googlegroups.com
@skeezix,

Would it be possible to get a snippet of example code for how you are managing the terminal in a canvas?

skeezix

unread,
Dec 1, 2012, 10:26:16 PM12/1/12
to kivy-...@googlegroups.com
On Sat, 1 Dec 2012, Akshay Arora wrote:

# Oh nice, @skeezix could you post the code/the approach you took? Emulating the whole terminal sounds interesting.
# I would be very interested in looking at how you went about it.

Oh, I didn't get very far.. just starting building various options
and actually forking a shell and handling its basic stdio is only a few
lines of code.. but I didn't bother trying to do the terminal emulation;
for what I was doing, I didn't need to bother (but have done it before in
other projects.) ie: I just wanted to write keyb input out to its stdin,
and capture its stdout and display on something. I've already got an
enormous canvas 'thing' going on, so this just fed into it.

Its not practical to share due to the convoluted canvas stuff its
doing (and I'm keeping this particular project closed at least for now
I'ma fraid). (Its a game, and has a vaguely terminal like thing as just
one of the widgets on the display, but the whole display is tied
together.)

What I was doing was a cell (rectangle with texture) per character
though, to be most authentic; pretty easy to implement. You could use na
Array, but I just used a list (rows) of list (column) and had a Rectangle
for each cell in there. Add a texture for the character, and good to go.
(I pre-created the character-set to texture mapping, so as to re-use
textures as needed without recreating them for each cell.. that woudl have
been wasteful.)
Reply all
Reply to author
Forward
0 new messages