diff options
| author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-10-05 16:47:32 +0200 | 
|---|---|---|
| committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-10-05 16:47:32 +0200 | 
| commit | ada6a68b4f25c912705542a6b03aae7ffffb5e99 (patch) | |
| tree | 63ffb7d4c2f6c8ce194f90f6b3568b9c08286bf9 /pkg/config/config.go | |
| parent | 78af329f2c7bc1739bcd36baf45ab95aaff43434 (diff) | |
| download | cerrado-ada6a68b4f25c912705542a6b03aae7ffffb5e99.tar.gz cerrado-ada6a68b4f25c912705542a6b03aae7ffffb5e99.tar.bz2 cerrado-ada6a68b4f25c912705542a6b03aae7ffffb5e99.zip  | |
feat: Make syntax highlight configurable
Now cerrado has configurable theme through "syntax-highlight".
Diffstat (limited to 'pkg/config/config.go')
| -rw-r--r-- | pkg/config/config.go | 50 | 
1 files changed, 33 insertions, 17 deletions
diff --git a/pkg/config/config.go b/pkg/config/config.go index 902ff0d..812a06e 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -30,12 +30,13 @@ type (  	// configuration represents file configuration.  	// fields needs to be exported to cmp to work  	configuration struct { -		Scan         *scan -		RootReadme   string -		ListenAddr   string -		Passphrase   string -		AESKey       string -		Repositories []*GitRepositoryConfiguration +		Scan            *scan +		RootReadme      string +		ListenAddr      string +		Passphrase      string +		SyntaxHighlight string +		AESKey          string +		Repositories    []*GitRepositoryConfiguration  	}  	// This is a per repository configuration. @@ -52,11 +53,12 @@ type (  	// This holds all the function necessary to ask for configuration  	// information.  	ConfigurationRepository struct { -		rootReadme   string -		listenAddr   string -		passphrase   string -		aesKey       string -		repositories []*GitRepositoryConfiguration +		rootReadme      string +		listenAddr      string +		passphrase      string +		aesKey          string +		syntaxHighlight string +		repositories    []*GitRepositoryConfiguration  	}  ) @@ -72,11 +74,12 @@ func LoadConfigurationRepository(configPath string) (*ConfigurationRepository, e  	}  	repo := &ConfigurationRepository{ -		rootReadme:   config.RootReadme, -		listenAddr:   config.ListenAddr, -		repositories: config.Repositories, -		passphrase:   config.Passphrase, -		aesKey:       config.AESKey, +		aesKey:          config.AESKey, +		listenAddr:      config.ListenAddr, +		passphrase:      config.Passphrase, +		repositories:    config.Repositories, +		rootReadme:      config.RootReadme, +		syntaxHighlight: config.SyntaxHighlight,  	}  	if config.Scan.Path != "" { @@ -87,7 +90,6 @@ func LoadConfigurationRepository(configPath string) (*ConfigurationRepository, e  	}  	return repo, nil -  }  // GetRootReadme returns root read path @@ -95,6 +97,10 @@ func (c *ConfigurationRepository) GetRootReadme() string {  	return c.rootReadme  } +func (c *ConfigurationRepository) GetSyntaxHighlight() string { +	return c.syntaxHighlight +} +  func (c *ConfigurationRepository) GetListenAddr() string {  	return c.listenAddr  } @@ -186,6 +192,11 @@ func parse(r io.Reader) (*configuration, error) {  		return nil, err  	} +	err = setSyntaxHighlight(block, &config.SyntaxHighlight) +	if err != nil { +		return nil, err +	} +  	err = setRepositories(block, &config.Repositories)  	if err != nil {  		return nil, err @@ -289,6 +300,11 @@ func setAESKey(block scfg.Block, listenAddr *string) error {  	return setString(scanDir, listenAddr)  } +func setSyntaxHighlight(block scfg.Block, listenAddr *string) error { +	scanDir := block.Get("syntax-highlight") +	return setString(scanDir, listenAddr) +} +  func setListenAddr(block scfg.Block, listenAddr *string) error {  	scanDir := block.Get("listen-addr")  	return setString(scanDir, listenAddr)  | 
