summary refs log tree commit diff stats
path: root/README
Commit message (Expand)AuthorAgeFilesLines
* new version: 1.3.1, merge with cp+preview branchhut2010-10-121-1/+1
* Incremented version number to 1.3 (testing)hut2010-09-131-1/+1
* Beware of low-flying butterflies v1.2.0hut2010-09-131-1/+1
* README: Usage Tips sectionhut2010-09-131-0/+6
* README: added ranger starting function examplehut2010-09-111-0/+14
* Tuned versioning scheme to be more intuitive, back to 1.1.2hut2010-08-281-2/+2
* Changed version number to 1.2 (testing) to adhere with versioning schemehut2010-08-281-2/+2
* Changed default config dir to $XDG_CONFIG_HOME/rangerhut2010-08-281-1/+1
* Why did the astrophysicist order three hamburgers? v1.1.2hut2010-07-121-1/+1
* README: added design goals sectionhut2010-06-241-0/+9
* README: formatting, cleanuphut2010-06-241-4/+4
* version = version + 1 v1.1.1hut2010-06-181-2/+2
* new stable version v1.1.0hut2010-06-091-2/+2
* README: updatedhut2010-05-241-6/+18
* README: minor changehut2010-05-151-2/+2
* README: rewritehut2010-05-151-115/+47
* Fixed bug #65 by adding flag "--fail-if-run"hut2010-04-261-1/+1
* README: Removed finished parts of roadmaphut2010-04-191-2/+0
* README: slightly improved Roadmaphut2010-04-131-1/+2
* README: added Roadmaphut2010-04-131-0/+18
* Fixed suggested cd-after-exit-script for zshhut2010-04-131-1/+1
* README: updatedhut2010-03-291-1/+1
* removed the cd-after-exit hackhut2010-03-291-0/+13
* README: Removed the reference to code/keys.rb >_<hut2010-03-291-2/+2
* incremented verison number v1.0.4hut2010-03-121-2/+2
* README: typohut2010-03-121-2/+2
* more documentationhut2010-03-121-3/+10
* README: slightly changed introductionhut2010-03-121-3/+3
* README: changed introductionhut2010-03-121-8/+10
* README: updatedhut2010-03-121-16/+19
* incremented version number and updated pydoc html files v1.0.3hut2010-02-161-2/+2
* readme: normalized letter casing in headingshut2010-02-151-2/+2
* updated READMEhut2010-02-151-29/+40
* made configuration more simplehut2010-01-251-6/+2
* README: corrected bad instructionshut2010-01-241-2/+2
* readme: improvedhut2010-01-201-6/+13
* 1.0.2! v1.0.2hut2010-01-141-2/+2
* readme: added part "customizing ranger"hut2010-01-141-0/+16
* readme: removed ugly sentencehut2010-01-141-3/+1
* new minor version v1.0.1hut2010-01-021-2/+2
* readme: updatedhut2010-01-011-4/+77
* decided to use python from now onhut2009-11-221-1/+1
* Initial commithut2009-11-161-0/+11
fa4eb170b3527cd20814eed'>f42724c ^
a0be5e8 ^
b275a39 ^

39c93d2 ^
60b351b ^
f406bf5 ^



b60999c ^
8126d82 ^



b275a39 ^
8126d82 ^




de122b1 ^
8126d82 ^





f406bf5 ^
8126d82 ^
b60999c ^

f406bf5 ^
77a0f68 ^


1418e1b ^
60b351b ^
de122b1 ^
a15ea01 ^


1418e1b ^
661e3ec ^

305446a ^
6394e38 ^
aeb7005
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136


            
             



                   
              
 
                                    

                                    


                                                   
                                               




                                                    

 



                                                                
                                                
                                            

                                                

                                            
                                                

                                                


                                                    
                                            

                                                
                               


                                                  





                                                                    


                       
                       

 
             















                                                                         



                                  




                                               
                                                   

                                          
                                                     
                       

                                                              
         
 



                                  
                                                                     



                                                                      
                                                     




                                                                         
                                         





                                              
                 
                          

          
                                              


                          
                        
 
                              


                                                               
                               

                                                         
                 
         
 
package main

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

	"git.sr.ht/~sircmpwn/getopt"
	"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/msg"
	"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,
			msg.MessageCommands,
			commands.GlobalCommands,
		}
	case *widgets.Composer:
		return []*commands.Commands{
			compose.ComposeCommands,
			commands.GlobalCommands,
		}
	case *widgets.MessageViewer:
		return []*commands.Commands{
			msgview.MessageViewCommands,
			msg.MessageCommands,
			commands.GlobalCommands,
		}
	case *widgets.Terminal:
		return []*commands.Commands{
			terminal.TerminalCommands,
			commands.GlobalCommands,
		}
	default:
		return []*commands.Commands{commands.GlobalCommands}
	}
}

var (
	Prefix   string
	ShareDir string
	Version  string
)

func main() {
	// TODO: Support starting with mailto links, ad-hoc accounts, etc
	opts, optind, err := getopt.Getopts(os.Args, "v")
	if err != nil {
		panic(err)
	}
	for _, opt := range opts {
		switch opt.Option {
		case 'v':
			fmt.Println("aerc " + Version)
			return
		}
	}
	if optind != len(os.Args) {
		log.Fatal("Usage: aerc [-v]")
	}

	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, ShareDir)
	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() {
		for aerc.Tick() {
			// Continue updating our internal state
		}
		if !ui.Tick() {
			// ~60 FPS
			time.Sleep(16 * time.Millisecond)
		}
	}
}