2019-03-13 04:14:30 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
type args struct {
|
|
|
|
ErrorCode *int
|
|
|
|
PrintConfig *bool
|
|
|
|
Config *string
|
2020-09-26 04:41:28 -07:00
|
|
|
Shell *string
|
2020-10-08 10:23:20 -07:00
|
|
|
PWD *string
|
2019-03-13 04:14:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
args := &args{
|
|
|
|
ErrorCode: flag.Int(
|
|
|
|
"error",
|
|
|
|
0,
|
|
|
|
"Error code of previously executed command"),
|
|
|
|
PrintConfig: flag.Bool(
|
|
|
|
"print-config",
|
|
|
|
false,
|
|
|
|
"Config prints the current settings in json format"),
|
|
|
|
Config: flag.String(
|
|
|
|
"config",
|
|
|
|
"",
|
|
|
|
"Add the path to a configuration you wish to load"),
|
2020-09-26 04:41:28 -07:00
|
|
|
Shell: flag.String(
|
|
|
|
"shell",
|
|
|
|
"",
|
|
|
|
"Override the shell you are working in"),
|
2020-10-08 10:23:20 -07:00
|
|
|
PWD: flag.String(
|
|
|
|
"pwd",
|
|
|
|
"",
|
|
|
|
"the path you are working in"),
|
2019-03-13 04:14:30 -07:00
|
|
|
}
|
|
|
|
flag.Parse()
|
|
|
|
env := &environment{
|
|
|
|
args: args,
|
|
|
|
}
|
|
|
|
settings := GetSettings(env)
|
|
|
|
if *args.PrintConfig {
|
|
|
|
theme, _ := json.MarshalIndent(settings, "", " ")
|
|
|
|
fmt.Println(string(theme))
|
|
|
|
return
|
|
|
|
}
|
2020-09-23 00:33:54 -07:00
|
|
|
colorWriter := &Renderer{
|
|
|
|
Buffer: new(bytes.Buffer),
|
|
|
|
}
|
2020-09-26 04:41:28 -07:00
|
|
|
shell := env.getShellName()
|
|
|
|
if *args.Shell != "" {
|
|
|
|
shell = *args.Shell
|
|
|
|
}
|
|
|
|
colorWriter.init(shell)
|
2019-03-13 04:14:30 -07:00
|
|
|
engine := &engine{
|
|
|
|
settings: settings,
|
|
|
|
env: env,
|
2020-09-23 00:33:54 -07:00
|
|
|
renderer: colorWriter,
|
2019-03-13 04:14:30 -07:00
|
|
|
}
|
2020-09-16 04:08:28 -07:00
|
|
|
engine.render()
|
2019-03-13 04:14:30 -07:00
|
|
|
}
|