-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
And refactor `UseConfigEnv()` method
- Loading branch information
Showing
6 changed files
with
109 additions
and
172 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package config | ||
|
||
import ( | ||
envUtil "koi/util/env" | ||
"strings" | ||
) | ||
|
||
func UseConfigEnv(env *[]string) { | ||
if Config.Env == nil { | ||
return | ||
} | ||
|
||
for _, e := range Config.Env { | ||
if len(e) == 0 { | ||
continue | ||
} | ||
|
||
i := strings.Index(e, "=") | ||
var k, v string | ||
if i >= 0 { | ||
k = e[:i] | ||
v = e[i+1:] | ||
} else { | ||
k = e | ||
v = "" | ||
} | ||
|
||
envUtil.UseEnv(env, k, v) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,34 @@ | ||
package env | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
func UseEnv(env *[]string, key string, value string) { | ||
RemoveEnv(env, key) | ||
*env = append(*env, fmt.Sprintf("%s=%s", key, value)) | ||
} | ||
|
||
func RemoveEnv(env *[]string, key string) { | ||
removeEnvIntl(env, key) | ||
removeEnvIntl(env, strings.ToUpper(key)) | ||
removeEnvIntl(env, strings.ToLower(key)) | ||
} | ||
|
||
func removeEnvIntl(env *[]string, key string) { | ||
for { | ||
notFound := true | ||
for i, e := range *env { | ||
if strings.HasPrefix(e, key+"=") { | ||
*env = append((*env)[:i], (*env)[i+1:]...) | ||
notFound = false | ||
break | ||
} | ||
} | ||
|
||
if notFound { | ||
break | ||
} | ||
} | ||
} |
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,36 @@ | ||
// Package supcolor determine whether the io supports color. | ||
package supcolor | ||
|
||
import ( | ||
envUtil "koi/util/env" | ||
"strconv" | ||
) | ||
|
||
func UseColorEnv(env *[]string, mode int8) { | ||
// FORCE_COLOR | ||
envUtil.UseEnv(env, "FORCE_COLOR", strconv.Itoa(int(mode))) | ||
|
||
// COLORTERM | ||
if mode >= 3 { | ||
envUtil.UseEnv(env, "COLORTERM", "truecolor") | ||
} | ||
|
||
// TERM | ||
if mode >= 3 { | ||
envUtil.UseEnv(env, "TERM", "xterm-truecolor") | ||
} else if mode == 2 { | ||
envUtil.UseEnv(env, "TERM", "xterm-256color") | ||
} else if mode == 1 { | ||
envUtil.UseEnv(env, "TERM", "xterm-color") | ||
} else { | ||
envUtil.UseEnv(env, "TERM", "dumb") | ||
} | ||
|
||
// CLICOLOR | ||
if mode >= 1 { | ||
envUtil.UseEnv(env, "CLICOLOR", "1") | ||
} | ||
|
||
// TERM_PROGRAM | ||
envUtil.UseEnv(env, "TERM_PROGRAM", "Koi") | ||
} |
This file was deleted.
Oops, something went wrong.