set a custom timeout before executing send-keys for commands

In some situations send-keys might fire before the shell prompt
  finished initilization. It happened for me when using fish shell and
  *oh-my-fish* which makes the send-keys start executing bofore my shell
  is ready and I endup with a written command that is not executed

  This patch adds a custom `sendkeys_timeout` as a top level option that
  takes an integer in milliseconds. It will ensure a Sleep call is made
  before.
sendkeys-timeout
spike 2 years ago
parent f5c5c51f2f
commit 80205349b5

@ -27,12 +27,13 @@ type Window struct {
} }
type Config struct { type Config struct {
Session string `yaml:"session"` SendKeysTimeout int `yaml:"sendkeys_timeout"`
Env map[string]string `yaml:"env"` Session string `yaml:"session"`
Root string `yaml:"root"` Env map[string]string `yaml:"env"`
BeforeStart []string `yaml:"before_start"` Root string `yaml:"root"`
Stop []string `yaml:"stop"` BeforeStart []string `yaml:"before_start"`
Windows []Window `yaml:"windows"` Stop []string `yaml:"stop"`
Windows []Window `yaml:"windows"`
} }
func addDefaultEnvs(c *Config, path string) { func addDefaultEnvs(c *Config, path string) {

@ -9,6 +9,7 @@ import (
func TestParseConfig(t *testing.T) { func TestParseConfig(t *testing.T) {
yaml := ` yaml := `
session: ${session} session: ${session}
sendkeys_timeout: 200
windows: windows:
- layout: tiled - layout: tiled
commands: commands:
@ -28,6 +29,7 @@ windows:
expected := Config{ expected := Config{
Session: "test", Session: "test",
SendKeysTimeout: 200,
Env: make(map[string]string), Env: make(map[string]string),
Windows: []Window{ Windows: []Window{
{ {

@ -6,6 +6,7 @@ import (
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"strings" "strings"
"time"
) )
const defaultWindowName = "smug_def" const defaultWindowName = "smug_def"
@ -153,6 +154,7 @@ func (smug Smug) Start(config *Config, options *Options, context Context) error
} }
for _, c := range w.Commands { for _, c := range w.Commands {
time.Sleep(time.Millisecond * time.Duration(config.SendKeysTimeout))
err := smug.tmux.SendKeys(window, c) err := smug.tmux.SendKeys(window, c)
if err != nil { if err != nil {
return err return err
@ -180,6 +182,7 @@ func (smug Smug) Start(config *Config, options *Options, context Context) error
} }
for _, c := range p.Commands { for _, c := range p.Commands {
time.Sleep(time.Millisecond * time.Duration(config.SendKeysTimeout))
err = smug.tmux.SendKeys(window+"."+newPane, c) err = smug.tmux.SendKeys(window+"."+newPane, c)
if err != nil { if err != nil {
return err return err

Loading…
Cancel
Save