Skip to content

Commit

Permalink
change: debug output
Browse files Browse the repository at this point in the history
  • Loading branch information
ShuheiKubota committed Nov 4, 2023
1 parent 4cec396 commit 6c522e8
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '1.21'
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
Expand Down
14 changes: 7 additions & 7 deletions cmd_alpha.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"errors"
"os"

"github.com/shu-go/nmfmt"
)
Expand All @@ -15,13 +16,12 @@ func (c alphaCmd) Run(args []string, g globalCmd) error {
}

opacity := toInt(args[0], 255)
if g.Debug {
nmfmt.Printf("opacity = $arg -> $opacity/255",
nmfmt.M{
"arg": args[0],
"opacity": opacity,
})
}

g.debug(os.Stderr, "opacity $=arg:q -> $opacity/255\n",
nmfmt.M{
"arg": args[0],
"opacity": opacity,
})

style, _, _ := getWindowLong.Call(uintptr(g.targetHandle), gwlEXStyle)
setWindowLong.Call(uintptr(g.targetHandle), gwlEXStyle, style|wsEXLayered)
Expand Down
22 changes: 12 additions & 10 deletions cmd_resize.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package main

import (
"errors"
"os"
"unsafe"

"github.com/shu-go/rog"
"github.com/shu-go/nmfmt"
)

type resizeCmd struct {
Expand All @@ -29,9 +30,11 @@ func (c *resizeCmd) Before(g globalCmd) error {

oldrect := c.rect

if g.Debug {
rog.Print(oldrect)
}
g.debug(os.Stderr, "$=original\n",
nmfmt.M{
"original": oldrect,
})

if c.Left != "" {
c.rect.Left = toInt(c.Left, g.scrWidth)
}
Expand All @@ -48,12 +51,11 @@ func (c *resizeCmd) Before(g globalCmd) error {
} else {
c.rect.Bottom = c.rect.Top + (oldrect.Bottom - oldrect.Top)
}
if g.Debug {
if c.Restore {
rog.Print("restore")
} else {
rog.Print(c.rect)
}

if c.Restore {
g.debug(os.Stderr, "restore\n")
} else {
g.debug(os.Stderr, "resized $rect\n", nmfmt.M{"rect": c.rect})
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd_wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ waitLoop:
fmt.Fprintln(os.Stderr, "cancelled")
break waitLoop
case <-ctx.Done():
fmt.Fprintln(os.Stderr, "cancelled")
fmt.Fprintln(os.Stderr, "cancelled (timeout)")
break waitLoop
default:
//nop
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.21
require (
github.com/mitchellh/go-ps v1.0.0
github.com/shu-go/gli/v2 v2.0.1
github.com/shu-go/rog v0.1.0
github.com/shu-go/nmfmt v0.1.0
)

Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,5 @@ github.com/shu-go/gli/v2 v2.0.1 h1:XA1QSfUdpWW1FIqLjuXo+Gs/IjEy+uviuxKQ45IRYC8=
github.com/shu-go/gli/v2 v2.0.1/go.mod h1:pSC0XKb69hEarQpiQU74CNiKpcS7a90iJAMUGL3SinQ=
github.com/shu-go/gotwant v0.0.0-20190920074605-b4f19c0bac91 h1:nwDc3kHbf9scf1UZIWiWw5tZF3Z4yOJAMjNN+kYXJwE=
github.com/shu-go/gotwant v0.0.0-20190920074605-b4f19c0bac91/go.mod h1:FZepfqvib0mXjHiaQPTv0RUD5QMpMA/FHLfBQjZRRQg=
github.com/shu-go/rog v0.1.0 h1:mplglNOiUN1ujq0UTkosB5NL/GQhFX2gRYcen7aEhTY=
github.com/shu-go/rog v0.1.0/go.mod h1:gO+FpqgnHoxbF6FPJN6PaAEl6hcZRLNL+nQZgbbElzo=
github.com/shu-go/nmfmt v0.1.0 h1:gL5u0yiIsegh2gofeNUpAJPWCNgOF+qIivBc9qO/KoE=
github.com/shu-go/nmfmt v0.1.0/go.mod h1:ulgNf0sfuQEEdX2cM71sGviSEKDf9DUXlm5WtFn0PJY=
18 changes: 18 additions & 0 deletions vvin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"errors"
"fmt"
"io"
"math"
"os"
"strconv"
Expand All @@ -12,6 +13,7 @@ import (

"github.com/mitchellh/go-ps"
"github.com/shu-go/gli/v2"
"github.com/shu-go/nmfmt"
)

// Version is app version
Expand All @@ -21,6 +23,8 @@ type globalCmd struct {
Target string `cli:"target,t=WINDOW_TITLE" help:"default to current window"`
Debug bool `help:"output debug info"`

debug func(io.Writer, string, ...any) (int, error) // nmfmt

Minimize minCmd `cli:"minimize,min" help:"minimize/restore"`
Maximize maxCmd `cli:"maximize,max" help:"maximize/restore"`
Resize resizeCmd `cli:"resize,move,mv" help:"resize/move"`
Expand All @@ -34,6 +38,14 @@ type globalCmd struct {
}

func (c *globalCmd) Before() error {
c.debug = func(io.Writer, string, ...any) (int, error) {
return 0, nil
}
if c.Debug {
c.debug = nmfmt.Fprintf
}
c.debug(os.Stderr, "Debug enabled.\n")

wins, err := listAllWindows()
if err != nil {
return err
Expand All @@ -45,6 +57,12 @@ func (c *globalCmd) Before() error {
}
c.targetHandle = win.Handle

c.debug(os.Stderr, "$=target:q -> $=handle:x\n",
nmfmt.M{
"target": c.Target,
"handle": c.targetHandle,
})

w, _, _ := getSystemMetrics.Call(smCXVirtualScreen)
h, _, _ := getSystemMetrics.Call(smCYVirtualScreen)
c.scrWidth = int(w)
Expand Down

0 comments on commit 6c522e8

Please sign in to comment.