about summary refs log blame commit diff stats
path: root/aerc.go
blob: a018f9e9bc0b90ca4566edba7b78e8e5aeafed64 (plain) (tree)
661e3ec ^

pre { line-height: 125%; } td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; } span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; } td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
c{0: 0 (((1 string-address)) <- ((new)) hello, _!) -- nil
c{0: 1 (((2 string-address)) <- ((new)) abc) -- nil
c{0: 2 (((3 string-address)) <- ((interpolate)) ((1 string-address)) ((2 string-address))) -- nil
c{1: 0 ✓ (((1 string-address)) <- ((new)) hello, _!)
c{1: 1 ✓ (((2 string-address)) <- ((new)) abc)
c{1: 2 ✓ (((3 string-address)) <- ((interpolate)) ((1 string-address)) ((2 string-address)))
cn0: convert-names in main
cn0: (((1 string-address)) <- ((new)) hello, _!) nil nil
cn0: checking arg hello, _!
cn0: checking oarg ((1 string-address))
maybe-add: ((1 string-address))
cn0: (((2 string-address)) <- ((new)) abc) nil nil
cn0: checking arg abc
cn0: checking oarg ((2 string-address))
maybe-add: ((2 string-address))
cn0: (((3 string-address)) <- ((interpolate)) ((1 string-address)) ((2 string-address))) nil nil
cn0: checking arg ((1 string-address))
maybe-add: ((1 string-address))
cn0: checking arg ((2 string-address))
maybe-add: ((2 string-address))
cn0: checking oarg ((3 string-address))
maybe-add: ((3 string-address))
cn1: (((1 string-address)) <- ((new)) hello, _!)
cn1: (((2 string-address)) <- ((new)) abc)
cn1: (((3 string-address)) <- ((interpolate)) ((1 string-address)) ((2 string-address)))
schedule: main
run: main 0: (((1 string-address)) <- ((new)) hello, _!)
run: main 0: 1000 => ((1 string-address))
mem: ((1 string-address)): 1 <= 1000
run: main 1: (((2 string-address)) <- ((new)) abc)
run: main 1: 1010 => ((2 string-address))
mem: ((2 string-address)): 2 <= 1010
run: main 2: (((3 string-address)) <- ((interpolate)) ((1 string-address)) ((2 string-address)))
mem: ((1 string-address)) => 1000
mem: ((2 string-address)) => 1010
run: interpolate/main 0: (((default-space space-address)) <- ((new)) ((space literal)) ((60 literal)))
run: interpolate/main 0: 1014 => ((default-space space-address))
run: interpolate/main 1: (((1 string-address)) <- ((next-input)))
arg: nil 0 (1000 1010)
run: interpolate/main 1: 1000 => ((1 string-address))
mem: ((1 string-address)): 1016 <= 1000
run: interpolate/main 2: (((2 integer)) <- ((length)) ((1 string-address) (deref)))
array-len: ((1 string-address) (deref))
mem: ((1000 integer) (raw)) => 9
run: interpolate/main 2: 9 => ((2 integer))
mem: ((2 integer)): 1017 <= 9
run: interpolate/main 3: (((3 integer)) <- ((copy)) ((2 integer)))
mem: ((2 integer)) => 9
run: interpolate/main 3: 9 => ((3 integer))
mem: ((3 integer)): 1018 <= 9
run: interpolate/main 4: (((4 string-address)) ((5 boolean)) <- ((next-input)))
arg: nil 1 (1000 1010)
run: interpolate/main 4: 1010 => ((4 string-address))
mem: ((4 string-address)): 1019 <= 1010
run: interpolate/main 4: t => ((5 boolean))
mem: ((5 boolean)): 1020 <= t
run: interpolate/main 5: (((jump-unless)) ((5 boolean)) ((4 offset)))
mem: ((5 boolean)) => t
run: interpolate/main 6: (((6 integer)) <- ((length)) ((4 string-address) (deref)))
array-len: ((4 string-address) (deref))
mem: ((1010 integer) (raw)) => 3
run: interpolate/main 6: 3 => ((6 integer))
mem: ((6 integer)): 1021 <= 3
run: interpolate/main 7: (((3 integer)) <- ((add)) ((3 integer)) ((6 integer)))
mem: ((3 integer)) => 9
mem: ((6 integer)) => 3
run: interpolate/main 7: 12 => ((3 integer))
mem: ((3 integer)): 1018 <= 12
run: interpolate/main 8: (((3 integer)) <- ((subtract)) ((3 integer)) ((1 literal)))
mem: ((3 integer)) => 12
run: interpolate/main 8: 11 => ((3 integer))
mem: ((3 integer)): 1018 <= 11
run: interpolate/main 9: (((jump)) ((-6 offset)))
run: interpolate/main 4: (((4 string-address)) ((5 boolean)) <- ((next-input)))
arg: nil 2 (1000 1010)
run: interpolate/main 4: nil => ((4 string-address))
mem: ((4 string-address)): 1019 <= nil
run: interpolate/main 4: nil => ((5 boolean))
mem: ((5 boolean)): 1020 <= nil
run: interpolate/main 5: (((jump-unless)) ((5 boolean)) ((4 offset)))
mem: ((5 boolean)) => nil
run: interpolate/main 10: (_ <- ((input)) ((0 literal)))
arg: (((0 literal))) 0 (1000 1010)
run: interpolate/main 11: (((7 string-address)) <- ((new)) ((string literal)) ((3 integer)))
mem: ((3 integer)) => 11
run: interpolate/main 11: 1075 => ((7 string-address))
mem: ((7 string-address)): 1022 <= 1075
run: int
package main

import (
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"os"
	"time"

	"github.com/mattn/go-isatty"

	"git.sr.ht/~sircmpwn/aerc/commands"
	"git.sr.ht/~sircmpwn/aerc/commands/account"
	"git.sr.ht/~sircmpwn/aerc/commands/compose"
	"git.sr.ht/~sircmpwn/aerc/commands/msgview"
	"git.sr.ht/~sircmpwn/aerc/commands/terminal"
	"git.sr.ht/~sircmpwn/aerc/config"
	libui "git.sr.ht/~sircmpwn/aerc/lib/ui"
	"git.sr.ht/~sircmpwn/aerc/widgets"
)

func getCommands(selected libui.Drawable) []*commands.Commands {
	switch selected.(type) {
	case *widgets.AccountView:
		return []*commands.Commands{
			account.AccountCommands,
			commands.GlobalCommands,
		}
	case *widgets.Composer:
		return []*commands.Commands{
			compose.ComposeCommands,
			commands.GlobalCommands,
		}
	case *widgets.MessageViewer:
		return []*commands.Commands{
			msgview.MessageViewCommands,
			commands.GlobalCommands,
		}
	case *widgets.Terminal:
		return []*commands.Commands{
			terminal.TerminalCommands,
			commands.GlobalCommands,
		}
	default:
		return []*commands.Commands{commands.GlobalCommands}
	}
}

func main() {
	var (
		logOut io.Writer
		logger *log.Logger
	)
	if !isatty.IsTerminal(os.Stdout.Fd()) {
		logOut = os.Stdout
	} else {
		logOut = ioutil.Discard
	}
	logger = log.New(logOut, "", log.LstdFlags)
	logger.Println("Starting up aerc")

	conf, err := config.LoadConfig(nil)
	if err != nil {
		fmt.Printf("Failed to load config: %v\n", err)
		os.Exit(1)
	}

	var (
		aerc *widgets.Aerc
		ui   *libui.UI
	)
	aerc = widgets.NewAerc(conf, logger, func(cmd string) error {
		cmds := getCommands(aerc.SelectedTab())
		for i, set := range cmds {
			err := set.ExecuteCommand(aerc, cmd)
			if _, ok := err.(commands.NoSuchCommand); ok {
				if i == len(cmds)-1 {
					return err
				} else {
					continue
				}
			} else if _, ok := err.(commands.ErrorExit); ok {
				ui.Exit()
				return nil
			} else if err != nil {
				return err
			} else {
				break
			}
		}
		return nil
	})

	ui, err = libui.Initialize(conf, aerc)
	if err != nil {
		panic(err)
	}
	defer ui.Close()

	for !ui.ShouldExit() {
		if !ui.Tick() {
			// ~60 FPS
			time.Sleep(16 * time.Millisecond)
		}
	}
}
) ((1 literal))) mem: ((8 integer)) => 10 run: interpolate/main 43: 11 => ((8 integer)) mem: ((8 integer)): 1023 <= 11 run: interpolate/main 44: (((jump)) ((-8 offset))) run: interpolate/main 37: (((10 boolean)) <- ((greater-or-equal)) ((9 integer)) ((2 integer))) mem: ((9 integer)) => 9 mem: ((2 integer)) => 9 run: interpolate/main 37: t => ((10 boolean)) mem: ((10 boolean)): 1025 <= t run: interpolate/main 38: (((jump-if)) ((10 boolean)) ((6 offset))) mem: ((10 boolean)) => t run: interpolate/main 45: (((reply)) ((7 string-address))) mem: ((7 string-address)) => 1075 run: main 2: 1075 => ((3 string-address)) mem: ((3 string-address)): 3 <= 1075 schedule: done with routine nil