From 84501296f3aed22db481322176043a1c03656be9 Mon Sep 17 00:00:00 2001 From: Liam Burnand Date: Sat, 16 Dec 2023 14:12:23 +0000 Subject: [PATCH] Deleting gomux --- gomux/cmd.go | 110 ------------------------- gomux/go.mod | 3 - gomux/go.sum | 0 gomux/gomux.go | 212 ------------------------------------------------- 4 files changed, 325 deletions(-) delete mode 100644 gomux/cmd.go delete mode 100644 gomux/go.mod delete mode 100644 gomux/go.sum delete mode 100644 gomux/gomux.go diff --git a/gomux/cmd.go b/gomux/cmd.go deleted file mode 100644 index 1cca479..0000000 --- a/gomux/cmd.go +++ /dev/null @@ -1,110 +0,0 @@ -package gomux - -import "fmt" - -type killSession struct { - t string -} - -func (this killSession) String() string { - return fmt.Sprintf("tmux kill-Session -t \"%s\" > /dev/null 2>&1\n", this.t) -} - -type newSession struct { - d bool - s string - n string - c string -} - -func (this newSession) String() string { - cmd := "tmux new-Session" - if this.d == true { - cmd += " -d" - } - if this.s != "" { - cmd += " -s \"" + this.s + "\"" - } - if this.n != "" { - cmd += " -n " + this.n - } - if this.c != "" { - cmd += " -c " + this.c - } - return cmd + "\n" -} - -type splitWindow struct { - h bool - v bool - t string - c string -} - -func (this splitWindow) String() string { - cmd := "tmux split-Window" - if this.h == true { - cmd += " -h" - } - if this.v == true { - cmd += " -v" - } - if this.t != "" { - cmd += " -t \"" + this.t + "\"" - } - if this.c != "" { - cmd += " -c " + this.c - } - return cmd + "\n" -} - -type newWindow struct { - t string - n string - c string -} - -func (this newWindow) String() string { - cmd := "tmux new-Window" - if this.t != "" { - cmd += " " + this.t - } - if this.n != "" { - cmd += " -n \"" + this.n + "\"" - } - - if this.c != "" { - cmd += " -c " + this.c - } - return cmd + "\n" -} - -type renameWindow struct { - t string - n string -} - -func (this renameWindow) String() string { - cmd := "tmux rename-Window" - if this.t != "" { - cmd += " " + this.t - } - if this.n != "" { - cmd += " \"" + this.n + "\"" - } - - return cmd + "\n" -} - -type selectWindow struct { - t string -} - -func (this selectWindow) String() string { - cmd := "tmux select-Window" - if this.t != "" { - cmd += " -t \"" + this.t + "\"" - } - - return cmd + "\n" -} diff --git a/gomux/go.mod b/gomux/go.mod deleted file mode 100644 index ac6d0be..0000000 --- a/gomux/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module github.com/ystv/streamer/gomux - -go 1.21 diff --git a/gomux/go.sum b/gomux/go.sum deleted file mode 100644 index e69de29..0000000 diff --git a/gomux/gomux.go b/gomux/gomux.go deleted file mode 100644 index 661eed3..0000000 --- a/gomux/gomux.go +++ /dev/null @@ -1,212 +0,0 @@ -package gomux - -import ( - "fmt" - "io" - "strings" -) - -type Pane struct { - Number int - commands []string - Window *Window -} - -func NewPane(number int, window *Window) *Pane { - p := new(Pane) - p.Number = number - p.commands = make([]string, 0) - p.Window = window - return p -} - -type SplitAttr struct { - Directory string -} - -func (this *Pane) Exec(command string) { - fmt.Fprintf(this.Window.Session.Writer, "tmux send-keys -t \"%s\" \"%s\" %s\n", this.getTargetName(), strings.Replace(command, "\"", "\\\"", -1), "C-m") -} - -func (this *Pane) Vsplit() *Pane { - fmt.Fprint(this.Window.Session.Writer, splitWindow{h: true, t: this.getTargetName()}) - return this.Window.AddPane(this.Number + 1) -} - -func (this *Pane) VsplitWAttr(attr SplitAttr) *Pane { - var c string - if attr.Directory != "" { - c = attr.Directory - } else if this.Window.Directory != "" { - c = this.Window.Directory - } else if this.Window.Session.Directory != "" { - c = this.Window.Session.Directory - } - - fmt.Fprint(this.Window.Session.Writer, splitWindow{h: true, t: this.getTargetName(), c: c}) - return this.Window.AddPane(this.Number + 1) -} - -func (this *Pane) Split() *Pane { - fmt.Fprint(this.Window.Session.Writer, splitWindow{v: true, t: this.getTargetName()}) - return this.Window.AddPane(this.Number + 1) -} - -func (this *Pane) SplitWAttr(attr SplitAttr) *Pane { - var c string - if attr.Directory != "" { - c = attr.Directory - } else if this.Window.Directory != "" { - c = this.Window.Directory - } else if this.Window.Session.Directory != "" { - c = this.Window.Session.Directory - } - - fmt.Fprint(this.Window.Session.Writer, splitWindow{v: true, t: this.getTargetName(), c: c}) - return this.Window.AddPane(this.Number + 1) -} - -func (this *Pane) ResizeRight(num int) { - this.resize("R", num) -} - -func (this *Pane) ResizeLeft(num int) { - this.resize("L", num) -} - -func (this *Pane) ResizeUp(num int) { - this.resize("U", num) -} - -func (this *Pane) ResizeDown(num int) { - this.resize("U", num) -} - -func (this *Pane) resize(prefix string, num int) { - fmt.Fprintf(this.Window.Session.Writer, "tmux resize-pane -t \"%s\" -%s %v\n", this.getTargetName(), prefix, fmt.Sprint(num)) -} - -func (this *Pane) getTargetName() string { - return this.Window.Session.Name + ":" + fmt.Sprint(this.Window.Number) + "." + fmt.Sprint(this.Number) -} - -// Window Represent a tmux Window. You usually should not create an instance of Window directly. -type Window struct { - Number int - Name string - Directory string - Session *Session - panes []*Pane - split_commands []string -} - -type WindowAttr struct { - Name string - Directory string -} - -func createWindow(number int, attr WindowAttr, session *Session) *Window { - w := new(Window) - w.Name = attr.Name - w.Directory = attr.Directory - w.Number = number - w.Session = session - w.panes = make([]*Pane, 0) - w.split_commands = make([]string, 0) - w.AddPane(0) - - if number != 0 { - fmt.Fprint(session.Writer, newWindow{t: w.t(), n: w.Name, c: attr.Directory}) - } - - fmt.Fprint(session.Writer, renameWindow{t: w.t(), n: w.Name}) - return w -} - -func (this *Window) t() string { - return fmt.Sprintf("-t \"%s:%s\"", this.Session.Name, fmt.Sprint(this.Number)) -} - -// Create a new Pane and add to this Window -func (this *Window) AddPane(withNumber int) *Pane { - pane := NewPane(withNumber, this) - this.panes = append(this.panes, pane) - return pane -} - -// Find and return the Pane object by its index in the panes slice -func (this *Window) Pane(number int) *Pane { - return this.panes[number] -} - -// Executes a command on the first pane of this Window -// -// // example -// // example -func (this *Window) Exec(command string) { - this.Pane(0).Exec(command) -} - -func (this *Window) Select() { - fmt.Fprint(this.Session.Writer, selectWindow{t: this.Session.Name + ":" + fmt.Sprint(this.Number)}) -} - -// Session represents a tmux Session. -// -// Use the method NewSession to create a Session instance. -type Session struct { - Name string - Directory string - windows []*Window - directory string - next_window_number int - Writer io.Writer -} - -// Creates a new Tmux Session. It will kill any existing Session with the provided name. -func NewSession(name string, writer io.Writer) *Session { - p := SessionAttr{ - Name: name, - } - return NewSessionAttr(p, writer) -} - -type SessionAttr struct { - Name string - Directory string -} - -// Creates a new Tmux Session based on NewSessionAttr. It will kill any existing Session with the provided name. -func NewSessionAttr(p SessionAttr, writer io.Writer) *Session { - s := new(Session) - s.Writer = writer - s.Name = p.Name - s.Directory = p.Directory - s.windows = make([]*Window, 0) - - fmt.Fprint(writer, newSession{d: true, s: p.Name, c: p.Directory, n: "tmp"}) - return s -} - -// KillSession sends a command to kill the tmux Session -func KillSession(name string, writer io.Writer) { - fmt.Fprint(writer, killSession{t: name}) -} - -// Creates Window with provided name for this Session -func (this *Session) AddWindow(name string) *Window { - - attr := WindowAttr{ - Name: name, - } - - return this.AddWindowAttr(attr) -} - -// Creates Window with provided name for this Session -func (this *Session) AddWindowAttr(attr WindowAttr) *Window { - w := createWindow(this.next_window_number, attr, this) - this.windows = append(this.windows, w) - this.next_window_number = this.next_window_number + 1 - return w -}