Giter Club home page Giter Club logo

go-tmux's People

Contributors

azurethi avatar japiotr123 avatar jubnzv avatar madflow avatar thavlik avatar yitsushi avatar yuguorui avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

go-tmux's Issues

Make panes and windows selectable

package main

import (
	gotmux "github.com/jubnzv/go-tmux"
)

func main() {
	server := new(gotmux.Server)

	session := gotmux.Session{Name: "windows-panes"}
	pane1 := gotmux.Pane{ID: 1}
	pane2 := gotmux.Pane{ID: 2}
	w1 := gotmux.Window{Name: "window-1", Id: 0}
	w1.AddPane(pane1)
	w1.AddPane(pane2)
	w2 := gotmux.Window{Name: "window-2", Id: 1}

	session.AddWindow(w1)
	session.AddWindow(w2)
	server.AddSession(session)
	sessions := []*gotmux.Session{}
	sessions = append(sessions, &session)
	conf := gotmux.Configuration{
		Server:        server,
		Sessions:      sessions,
		ActiveSession: nil,
	}

	err := conf.Apply()
	if err != nil {
		panic(err)
	}

	currentWindows, _ := session.ListWindows()

	// select the first window
	firstWindow := currentWindows[0]
	firstWindow.Select()

	// select the second pane in the first window
	currentPanes, _ := firstWindow.ListPanes()
	secondPane := currentPanes[1]
	secondPane.Select()

	err = session.AttachSession()
	if err != nil {
		panic(err)
	}
}

Session StartDirectory is ignored

package main

import (
	"fmt"

	gotmux "github.com/jubnzv/go-tmux"
)

func main() {
	// Create instance of the running tmux server.
	server := new(gotmux.Server)

	// Prepare a configuration for the new session that contains some windows.
	session := gotmux.Session{Name: "windows-panes", StartDirectory: "/tmp/"}
	w := gotmux.Window{Name: "default-tmp", Id: 0}

	session.AddWindow(w)
	server.AddSession(session)
	sessions := []*gotmux.Session{}
	sessions = append(sessions, &session)
	conf := gotmux.Configuration{
		Server:        server,
		Sessions:      sessions,
		ActiveSession: nil,
	}

	// Setup this configuration.
	err := conf.Apply()
	if err != nil {
		msg := fmt.Errorf("Can't apply prepared configuration: %s", err)
		fmt.Println(msg)
		return
	}

	currentWindows, _ := session.ListWindows()
	for _, w := range currentWindows {
		fmt.Printf("Current window: %v\n", w)
		currentPanes, _ := w.ListPanes()
		fmt.Printf("Current panes: %v\n", currentPanes)
		fmt.Println()
	}

	// Attach to the created session
	err = session.AttachSession()
	if err != nil {
		msg := fmt.Errorf("Can't attached to created session: %s", err)
		fmt.Println(msg)
		return
	}
}
Current window: {default-tmp 1 0 windows-panes /madflow/go-tmux []}

I would expect the windows directory to be "/tmp/".

pane.RunCommand failure for mutli session

I running func (p *Pane) RunCommand(command string) error is successful, when only exist one session.
But it may be failed when there is multi-session, because of can not find pane in window.
I guess pane index should be used in Pane.RunCommand instead of p.ID(is pane globally unique id in reality)๏ผŒ or modify command format after -tใ€‚
In multi-session, the value of pane global unique id may be beyond pane number of same window.

Window.ListPanes returns all panes

Considering the follwing example:

package main

import (
	"fmt"

	gotmux "github.com/jubnzv/go-tmux"
)

func main() {
	// Create instance of the running tmux server.
	server := new(gotmux.Server)

	// Prepare a configuration for the new session that contains some windows.
	session := gotmux.Session{Name: "windows-panes", StartDirectory: "/tmp/"}
	w1 := gotmux.Window{Name: "first", Id: 0, StartDirectory: "/tmp/"}
	w2 := gotmux.Window{Name: "second", Id: 1}

	w2.AddPane(gotmux.Pane{
		ID: 0,
	})

	w2.AddPane(gotmux.Pane{
		ID: 1,
	})

	w2.AddPane(gotmux.Pane{
		ID: 3,
	})

	session.AddWindow(w1)
	session.AddWindow(w2)
	server.AddSession(session)
	sessions := []*gotmux.Session{}
	sessions = append(sessions, &session)
	conf := gotmux.Configuration{
		Server:        server,
		Sessions:      sessions,
		ActiveSession: nil,
	}

	// Setup this configuration.
	err := conf.Apply()
	if err != nil {
		msg := fmt.Errorf("Can't apply prepared configuration: %s", err)
		fmt.Println(msg)
		return
	}

	currentWindows, _ := session.ListWindows()
	for _, w := range currentWindows {
		fmt.Printf("Current window: %v\n", w)
		currentPanes, _ := w.ListPanes()
		fmt.Printf("Current panes: %v\n", currentPanes)
	}

	// Attach to the created session
	err = session.AttachSession()
	if err != nil {
		msg := fmt.Errorf("Can't attached to created session: %s", err)
		fmt.Println(msg)
		return
	}
}

This outputs

Current window: {first 29 0 windows-panes /private/tmp  []}
Current panes: [{45 12 windows-panes 29 first 0 true} {46 12 windows-panes 30 second 1 false} {47 12 windows-panes 30 second 1 false} {48 12 windows-panes 30 second 1 true}]
Current window: {second 30 0 windows-panes /go-tmux  []}
Current panes: [{45 12 windows-panes 29 first 0 true} {46 12 windows-panes 30 second 1 false} {47 12 windows-panes 30 second 1 false} {48 12 windows-panes 30 second 1 true}]

I would expect, that only Panes of the specific window should be returned.

Is this a "bug" and would a PR be acceptable?

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.