aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Thyssen Tishman <johannes@thyssentishman.com>2024-03-26 23:00:50 +0100
committerRobin Jarry <robin@jarry.cc>2024-04-02 22:22:33 +0200
commit3d529aa09330f383298a5735a18549b44bc3098f (patch)
treea075dbdde8c4ecbfda22dc92ce97949a8d6b69b2
parent1ce82f50d0981a9ee047e75d94c7ab496070bd4a (diff)
downloadaerc-3d529aa09330f383298a5735a18549b44bc3098f.tar.gz
aerc-3d529aa09330f383298a5735a18549b44bc3098f.zip
config: make popover dialogs configurable
Add the [ui].dialog-{position,width,height} options in aerc.conf to set the position, width and height of popover dialogs such as the one from :menu, :envelope or :attach -m relative to the main window. Changelog-added: Add `[ui].dialog-{position,width,height}` to set the position, width and height of popover dialogs. Signed-off-by: Johannes Thyssen Tishman <johannes@thyssentishman.com> Reviewed-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r--app/aerc.go7
-rw-r--r--app/dialog.go52
-rw-r--r--commands/compose/attach.go2
-rw-r--r--commands/msg/envelope.go17
-rw-r--r--commands/patch/list.go2
-rw-r--r--commands/patch/rebase.go2
-rw-r--r--config/ui.go24
-rw-r--r--doc/aerc-config.5.scd18
8 files changed, 85 insertions, 39 deletions
diff --git a/app/aerc.go b/app/aerc.go
index 97604b17..7418e979 100644
--- a/app/aerc.go
+++ b/app/aerc.go
@@ -188,10 +188,11 @@ func (aerc *Aerc) Draw(ctx *ui.Context) {
if aerc.dialog != nil {
if w, h := ctx.Width(), ctx.Height(); w > 8 && h > 4 {
if d, ok := aerc.dialog.(Dialog); ok {
- start, height := d.ContextHeight()
+ xstart, width := d.ContextWidth()
+ ystart, height := d.ContextHeight()
aerc.dialog.Draw(
- ctx.Subcontext(4, start(h),
- w-8, height(h)))
+ ctx.Subcontext(xstart(w), ystart(h),
+ width(w), height(h)))
} else {
aerc.dialog.Draw(ctx.Subcontext(4, h/2-2, w-8, 4))
}
diff --git a/app/dialog.go b/app/dialog.go
index 3ed8b469..fba0fd7b 100644
--- a/app/dialog.go
+++ b/app/dialog.go
@@ -6,47 +6,65 @@ import (
type Dialog interface {
ui.DrawableInteractive
+ ContextWidth() (func(int) int, func(int) int)
ContextHeight() (func(int) int, func(int) int)
}
type dialog struct {
ui.DrawableInteractive
+ x func(int) int
y func(int) int
+ w func(int) int
h func(int) int
}
+func (d *dialog) ContextWidth() (func(int) int, func(int) int) {
+ return d.x, d.w
+}
+
func (d *dialog) ContextHeight() (func(int) int, func(int) int) {
return d.y, d.h
}
-func NewDialog(d ui.DrawableInteractive, y func(int) int, h func(int) int) Dialog {
- return &dialog{DrawableInteractive: d, y: y, h: h}
+func NewDialog(
+ d ui.DrawableInteractive,
+ x func(int) int, y func(int) int,
+ w func(int) int, h func(int) int,
+) Dialog {
+ return &dialog{DrawableInteractive: d, x: x, y: y, w: w, h: h}
}
// DefaultDialog creates a dialog window spanning half of the screen
func DefaultDialog(d ui.DrawableInteractive) Dialog {
+ position := SelectedAccountUiConfig().DialogPosition
+ width := SelectedAccountUiConfig().DialogWidth
+ height := SelectedAccountUiConfig().DialogHeight
return NewDialog(d,
- // vertical starting position in lines from the top
- func(h int) int {
- return h / 4
- },
- // dialog height from the starting line
- func(h int) int {
- return h / 2
+ // horizontal starting position in columns from the left
+ func(w int) int {
+ return (w * (100 - width)) / 200
},
- )
-}
-
-// LargeDialog creates a dialog window spanning three quarter of the screen
-func LargeDialog(d ui.DrawableInteractive) Dialog {
- return NewDialog(d,
// vertical starting position in lines from the top
func(h int) int {
- return h / 8
+ switch position {
+ case "center":
+ return (h * (100 - height)) / 200
+ case "bottom":
+ return h - (h * height / 100)
+ default:
+ return 1
+ }
+ },
+ // dialog width from the starting column
+ func(w int) int {
+ return w * width / 100
},
// dialog height from the starting line
func(h int) int {
- return 3 * h / 4
+ if position == "bottom" {
+ return h*height/100 - 1
+ }
+ return h * height / 100
},
)
}
diff --git a/commands/compose/attach.go b/commands/compose/attach.go
index 2cf43e80..c86b0f4f 100644
--- a/commands/compose/attach.go
+++ b/commands/compose/attach.go
@@ -177,7 +177,7 @@ func (a Attach) openMenu() error {
}
}
- app.AddDialog(app.LargeDialog(
+ app.AddDialog(app.DefaultDialog(
ui.NewBox(t, "File Picker", "", app.SelectedAccountUiConfig()),
))
diff --git a/commands/msg/envelope.go b/commands/msg/envelope.go
index 9b168fae..35243509 100644
--- a/commands/msg/envelope.go
+++ b/commands/msg/envelope.go
@@ -57,8 +57,7 @@ func (e Envelope) Execute(args []string) error {
}
}
- n := len(list)
- app.AddDialog(app.NewDialog(
+ app.AddDialog(app.DefaultDialog(
app.NewListBox(
"Message Envelope. Press <Esc> or <Enter> to close. "+
"Start typing to filter.",
@@ -68,20 +67,6 @@ func (e Envelope) Execute(args []string) error {
app.CloseDialog()
},
),
- // start pos on screen
- func(h int) int {
- if n < h/8*6 {
- return h/2 - n/2 - 1
- }
- return h / 8
- },
- // dialog height
- func(h int) int {
- if n < h/8*6 {
- return n + 2
- }
- return h / 8 * 6
- },
))
return nil
diff --git a/commands/patch/list.go b/commands/patch/list.go
index e73cea3a..0451605b 100644
--- a/commands/patch/list.go
+++ b/commands/patch/list.go
@@ -88,7 +88,7 @@ func (l List) Execute(args []string) error {
)
}
- app.AddDialog(app.LargeDialog(
+ app.AddDialog(app.DefaultDialog(
ui.NewBox(viewer, "Patch Management", "",
app.SelectedAccountUiConfig(),
),
diff --git a/commands/patch/rebase.go b/commands/patch/rebase.go
index 45136935..e99cc275 100644
--- a/commands/patch/rebase.go
+++ b/commands/patch/rebase.go
@@ -117,7 +117,7 @@ func (r Rebase) Execute(args []string) error {
return err
}
- app.AddDialog(app.LargeDialog(
+ app.AddDialog(app.DefaultDialog(
ui.NewBox(viewer, fmt.Sprintf("Patch Rebase on %-6.6s", baseID), "",
app.SelectedAccountUiConfig(),
),
diff --git a/config/ui.go b/config/ui.go
index a6034d46..7b819192 100644
--- a/config/ui.go
+++ b/config/ui.go
@@ -70,6 +70,9 @@ type UIConfig struct {
CompletionMinChars int `ini:"completion-min-chars" default:"1" parse:"ParseCompletionMinChars"`
CompletionPopovers bool `ini:"completion-popovers" default:"true"`
MsglistScrollOffset int `ini:"msglist-scroll-offset" default:"0"`
+ DialogPosition string `ini:"dialog-position" default:"center" parse:"ParseDialogPosition"`
+ DialogWidth int `ini:"dialog-width" default:"50" parse:"ParseDialogDimensions"`
+ DialogHeight int `ini:"dialog-height" default:"50" parse:"ParseDialogDimensions"`
StyleSetDirs []string `ini:"stylesets-dirs" delim:":"`
StyleSetName string `ini:"styleset-name" default:"default"`
style StyleSet
@@ -271,6 +274,27 @@ func (*UIConfig) ParseSplit(section *ini.Section, key *ini.Key) (p SplitParams,
return
}
+func (*UIConfig) ParseDialogPosition(section *ini.Section, key *ini.Key) (string, error) {
+ match, _ := regexp.MatchString(`^\s*(top|center|bottom)\s*$`, key.String())
+ if !(match) {
+ return "", fmt.Errorf("bad option value")
+ }
+ return key.String(), nil
+}
+
+const (
+ DIALOG_MIN_PROPORTION = 10
+ DIALOG_MAX_PROPORTION = 100
+)
+
+func (*UIConfig) ParseDialogDimensions(section *ini.Section, key *ini.Key) (int, error) {
+ value, err := key.Int()
+ if value < DIALOG_MIN_PROPORTION || value > DIALOG_MAX_PROPORTION || err != nil {
+ return 0, fmt.Errorf("value out of range")
+ }
+ return value, nil
+}
+
const MANUAL_COMPLETE = math.MaxInt
func (*UIConfig) ParseCompletionMinChars(section *ini.Section, key *ini.Key) (int, error) {
diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd
index 60fc5b7f..e72f2c6a 100644
--- a/doc/aerc-config.5.scd
+++ b/doc/aerc-config.5.scd
@@ -494,6 +494,24 @@ These options are configured in the *[ui]* section of _aerc.conf_.
Default: _0_
+*dialog-position* = _top_|_center_|_bottom_
+ Set the position of popover dialogs such as the one from *:menu*,
+ *:envelope* or *:attach -m*.
+
+ Default: _center_
+
+*dialog-width* = _<width>_
+ Set the width of popover dialogs as a percentage of the total width of
+ the window. The specified value should be between _10%_ and _100%_.
+
+ Default: _50_
+
+*dialog-height* = _<height>_
+ Set the height of popover dialogs as a percentage of the total height of
+ the window. The specified value should be between _10%_ and _100%_.
+
+ Default: _50_
+
## THREAD PREFIX CUSTOMIZATION
You can fully customize the thread arrows appearance, which is defined by the