diff --git a/cmd/cmd.go b/cmd/cmd.go index 34e33fc..bb75291 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -57,7 +57,7 @@ func run(cmd *cobra.Command, _ []string) error { g := game.New( game.WithPattern(pat), - game.WithDimensions(400, 400), + game.WithDimensions(conf.Width, conf.Height), game.WithPlay(conf.Play), ) diff --git a/docs/cli-of-life.md b/docs/cli-of-life.md index acf2f51..0af357f 100644 --- a/docs/cli-of-life.md +++ b/docs/cli-of-life.md @@ -12,8 +12,10 @@ cli-of-life [flags] --completion string Output command-line completion code for the specified shell (one of: bash, zsh, fish, powershell) -f, --file string Loads a pattern file on startup --file-format string File format (one of: auto, rle, plaintext) (default "auto") + --height uint Board height. Will be ignored if a larger pattern is loaded. (default 400) -h, --help help for cli-of-life --play Play on startup --rule-string string Rule string to use. This will be ignored if a pattern file is loaded. (default "B3/S23") + --width uint Board width. Will be ignored if a larger pattern is loaded. (default 400) ``` diff --git a/internal/config/config.go b/internal/config/config.go index e301edf..95f14a1 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -7,6 +7,8 @@ type Config struct { FileFormat string RuleString string Play bool + Width uint + Height uint Completion string } @@ -15,5 +17,7 @@ func New() *Config { return &Config{ FileFormat: "auto", RuleString: pattern.GameOfLife().String(), + Width: 400, + Height: 400, } } diff --git a/internal/config/flags.go b/internal/config/flags.go index 23990da..7bcc47c 100644 --- a/internal/config/flags.go +++ b/internal/config/flags.go @@ -12,6 +12,8 @@ const ( FileFormatFlag = "file-format" RuleStringFlag = "rule-string" PlayFlag = "play" + WidthFlag = "width" + HeightFlag = "height" CompletionFlag = "completion" ) @@ -20,5 +22,7 @@ func (c *Config) RegisterFlags(fs *pflag.FlagSet) { fs.StringVar(&c.FileFormat, FileFormatFlag, c.FileFormat, "File format (one of: "+strings.Join(pattern.FormatStrings(), ", ")+")") fs.StringVar(&c.RuleString, RuleStringFlag, c.RuleString, "Rule string to use. This will be ignored if a pattern file is loaded.") fs.BoolVar(&c.Play, PlayFlag, c.Play, "Play on startup") + fs.UintVar(&c.Width, WidthFlag, c.Width, "Board width. Will be ignored if a larger pattern is loaded.") + fs.UintVar(&c.Height, HeightFlag, c.Height, "Board height. Will be ignored if a larger pattern is loaded.") fs.StringVar(&c.Completion, CompletionFlag, c.Completion, "Output command-line completion code for the specified shell (one of: "+strings.Join(shells(), ", ")+")") } diff --git a/internal/game/opts.go b/internal/game/opts.go index 08fbf8d..f5f3700 100644 --- a/internal/game/opts.go +++ b/internal/game/opts.go @@ -15,10 +15,10 @@ func WithPattern(pat pattern.Pattern) Option { } } -func WithDimensions(width, height int) Option { +func WithDimensions(width, height uint) Option { return func(game *Game) { - newW := max(width, game.BoardW()+100) - newH := max(height, game.BoardH()+100) + newW := max(int(width), game.BoardW()+100) + newH := max(int(height), game.BoardH()+100) game.Resize(newW, newH, image.Pt(0, 0)) } }