Return terminal to normal when config file can't be found

Fixes #55
This commit is contained in:
erroneousboat 2017-08-04 10:22:42 +02:00
parent 732e292e44
commit 843f61d7aa
2 changed files with 11 additions and 6 deletions

View File

@ -1,8 +1,6 @@
package context
import (
"log"
"github.com/gizak/termui"
termbox "github.com/nsf/termbox-go"
@ -28,11 +26,11 @@ type AppContext struct {
// CreateAppContext creates an application context which can be passed
// and referenced througout the application
func CreateAppContext(flgConfig string) *AppContext {
func CreateAppContext(flgConfig string) (*AppContext, error) {
// Load config
config, err := config.NewConfig(flgConfig)
if err != nil {
log.Fatalf("ERROR: not able to load config file (%s): %s", flgConfig, err)
return nil, err
}
// Create Service
@ -47,5 +45,5 @@ func CreateAppContext(flgConfig string) *AppContext {
View: view,
Config: config,
Mode: CommandMode,
}
}, nil
}

View File

@ -4,11 +4,13 @@ import (
"flag"
"fmt"
"log"
"os"
"os/user"
"path"
"github.com/erroneousboat/slack-term/context"
"github.com/erroneousboat/slack-term/handlers"
termbox "github.com/nsf/termbox-go"
"github.com/gizak/termui"
)
@ -74,7 +76,12 @@ func main() {
termui.DefaultEvtStream = customEvtStream
// Create context
ctx := context.CreateAppContext(flgConfig)
ctx, err := context.CreateAppContext(flgConfig)
if err != nil {
termbox.Close()
log.Println(err)
os.Exit(0)
}
// Setup body
termui.Body.AddRows(