aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-01-09 19:18:19 -0500
committerDrew DeVault <sir@cmpwn.com>2018-01-09 19:28:43 -0500
commit39c93d2897af5bb0c145ef4f99f542bf42babdab (patch)
tree4a3d3ac3553b2d2f31960a7af35ea286b62597d7
parentaeb700577b5b2955c75093129e01de49b92f124f (diff)
Load UI configuration
-rw-r--r--Makefile2
-rw-r--r--cmd/aerc/main.go11
-rw-r--r--config/accounts.conf17
-rw-r--r--config/aerc.conf179
-rw-r--r--config/config.go85
5 files changed, 292 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 064c86b..fed3d69 100644
--- a/Makefile
+++ b/Makefile
@@ -21,4 +21,4 @@ aerc: .go
clean:
rm -rf .go aerc
-.PHONY: get test clean
+.PHONY: aerc get test clean
diff --git a/cmd/aerc/main.go b/cmd/aerc/main.go
index 24dcac8..96a8e0c 100644
--- a/cmd/aerc/main.go
+++ b/cmd/aerc/main.go
@@ -2,8 +2,17 @@ package main
import (
"fmt"
+
+ "git.sr.ht/~sircmpwn/aerc2/config"
)
func main() {
- fmt.Println("Hello world")
+ var (
+ c *config.AercConfig
+ err error
+ )
+ if c, err = config.LoadConfig(nil); err != nil {
+ panic(err)
+ }
+ fmt.Printf("%+v\n", *c)
}
diff --git a/config/accounts.conf b/config/accounts.conf
new file mode 100644
index 0000000..a25c64e
--- /dev/null
+++ b/config/accounts.conf
@@ -0,0 +1,17 @@
+#
+# aerc accounts configuration
+#
+# This file configures each of the available mail accounts.
+
+# You may add an arbitrary number of sections like so:
+#
+# [Personal]
+# source=imaps://username[:password]@hostname[:port]
+#
+# [Work]
+# source=imaps://username[:password]@hostname[:port]
+# folders=INBOX,Sent,Archives
+# default=Archives
+#
+# Each supported protocol may have some arbitrary number of extra configuration
+# options. See aerc-[protocol](5) for details (i.e. aerc-imap).
diff --git a/config/aerc.conf b/config/aerc.conf
new file mode 100644
index 0000000..76b0310
--- /dev/null
+++ b/config/aerc.conf
@@ -0,0 +1,179 @@
+#
+# aerc main configuration
+
+[ui]
+#
+# Describes the format for each row in a mailbox view. This field is compatible
+# with mutt's printf-like syntax. TODO: document properly
+#
+# Default:
+index-format=%4C %Z %D %-17.17n %s
+
+#
+# See strftime(3)
+#
+# Default: %F %l:%M %p (ISO 8501 + 12 hour time)
+timestamp-format=%F %l:%M %p
+
+#
+# Which headers to show when viewing an email.
+#
+# Default: From,To,Cc,Bcc,Subject,Date
+show-headers=From,To,Cc,Bcc,Subject,Date
+
+#
+# The frames of animation to use in the UI for things that are still loading.
+# Seperate each frame with a comma.
+#
+# Default: "[..] , [..] , [..], [..] " (note extra spaces)
+loading-frames=[..] , [..] , [..], [..]
+
+#
+# One of "on", "off", or "auto".
+#
+# Default: auto
+render-account-tabs=auto
+
+#
+# Width of the sidebar, including the border.
+#
+# Default: 20
+sidebar-width=20
+
+#
+# Height of the message preview, including the border.
+#
+# Default: 12
+preview-height=12
+
+#
+# Message to display when viewing an empty folder.
+#
+# Default: (no messages)
+empty-message=(no messages)
+
+[viewer]
+#
+# We can use different programs to display various kinds of email attachments.
+# These programs will have the mail piped into them and are expected to output
+# it ready to display on a terminal (you can include terminal control
+# characters if you like, for colors and such). Emails will be stripped of
+# non-printable characters before being piped into these commands, and will be
+# encoded with UTF-8. These commands are invoked with sh and run
+# non-interactively, and their output is piped into your pager command
+# (interactively). The following environment variables will be set:
+#
+# $WIDTH: the width of the terminal window
+# $HEIGHT: the height of the terminal window
+# $MIMETYPE: the email's mimetype
+#
+# You can use * as a wildcard for any subtype of a given mimetype. When
+# displaying a text/* message and no command matches, the message will just be
+# piped directly into your pager (after being stripped of non-printable
+# characters).
+
+# Examples:
+#
+#text/html=w3m -T text/html -cols $WIDTH -dump -o display_image=false -o display_link_number=true
+text/*=fold -sw $WIDTH
+
+#
+# Default: less -r
+pager=less -r
+
+#
+# If an email offers several versions (multipart), you can configure which
+# mimetype to prefer. For example, this can be used to prefer plaintext over
+# html emails.
+#
+# Default: text/plain,text/html
+alternatives=text/plain,text/html
+
+[lbinds]
+#
+# Binds are of the form <key sequence> = <command to run>
+# To use '=' in a key sequence, substitute it with "Eq": "<Ctrl+Eq>"
+# If you wish to bind #, you can wrap the key sequence in quotes: "#" = quit
+#
+# lbinds are bindings that take effect in the list view
+# mbinds are bindings that take effect in the message view
+q=:quit<Enter>
+<Ctrl+c>=:quit<Enter>
+
+j=:next-message<Enter>
+<Down>=:next-message<Enter>
+<Ctrl+d>=:next-message --scroll 50%<Enter>
+<Ctrl+f>=:next-message --scroll 100%<Enter>
+<PageDown>=:next-message --scroll 100%<Enter>
+<WheelDown>=:next-message --scroll 1<Enter>
+
+k=:previous-message<Enter>
+<Up>=:previous-message<Enter>
+<Ctrl+u>=:previous-message --scroll 50%<Enter>
+<Ctrl+b>=:previous-message --scroll 100%<Enter>
+<PageUp>=:previous-message --scroll 100%<Enter>
+<WheelUp>=:previous-message --scroll 1<Enter>
+g=:select-message 0<Enter>
+G=:select-message -1<Enter>
+
+J=:next-folder<Enter>
+K=:previous-folder<Enter>
+l = :next-account<Enter>
+<Right> = :next-account<Enter>
+h = :previous-account<Enter>
+<Left> = :previous-account<Enter>
+
+<Enter>=:view-message<Enter>
+d=:confirm 'Really delete this message?' ':delete-message<Enter>'<Enter>
+
+c=:cd
+$=:term-exec
+
+[mbinds]
+#
+# Any key not bound is passed through to the sub-terminal.
+
+<Ctrl+h> = :previous-account<Enter>
+<Ctrl+l> = :next-account<Enter>
+
+[colors]
+#
+# Colors are configured in one of two ways:
+#
+# "foreground" or "background:foreground"
+#
+# You can specify colors according to the base 8 names:
+# default, black, red, green, yellow, blue, magenta, cyan, white
+#
+# or you can use numbers for the 256 color palette,
+# e.g. "127:118" (a particularly ugly combination FYI)
+#
+# Add one or more of the following characters to the beginning
+# of the foreground color to add modifiers:
+#
+# * bold
+# _ underline
+# ^ reverse
+#
+# e.g. "default:_*^default" would reverse the default colors and
+# with bold and underlined modifiers
+borders=default:^default
+loading-indicator=default:default
+
+account-unselected=white:black
+account-selected=default:default
+account-error=red:black
+
+folder-unselected=default:default
+folder-selected=white:black
+
+status-line=white:black
+status-line-error=red:black
+
+ex-line=default:default
+
+message-list-selected=white:black
+message-list-selected-unread=white:_black
+message-list-unselected=default:default
+message-list-unselected-unread=default:*default
+message-list-empty=default:default
diff --git a/config/config.go b/config/config.go
new file mode 100644
index 0000000..b620258
--- /dev/null
+++ b/config/config.go
@@ -0,0 +1,85 @@
+package config
+
+import (
+ "github.com/go-ini/ini"
+ "github.com/kyoh86/xdg"
+
+ "path"
+ "unicode"
+)
+
+type UIConfig struct {
+ IndexFormat string
+ TimestampFormat string
+ ShowHeaders []string `delim:","`
+ LoadingFrames []string `delim:","`
+ RenderAccountTabs string
+ SidebarWidth int
+ PreviewHeight int
+ EmptyMessage string
+}
+
+type AccountConfig struct {
+ ConfigPath string
+ Name string
+ Source string
+ Folders []string
+ Params map[string]string
+}
+
+type AercConfig struct {
+ Ini *ini.File `ini:"-"`
+ Accounts []AccountConfig `ini:"-"`
+ Ui UIConfig
+}
+
+// Input: TimestampFormat
+// Output: timestamp-format
+func mapName(raw string) string {
+ newstr := make([]rune, 0, len(raw))
+ for i, chr := range raw {
+ if isUpper := 'A' <= chr && chr <= 'Z'; isUpper {
+ if i > 0 {
+ newstr = append(newstr, '-')
+ }
+ }
+ newstr = append(newstr, unicode.ToLower(chr))
+ }
+ return string(newstr)
+}
+
+func LoadConfig(root *string) (*AercConfig, error) {
+ var (
+ err error
+ file *ini.File
+ )
+ if root == nil {
+ _root := path.Join(xdg.ConfigHome(), "aerc")
+ root = &_root
+ }
+ if file, err = ini.Load(path.Join(*root, "aerc.conf")); err != nil {
+ return nil, err
+ }
+ file.NameMapper = mapName
+ config := &AercConfig{
+ Ini: file,
+ Ui: UIConfig{
+ IndexFormat: "%4C %Z %D %-17.17n %s",
+ TimestampFormat: "%F %l:%M %p",
+ ShowHeaders: []string{
+ "From", "To", "Cc", "Bcc", "Subject", "Date",
+ },
+ LoadingFrames: []string{
+ "[..] ", " [..] ", " [..]", " [..] ",
+ },
+ RenderAccountTabs: "auto",
+ SidebarWidth: 20,
+ PreviewHeight: 12,
+ EmptyMessage: "(no messages)",
+ },
+ }
+ if ui, err := file.GetSection("ui"); err != nil {
+ ui.MapTo(config.Ui)
+ }
+ return config, nil
+}