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

View File

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