Comments (2)
Hi @dc-git-git , sorry for the late response.
Is it possible to create multiple Pane
instances in your code? I mean, each Pane
has the SessionName
attribute, which is created when initializing the Session
instance (see example).
Therefore, I assume, you can create multiple sessions in your code and access their panes. Otherwise, could you please explain your use-case in more details?
from go-tmux.
Sorry for the late response and unclear statement。
My testing environment is:
I has owner a other session that create by command tmux new -t test-session
directly。
$ tmux ls
test-session: 1 windows (created Mon Apr 3 16:49:17 2023)
Then I want running a command in pane using example code(only using one window):
Code added by me in example code:
currPane, _ := w1.ListPanes()
fmt.Println("pance :", currPane)
err = currPane[0].RunCommand("yes")
if err != nil {
fmt.Println("run command in pane 0 err: ", err)
}
Here is the full code:
package main
import (
"fmt"
gotmux "github.com/jubnzv/go-tmux"
)
func main() {
// Create instance of running tmux server.
server := new(gotmux.Server)
// Check that "example" session already exists.
exists, err := server.HasSession("example")
if err != nil {
msg := fmt.Errorf("Can't check 'example' session: %s", err)
fmt.Println(msg)
return
}
if exists {
// Sure, you can use KillSession here.
fmt.Println("Session 'example' already exists!")
fmt.Println("Please stop it before running this demo.")
return
}
// Prepare configuration for a new session with some windows.
session := gotmux.Session{Name: "example-session"}
w1 := gotmux.Window{Name: "first", Id: 0}
// w2 := gotmux.Window{Name: "second", 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}
// Setup this configuration.
err = conf.Apply()
if err != nil {
msg := fmt.Errorf("Can't apply prepared configuration: %s", err)
fmt.Println(msg)
return
}
// new add code by me
currPane, _ := w1.ListPanes()
fmt.Println("pance :", currPane)
err = currPane[0].RunCommand("yes")
if err != nil {
fmt.Println("run command in pane 0 err: ", err)
}
// Attach to created session
err = session.AttachSession()
if err != nil {
msg := fmt.Errorf("Can't attached to created session: %s", err)
fmt.Println(msg)
return
}
}
When I run code, error occurred:
run command in pane 0 err: exit status 1: can't find window: 63
Check id of tmux window and pane by command and show:
$ tmux list-panes -t example-session -F "#{window_index}:#{window_id}:#{pane_index}:#{pane_id}"
0:@63:0:%85
According to the result of tmux list-panes ...
command。 63 is windows globally unique id, but it is used as an Index in function Pane.RunCommand
.
If modify id in Pane forcibly:
// new add code by me
currPane, _ := w1.ListPanes()
fmt.Println("pance :", currPane)
currPane[0].ID = 0 // modify id using index
currPane[0].WindowId = 0 // modify id using index
err = currPane[0].RunCommand("yes")
if err != nil {
fmt.Println("run command in pane 0 err: ", err)
}
Running code is ok. And that's exactly what I expected
So overall, I think Id
and Index
of pane and window is confused in function Pane.RunCommand
。
My tmux version is tmux 3.0a
I using ubuntu: Linux megvii-cp 5.15.0-67-generic #74~20.04.1-Ubuntu SMP Wed Feb 22 14:52:34 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
Thanks.
from go-tmux.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-tmux.