Giter Site home page Giter Site logo

VTE bindings about gotk4 HOT 14 CLOSED

jgillich avatar jgillich commented on September 21, 2024
VTE bindings

from gotk4.

Comments (14)

jgillich avatar jgillich commented on September 21, 2024

Aha, played a bit with the generator and it turns out I just needed to add the namespace:

{Name: "vte-2.91-gtk4", Namespaces: []string{"Vte-3"}},

No idea what the difference between Vte-2 and Vte-3 is though

from gotk4.

jgillich avatar jgillich commented on September 21, 2024

I almost got it working (repo), but the most important function vte_pty_spawn_async is missing, making it rather useless 😄

Debug output gives a hint, it's because Glib.Pid is skipped

girgen: debug: package vte/v3: filtering type GLib.Pid (C.GPid) using filter types.absoluteFilter, trace: github.com/diamondburned/gotk4/gir/cmd/gir-generate/gendata.init @ gendata.go:348
girgen: debug: package vte/v3: ignored type GLib.Pid
girgen: debug: package vte/v3: callback TerminalSpawnAsyncCallback (C.): C arg2 -> Go _pid (in): can't resolve C.GPid
girgen: debug: package vte/v3: callback TerminalSpawnAsyncCallback (C.): C arg2 -> Go _pid (in): cannot resolve type
girgen: debug: package vte/v3: callback TerminalSpawnAsyncCallback (C.): C arg2 -> Go _pid (in): no conversion
girgen: debug: package vte/v3: callback TerminalSpawnAsyncCallback (C.): has no conversion

AbsoluteFilter("GLib.Pid"),

Pid is an int on Linux and a process handle on Windows h

gtk-rs supports this: https://github.com/gi-rust/glib-sys/blob/cd5bf488b32b01cff76da88100ab9c7d2478fe9d/lib.rs#L86-L90

We could probably do something similar with go tags if we extend the generator. Thoughts? I'll probably try once I find the time, but perhaps you have some pointers

from gotk4.

diamondburned avatar diamondburned commented on September 21, 2024

The easiest way to do this is to add GPID in as a built-in for core/glib. You can then add special code for this in types, typeconv and the callable generators. It's kind of a pain to do it, but it's the easiest way.

from gotk4.

diamondburned avatar diamondburned commented on September 21, 2024

It might be best to declare the built-in as type PID C.GPid rather than using build tags.

from gotk4.

diamondburned avatar diamondburned commented on September 21, 2024

Out of curiosity, have you tried combining vte.Pty with os/exec.Command? It looks like you could allocate a new Pty and use its fd as the value for cmd.Stdout?

Also, Pty should be strcased to be PTY.

from gotk4.

diamondburned avatar diamondburned commented on September 21, 2024

Potentially this...

screenshot of terminal running bash mostly fine
Code
package main

import (
	"context"
	"os/exec"

	"github.com/creack/pty"
	"github.com/diamondburned/gotk4/pkg/core/glib"
	"github.com/diamondburned/gotk4/pkg/gio/v2"
	"github.com/diamondburned/gotk4/pkg/gtk/v4"
	"github.com/jgillich/gotk4-vte/pkg/vte/v3"
)

func main() {
	app := gtk.NewApplication("so.libdb.gotk4-vte-test", gio.ApplicationFlagsNone)
	app.ConnectActivate(func() { activate(app) })
	app.Run(nil)
}

func activate(app *gtk.Application) {
	terminal := vte.NewTerminal()
	terminal.SetSize(80, 24)

	go func() {
		tty, err := pty.Start(exec.Command("bash"))
		if err != nil {
			panic(err)
		}

		pty, err := vte.NewPtyForeignSync(context.Background(), int(tty.Fd()))
		if err != nil {
			panic(err)
		}

		glib.IdleAdd(func() {
			terminal.SetPty(pty)
		})
	}()

	win := gtk.NewApplicationWindow(app)
	win.SetTitle("VTE Example")
	win.SetChild(terminal)
	win.Show()
}

from gotk4.

diamondburned avatar diamondburned commented on September 21, 2024

strcases:

  • Pty -> PTY
  • Tty -> TTY
  • Icu -> ICU
  • Cjk -> CJK
  • Sixel -> SIXEL

from gotk4.

diamondburned avatar diamondburned commented on September 21, 2024

How's this!

vte example running neofetch in /bin/sh

from gotk4.

diamondburned avatar diamondburned commented on September 21, 2024

Windows compatibility will need to be tested... Note that (*os.File).Fd() on Windows returns a uintptr! Our NewPtyForeignSync is not portable because it still takes in an int there...

It might be a good idea to manually create a vte_windows.go file with a type Fd = uintptr, then generate NewPtyForeignSync to use Fd instead of int.

from gotk4.

jgillich avatar jgillich commented on September 21, 2024

Haha nice! Looks like I could've saved myself a lot of pain. creack/pty doesn't support Windows at all, but VTE's pty should work too...

#129 does at least compile now, but it's likely going to explode at runtime 😄

from gotk4.

diamondburned avatar diamondburned commented on September 21, 2024

but VTE's pty should work too...

You might still want to get its functions working then... I can pick up the glib.PID PR in a few days likely. It seems to be a fairly important type.

Does glib have an Fd type already as well? We could add that in also.

from gotk4.

jgillich avatar jgillich commented on September 21, 2024

terminal.PtyNewSync already works, it's only the spawn function that's missing. At first I couldn't figure out how to hook it up, but after some Unix 101 I realized I needed a tty from the pty. Copied a few lines from creack/pty for now as I couldn't find it in VTE. https://github.com/getseabird/seabird/blob/535cce58b5d1919c5bc04b04d3e2cb54c9c52b8c/ui/terminal_page_unix.go#L43

But it appears that VTE doesn't support Windows at all. Bummer for my cross-platform app

from gotk4.

diamondburned avatar diamondburned commented on September 21, 2024

But it appears that VTE doesn't support Windows at all.

Oh, I actually didn't know that at all...

from gotk4.

pekim avatar pekim commented on September 21, 2024

But it appears that VTE doesn't support Windows at all.

Yes, there's a 5 year old issue, https://gitlab.gnome.org/GNOME/vte/-/issues/86. And it doesn't look likely that it'll be addressed any time soon.

from gotk4.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.