Pass style argument to the Boba program

This commit is contained in:
Christian Rocha 2020-05-15 13:09:46 -04:00 committed by Christian Muehlhaeuser
parent 8bb2812a6b
commit 5d2ca090ac
2 changed files with 41 additions and 33 deletions

34
main.go
View file

@ -151,21 +151,7 @@ func execute(cmd *cobra.Command, args []string) error {
validateOptions(cmd)
if len(args) == 0 {
//return executeArg(cmd, "", os.Stdout)
debug := os.Getenv("GLOW_DEBUG")
if debug != "" {
boba.UseSysLog("glow")
}
boba.AltScreen()
if err := ui.NewProgram().Start(); err != nil {
return err
}
boba.ExitAltScreen()
fmt.Printf("\n Thanks for using Glow!\n\n")
return nil
return executeArg(cmd, "", os.Stdout)
}
for _, arg := range args {
@ -177,6 +163,24 @@ func execute(cmd *cobra.Command, args []string) error {
}
func executeArg(cmd *cobra.Command, arg string, w io.Writer) error {
// TODO: Put this somewhere where it makes more sense
if arg == "" {
debug := os.Getenv("GLOW_DEBUG")
if debug != "" {
boba.UseSysLog("glow")
}
boba.AltScreen()
if err := ui.NewProgram(style).Start(); err != nil {
return err
}
boba.ExitAltScreen()
fmt.Printf("\n Thanks for using Glow!\n\n")
return nil
}
// create an io.Reader from the markdown source in cli-args
src, err := sourceFromArg(arg)
if err != nil {

View file

@ -28,8 +28,8 @@ var (
)
// NewProgram returns a new Boba program
func NewProgram() *boba.Program {
return boba.NewProgram(initialize, update, view)
func NewProgram(style string) *boba.Program {
return boba.NewProgram(initialize(style), update, view)
}
// MESSAGES
@ -61,6 +61,7 @@ const (
)
type model struct {
style string // style to use
cc *charm.Client
user *charm.User
spinner spinner.Model
@ -82,24 +83,27 @@ func (m *model) unloadDocument() {
// INIT
func initialize() (boba.Model, boba.Cmd) {
s := spinner.NewModel()
s.Type = spinner.Dot
s.ForegroundColor = common.SpinnerColor
func initialize(style string) func() (boba.Model, boba.Cmd) {
return func() (boba.Model, boba.Cmd) {
s := spinner.NewModel()
s.Type = spinner.Dot
s.ForegroundColor = common.SpinnerColor
w, h, err := terminal.GetSize(int(os.Stdout.Fd()))
w, h, err := terminal.GetSize(int(os.Stdout.Fd()))
return model{
spinner: s,
state: stateInitCharmClient,
err: err,
terminalWidth: w,
terminalHeight: h,
}, boba.Batch(
newCharmClient,
spinner.Tick(s),
getTerminalSize(),
)
return model{
style: style,
spinner: s,
state: stateInitCharmClient,
err: err,
terminalWidth: w,
terminalHeight: h,
}, boba.Batch(
newCharmClient,
spinner.Tick(s),
getTerminalSize(),
)
}
}
// UPDATE