You are not logged in.

#1 2013-07-10 22:31:39

VanillaFunk
Member
From: MA. USA
Registered: 2013-06-10
Posts: 396
Website

gtk terminal

havent had much luck googling anything with an answer
but wanted to know if its possible to embed an interactive terminal in gtk
gonna keep looking but if anyone knows a place to look, please reply here.

Thanks


archx86_64 : awesomewm
https://github.com/dreemsoul

Remeber to feed the squirrels

Offline

#2 2013-07-10 22:34:11

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: gtk terminal

Offline

#3 2013-07-10 22:34:32

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,332
Website

Re: gtk terminal

I don't use toolkits like gtk, but this can be done directly through X with xembed protocol, or even easier with either xterm or urxvt (probably some others) you can invoke them with the "-embed" flag, and just pass the Window id of your gtk "widget" and it will embed itself there.

Edit: there's even example code with urxvt showing how to do this with gtk.  The man page has a very short excerpt using perl, but there are other docs with complete examples.

Last edited by Trilby (2013-07-10 22:42:39)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#4 2013-07-10 22:34:35

WorMzy
Administrator
From: Scotland
Registered: 2010-06-16
Posts: 12,600
Website

Re: gtk terminal

Embed a terminal in a toolkit? What do you mean?


If you want a gtk+ terminal, there's plenty to choose from.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#5 2013-07-10 22:48:31

VanillaFunk
Member
From: MA. USA
Registered: 2013-06-10
Posts: 396
Website

Re: gtk terminal

well just to make it understandable hopefully...

(thnx trilby lookin into that now)

I'm trying to build a gtk app that does my pacman -Syu command and gives me options based on upgradeable packages (which ones i want to install).

so i need to embed a terminal into the app.

thanks didnt expect a handful of responses so quickly.


archx86_64 : awesomewm
https://github.com/dreemsoul

Remeber to feed the squirrels

Offline

#6 2013-07-10 22:52:16

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: gtk terminal

There are some https://wiki.archlinux.org/index.php/Pa … _Frontends , have a look at what they do and how they work.
I don't think a terminal is necessary. IMHO the point of a GUI app is not to have to rely on a terminal.

Last edited by karol (2013-07-10 22:52:53)

Offline

#7 2013-07-10 23:00:47

VanillaFunk
Member
From: MA. USA
Registered: 2013-06-10
Posts: 396
Website

Re: gtk terminal

thanks karol ill give those a look gonna try to build this project anyway for practice sake.  but was gonna have a terminal inserted so i could watch packages get processed. either way thanks all for the help.

--- edit ---

if for example i was using it with yaourt to do aur stuff.

tongue

Last edited by VanillaFunk (2013-07-10 23:03:01)


archx86_64 : awesomewm
https://github.com/dreemsoul

Remeber to feed the squirrels

Offline

#8 2013-07-10 23:03:35

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: gtk terminal

How would that be different from just running 'pacman -Syu' in a terminal? What other functions would your app have?

Offline

#9 2013-07-10 23:14:50

VanillaFunk
Member
From: MA. USA
Registered: 2013-06-10
Posts: 396
Website

Re: gtk terminal

besides teaching me a lot?

the point of this exercize was to learn to embed a terminal inside a gui app

im not trying to learn to build the next best thing to pacman just was the easiest thing i could think of using a terminal for...

when i make it work i can branch of and have it do things like query uneeded packages, remove packages, or other things like that but im still new to programing things in gtk and wanna see what i can tinker with.

Last edited by VanillaFunk (2013-07-10 23:15:30)


archx86_64 : awesomewm
https://github.com/dreemsoul

Remeber to feed the squirrels

Offline

#10 2013-07-10 23:45:17

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,332
Website

Re: gtk terminal

VanillaFunk, you do not want an embedded terminal for this.  You could embed a terminal - if you did you could run pacman in the terminal while the rest of your program did something else.  But your program would not be aware of the state of pacman's progress, nor would pacman be aware of your program.  They would not interact in the way you are describing.

To do what you are describing, you should look at functions like popen, or perhaps if you need full duplex communication do your own fork() dup2() and execv().  With these, your program could interact with what is happening in the "terminal".

You don't need a terminal to run commands like pacman or yaourt - the terminal is just a place where their output goes, and from where they get input.  If you want the output to go to your program and the pacman/yaourt/etc process to get input from your program, then your program will take the place of the terminal.

I'd suggest starting with popen().  You can call pacman, for example, via popen:

    char line[MAX_LINE+1];
    FILE *pac = popen("pacman -Syu","r");
    while(fgets(line,MAX_LINE,pac)) {
        /* draw text from 'line' onto your widget */
    }
    pclose(pac);

This will run pacman -Syu and send all the output to your program, and you can chose how to display it in your gtk widgets.  This is a dangerously trivial example, though, as you will not be able to send anything to pacman, so if there is an update that requires any interaction (asking [Y/n] for example) it will fail.  There are pacman flags to allow for all default answers to be accepted, and while it would solve this issue, it will not generally be a good idea.

This is where two-way communication would be needed rather than the one-directional pipe of popen().  There are various tutorials on this online, but in a nutshell, you will use create a file descriptor pair and use (something like) dup2() to copy stdin/stdout streams, fork() to spawn a separate process, then in one of the forked processes you will rearrange the file descriptors for stdin/stdout, then use and execv() function to run pacman.

As you can see, there is much more to the second version, which is why I recommend starting with popen().  Popen will not do everything you want, but it will allow you to get started easier.

Last edited by Trilby (2013-07-10 23:45:52)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

Board footer

Powered by FluxBB