1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Expose the widget dimensions to commands in cmdrunner

This commit is contained in:
Tim Scheuermann 2019-10-09 14:55:23 +02:00
parent 4ef6eb76c6
commit 4e529b49e6
2 changed files with 18 additions and 0 deletions

View File

@ -19,6 +19,10 @@ type Settings struct {
cmd string `help:"The terminal command to be run, withouth the arguments. Ie: ping, whoami, curl."` cmd string `help:"The terminal command to be run, withouth the arguments. Ie: ping, whoami, curl."`
tail bool `help:"Automatically scroll to the end of the command output."` tail bool `help:"Automatically scroll to the end of the command output."`
maxLines int `help:"Maximum number of lines kept in the buffer."` maxLines int `help:"Maximum number of lines kept in the buffer."`
// The dimensions of the module
width int
height int
} }
// NewSettingsFromYAML loads the cmdrunner portion of the WTF config // NewSettingsFromYAML loads the cmdrunner portion of the WTF config
@ -33,5 +37,7 @@ func NewSettingsFromYAML(name string, moduleConfig *config.Config, globalConfig
maxLines: moduleConfig.UInt("maxLines", 256), maxLines: moduleConfig.UInt("maxLines", 256),
} }
settings.width, settings.height = utils.CalculateDimensions(moduleConfig, globalConfig)
return &settings return &settings
} }

View File

@ -3,6 +3,7 @@ package cmdrunner
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"os"
"os/exec" "os/exec"
"strings" "strings"
"sync" "sync"
@ -108,6 +109,7 @@ func (widget *Widget) execute() {
// Setup the command to run // Setup the command to run
cmd := exec.Command(widget.settings.cmd, widget.settings.args...) cmd := exec.Command(widget.settings.cmd, widget.settings.args...)
cmd.Stdout = widget cmd.Stdout = widget
cmd.Env = widget.environment()
// Run the command and wait for it to exit in another Go-routine // Run the command and wait for it to exit in another Go-routine
go func() { go func() {
@ -134,3 +136,13 @@ func (widget *Widget) drainLines(n int) {
widget.buffer.ReadBytes('\n') widget.buffer.ReadBytes('\n')
} }
} }
func (widget *Widget) environment() []string {
envs := os.Environ()
envs = append(
envs,
fmt.Sprintf("WTF_WIDGET_WIDTH=%d", widget.settings.width),
fmt.Sprintf("WTF_WIDGET_HEIGHT=%d", widget.settings.height),
)
return envs
}