-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from gdanko/use-config-file
Use config file
- Loading branch information
Showing
19 changed files
with
257 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
# Valid colors | ||
# black-bold | ||
# black | ||
# blue-bold | ||
# blue | ||
# cyan-bold | ||
# cyan | ||
# green-bold | ||
# green | ||
# magenta-bold | ||
# magenta | ||
# red-bold | ||
# red | ||
# white-bold | ||
# white | ||
# yellow-bold | ||
# yellow | ||
colors: | ||
alias_color: yellow-bold | ||
anchor_color: yellow-bold | ||
bool_color: yellow-bold | ||
key_color: cyan-bold | ||
null_color: black-bold | ||
number_color: magenta-bold | ||
string_color: green-bold | ||
vault_path: ~/Documents/Enpass/Vaults/primary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,73 @@ | ||
package globals | ||
|
||
import ( | ||
"fmt" | ||
"os/user" | ||
"sync" | ||
|
||
"github.com/fatih/color" | ||
) | ||
|
||
type Colors struct { | ||
AliasColor string `yaml:"alias_color"` | ||
AnchorColor string `yaml:"anchor_color"` | ||
BoolColor string `yaml:"bool_color"` | ||
KeyColor string `yaml:"key_color"` | ||
NullColor string `yaml:"null_color"` | ||
NumberColor string `yaml:"number_color"` | ||
StringColor string `yaml:"string_color"` | ||
} | ||
|
||
type EnpassConfig struct { | ||
VaultPath string `yaml:"vault_path"` | ||
VaultPassword string `yaml:"vault_password"` | ||
Colors Colors `yaml:"colors"` | ||
} | ||
|
||
var ( | ||
colorMap = map[string]color.Attribute{ | ||
"AliasColor": color.FgHiYellow, | ||
"AnchorColor": color.FgHiYellow, | ||
"BoolColor": color.FgHiYellow, | ||
"KeyColor": color.FgHiCyan, | ||
"NullColor": color.FgHiBlack, | ||
"NumberColor": color.FgHiMagenta, | ||
"StringColor": color.FgHiGreen, | ||
enpassConfig = EnpassConfig{ | ||
VaultPath: "~/Documents/Enpass/Vaults/primary", | ||
Colors: Colors{ | ||
AliasColor: "yellow-bold", | ||
AnchorColor: "yellow-bold", | ||
BoolColor: "yellow-bold", | ||
KeyColor: "cyan-bold", | ||
NullColor: "black-bold", | ||
NumberColor: "magenta-bold", | ||
StringColor: "green-bold", | ||
}, | ||
} | ||
mu sync.RWMutex | ||
homeDir string | ||
mu sync.RWMutex | ||
) | ||
|
||
func GetColorMap() (x map[string]color.Attribute) { | ||
// Set and get pairs | ||
func SetConfig(x EnpassConfig) { | ||
mu.Lock() | ||
enpassConfig = x | ||
mu.Unlock() | ||
} | ||
|
||
func GetConfig() (x EnpassConfig) { | ||
mu.Lock() | ||
x = enpassConfig | ||
mu.Unlock() | ||
return x | ||
} | ||
|
||
func SetHomeDirectory() (err error) { | ||
mu.Lock() | ||
userObj, err := user.Current() | ||
if err != nil { | ||
mu.Unlock() | ||
return fmt.Errorf("failed to determine the path of your home directory: %s", err) | ||
} | ||
homeDir = userObj.HomeDir | ||
mu.Unlock() | ||
return nil | ||
} | ||
|
||
func GetHomeDirectory() (x string) { | ||
mu.Lock() | ||
x = colorMap | ||
x = homeDir | ||
mu.Unlock() | ||
return x | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.