From 6b2a53e7a713d9c1a01da945d30fbb8a5e8ebac8 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Tue, 8 Oct 2019 17:33:50 -0700 Subject: [PATCH 1/7] Clean up go.mod Signed-off-by: Chris Cummer --- go.mod | 1 - 1 file changed, 1 deletion(-) diff --git a/go.mod b/go.mod index bf615807..7942aba1 100644 --- a/go.mod +++ b/go.mod @@ -27,7 +27,6 @@ require ( github.com/go-ole/go-ole v1.2.4 // indirect github.com/godbus/dbus v5.0.1+incompatible // indirect github.com/gogo/protobuf v1.3.0 // indirect - github.com/google/btree v1.0.0 // indirect github.com/google/go-cmp v0.3.1 // indirect github.com/google/go-github/v26 v26.1.3 github.com/hashicorp/go-cleanhttp v0.5.1 // indirect From 4ef6eb76c6672153af57190d292d43ff197605f0 Mon Sep 17 00:00:00 2001 From: Tim Scheuermann Date: Wed, 9 Oct 2019 14:54:47 +0200 Subject: [PATCH 2/7] Added utils.CalculateDimensions --- utils/utils.go | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/utils/utils.go b/utils/utils.go index d01b79f8..d5bf07a9 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -10,6 +10,8 @@ import ( "regexp" "runtime" "strings" + + "github.com/olebedev/config" ) const ( @@ -144,3 +146,53 @@ func ParseJson(obj interface{}, text io.Reader) error { } return nil } + +// CalculateDimensions reads the module dimensions from the module and global config. The border is already substracted. +func CalculateDimensions(moduleConfig, globalConfig *config.Config) (int, int) { + // Read the source data from the config + left := moduleConfig.UInt("position.left", 0) + top := moduleConfig.UInt("position.top", 0) + width := moduleConfig.UInt("position.width", 0) + height := moduleConfig.UInt("position.height", 0) + + cols := ToInts(globalConfig.UList("wtf.grid.columns")) + rows := ToInts(globalConfig.UList("wtf.grid.rows")) + + // Make sure the values are in bounds + left = clamp(left, 0, len(cols)-1) + top = clamp(top, 0, len(rows)-1) + width = clamp(width, 0, len(cols)-left) + height = clamp(height, 0, len(rows)-top) + + // Start with the border subtracted and add all the spanned rows and cols + w, h := -2, -2 + for _, x := range cols[left : left+width] { + w += x + } + for _, y := range rows[top : top+height] { + h += y + } + + // The usable space may be empty + w = max(w, 0) + h = max(h, 0) + + return w, h +} + +func max(a, b int) int { + if a > b { + return a + } + return b +} + +func clamp(x, a, b int) int { + if a > x { + return a + } + if b < x { + return b + } + return x +} From 4e529b49e64630e58af330e64f5ba6295be2cc19 Mon Sep 17 00:00:00 2001 From: Tim Scheuermann Date: Wed, 9 Oct 2019 14:55:23 +0200 Subject: [PATCH 3/7] Expose the widget dimensions to commands in cmdrunner --- modules/cmdrunner/settings.go | 6 ++++++ modules/cmdrunner/widget.go | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/modules/cmdrunner/settings.go b/modules/cmdrunner/settings.go index 3f6c13db..f1c33f04 100644 --- a/modules/cmdrunner/settings.go +++ b/modules/cmdrunner/settings.go @@ -19,6 +19,10 @@ type Settings struct { 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."` 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 @@ -33,5 +37,7 @@ func NewSettingsFromYAML(name string, moduleConfig *config.Config, globalConfig maxLines: moduleConfig.UInt("maxLines", 256), } + settings.width, settings.height = utils.CalculateDimensions(moduleConfig, globalConfig) + return &settings } diff --git a/modules/cmdrunner/widget.go b/modules/cmdrunner/widget.go index ddcfd36d..6e8ffecb 100644 --- a/modules/cmdrunner/widget.go +++ b/modules/cmdrunner/widget.go @@ -3,6 +3,7 @@ package cmdrunner import ( "bytes" "fmt" + "os" "os/exec" "strings" "sync" @@ -108,6 +109,7 @@ func (widget *Widget) execute() { // Setup the command to run cmd := exec.Command(widget.settings.cmd, widget.settings.args...) cmd.Stdout = widget + cmd.Env = widget.environment() // Run the command and wait for it to exit in another Go-routine go func() { @@ -134,3 +136,13 @@ func (widget *Widget) drainLines(n int) { 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 +} From fc95a6c1a002b6e852e9b769b89a644576fad23b Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Wed, 9 Oct 2019 18:20:26 -0700 Subject: [PATCH 4/7] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cd6fa01..ad2a4a30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,7 @@ * GitHub PR icons render properly without phantom characters, by [@Midnight-Conqueror](https://github.com/Midnight-Conqueror) * GitLab configuration now takes a list of project paths, [#566](https://github.com/wtfutil/wtf/issues/566) by [@senorprogrammer](https://github.com/senorprogrammer) * Kubernetes configuration segfault fixed, [#549](https://github.com/wtfutil/wtf/issues/549) by [@ibaum](https://github.com/ibaum) +* [Todoist](https://wtfutil.com/modules/todoist/) module now properly handles todo items with due date and times, [#645](https://github.com/wtfutil/wtf/issues/645) by [@massa1240](https://github.com/massa1240) ## v0.21.0 From 1fa73fc3ba623e60b527d0db08e272d06d3bee49 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Wed, 9 Oct 2019 18:20:48 -0700 Subject: [PATCH 5/7] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad2a4a30..e4f7aea3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ * [Transmission](https://wtfutil.com/modules/transmission/) module no longer blocks rendering when a Transmission daemon cannot be found, [#661](https://github.com/wtfutil/wtf/issues/661) by [@senorprogrammer](https://github.com/senorprogrammer) * [Trello](https://wtfutil.com/modules/trello/) module now respects project list order, [#664](https://github.com/wtfutil/wtf/issues/664) by [@Seanstoppable](https://github.com/Seanstoppable) * [Todo](https://wtfutil.com/modules/todo/) module now respects checkbox settings, [#616](https://github.com/wtfutil/wtf/issues/616) by [@Seanstoppable](https://github.com/Seanstoppable) +* [Todoist](https://wtfutil.com/modules/todoist/) module now properly handles todo items with due date and times, [#645](https://github.com/wtfutil/wtf/issues/645) by [@massa1240](https://github.com/massa1240) ### 👍 Updated @@ -62,7 +63,6 @@ * GitHub PR icons render properly without phantom characters, by [@Midnight-Conqueror](https://github.com/Midnight-Conqueror) * GitLab configuration now takes a list of project paths, [#566](https://github.com/wtfutil/wtf/issues/566) by [@senorprogrammer](https://github.com/senorprogrammer) * Kubernetes configuration segfault fixed, [#549](https://github.com/wtfutil/wtf/issues/549) by [@ibaum](https://github.com/ibaum) -* [Todoist](https://wtfutil.com/modules/todoist/) module now properly handles todo items with due date and times, [#645](https://github.com/wtfutil/wtf/issues/645) by [@massa1240](https://github.com/massa1240) ## v0.21.0 From cd893736eea52f3f405be6d2126fbf59847f0f72 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Wed, 9 Oct 2019 18:21:22 -0700 Subject: [PATCH 6/7] Update todoist dependency Signed-off-by: Chris Cummer --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 7942aba1..23f6f608 100644 --- a/go.mod +++ b/go.mod @@ -50,7 +50,7 @@ require ( github.com/shirou/gopsutil v2.19.9+incompatible github.com/sticreations/spotigopher v0.0.0-20181009182052-98632f6f94b0 github.com/stretchr/testify v1.4.0 - github.com/wtfutil/todoist v0.0.0-20180625015933-97395e581a76 + github.com/wtfutil/todoist v0.0.0-20190913231042-97395e581a76 github.com/xanzy/go-gitlab v0.20.1 github.com/yfronto/newrelic v0.0.0-20180622232530-7c9c2852e8f9 github.com/zmb3/spotify v0.0.0-20190520155326-158b1863f5b5 diff --git a/go.sum b/go.sum index bd71b491..c72289ee 100644 --- a/go.sum +++ b/go.sum @@ -263,6 +263,8 @@ github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyC github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= github.com/wtfutil/todoist v0.0.0-20180625015933-97395e581a76 h1:8pVwscQmyw1Dcca9R8QuHvLFTHr4h6MDlgbLM1A+WLA= github.com/wtfutil/todoist v0.0.0-20180625015933-97395e581a76/go.mod h1:YuuGLJSsTK6DGBD5Zaf3J8LSMfpEC2WtzYPey3XVOdI= +github.com/wtfutil/todoist v0.0.0-20190913231042-97395e581a76 h1:xYi42YVngKInpr8/IAuO5dUzaw8PrVPdyHCCqDoM3Ks= +github.com/wtfutil/todoist v0.0.0-20190913231042-97395e581a76/go.mod h1:YuuGLJSsTK6DGBD5Zaf3J8LSMfpEC2WtzYPey3XVOdI= github.com/xanzy/go-gitlab v0.20.1 h1:+1BWDry84G5PzsnzG9DI4YjPbHeWKyouM0q0gfDPKgY= github.com/xanzy/go-gitlab v0.20.1/go.mod h1:LSfUQ9OPDnwRqulJk2HcWaAiFfCzaknyeGvjQI67MbE= github.com/zmb3/spotify v0.0.0-20190520155326-158b1863f5b5 h1:UagwVflTu8e//SSwujymFEz0G9MUP5/fJJLCzdQy3as= From 02a39915dd0f82a848243be865a39c971ed574ab Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Wed, 9 Oct 2019 18:21:35 -0700 Subject: [PATCH 7/7] Add @massa1240 as a contributor --- .all-contributorsrc | 7 +++++++ README.md | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 3ce727e9..a51d415c 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -714,6 +714,13 @@ "name": "Jason Schweier", "avatar_url": "https://avatars1.githubusercontent.com/u/4923990?v=4", "profile": "http://jmks.ca", + "contributions": [] + }, + { + "login": "massa1240", + "name": "Massa", + "avatar_url": "https://avatars2.githubusercontent.com/u/8268483?v=4", + "profile": "https://github.com/massa1240", "contributions": [ ] } diff --git a/README.md b/README.md index 524738d7..f1da567f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-101-orange.svg?style=flat-square)](#contributors) +[![All Contributors](https://img.shields.io/badge/all_contributors-102-orange.svg?style=flat-square)](#contributors) [![Build Status](https://travis-ci.com/wtfutil/wtf.svg?branch=master)](https://travis-ci.com/wtfutil/wtf) [![Twitter](https://img.shields.io/badge/follow-on%20twitter-blue.svg)](https://twitter.com/wtfutil) [![Go Report Card](https://goreportcard.com/badge/github.com/wtfutil/wtf)](https://goreportcard.com/report/github.com/wtfutil/wtf) @@ -211,7 +211,7 @@ Dependency management in WTF is handled by [Go modules](https://github.com/golan | [Bob 'Wombat' Hogg
Bob 'Wombat' Hogg](https://github.com/rwhogg)
| [Christopher Hall
Christopher Hall](https://github.com/hxw)
| [Heitor Neiva
Heitor Neiva](https://github.com/hneiva)
| [Herby Gillot
Herby Gillot](https://github.com/herbygillot)
| [James Canning
James Canning](http://brudil.com)
| [jeffz
jeffz](https://twitter.com/jeffz4000)
| [Mikkel Jeppesen Juhl
Mikkel Jeppesen Juhl](https://mikkeljuhl.com)
| | [Erik
Erik](https://github.com/lesteenman)
| [Nate Yourchuck
Nate Yourchuck](https://github.com/nyourchuck)
| [Casey Primozic
Casey Primozic](https://cprimozic.net/)
| [Alvaro [Andor]
Alvaro [Andor]](http://pierdelacabeza.com/maruja)
| [Joel Valentine
Joel Valentine](https://github.com/Midnight-Conqueror)
| [Viktor Braun
Viktor Braun](https://www.viktor-braun.de)
| [ChrisDBrown
ChrisDBrown](https://www.chrisdbrown.co.uk/)
| | [Narendra L
Narendra L](https://narengowda.github.io/)
| [ibaum
ibaum](https://github.com/ibaum)
| [Tim Scheuermann
Tim Scheuermann](https://github.com/noxer)
| [Indradhanush Gupta
Indradhanush Gupta](https://indradhanush.github.io/)
| [Victor Hugo Avelar Ossorio
Victor Hugo Avelar Ossorio](https://victoravelar.com)
| [Steven Whitehead
Steven Whitehead](https://github.com/scw007)
| [Lawrence Craft
Lawrence Craft](https://github.com/lawrencecraft)
| -| [Avi Press
Avi Press](http://avi.press)
| [Sarah Kraßnigg
Sarah Kraßnigg](https://github.com/Tardog)
| [Jason Schweier
Jason Schweier](http://jmks.ca)
| +| [Avi Press
Avi Press](http://avi.press)
| [Sarah Kraßnigg
Sarah Kraßnigg](https://github.com/Tardog)
| [Jason Schweier
Jason Schweier](http://jmks.ca)
| [Massa
Massa](https://github.com/massa1240)
| ## Acknowledgments