Skip to content

Commit

Permalink
Merge pull request #6 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 0.0.4
  • Loading branch information
andyone authored Jul 7, 2021
2 parents d3e8268 + e47bd56 commit 1ee1621
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 4 deletions.
1 change: 1 addition & 0 deletions .codebeatignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
templates/**
35 changes: 33 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"pkg.re/essentialkaos/ek.v12/fmtc"
"pkg.re/essentialkaos/ek.v12/fmtutil"
Expand All @@ -30,7 +31,7 @@ import (

const (
APP = "scratch"
VER = "0.0.3"
VER = "0.0.4"
DESC = "Utility for generating blank files for apps and services"
)

Expand All @@ -56,6 +57,9 @@ var optMap = options.Map{
OPT_GENERATE_MAN: {Type: options.BOOL},
}

// useRawOutput is raw output flag (for cli command)
var useRawOutput = false

// ////////////////////////////////////////////////////////////////////////////////// //

// Init is main app func
Expand All @@ -70,7 +74,7 @@ func Init() {
os.Exit(1)
}

configureUI()
preConfigureUI()

if options.Has(OPT_COMPLETION) {
os.Exit(genCompletion())
Expand All @@ -80,6 +84,8 @@ func Init() {
os.Exit(genMan())
}

configureUI()

if options.GetB(OPT_VER) {
os.Exit(showAbout())
}
Expand All @@ -95,6 +101,31 @@ func Init() {
}
}

// preConfigureUI preconfigures UI based on information about user terminal
func preConfigureUI() {
term := os.Getenv("TERM")

fmtc.DisableColors = true

if term != "" {
switch {
case strings.Contains(term, "xterm"),
strings.Contains(term, "color"),
term == "screen":
fmtc.DisableColors = false
}
}

if !fsutil.IsCharacterDevice("/dev/stdout") && os.Getenv("FAKETTY") == "" {
fmtc.DisableColors = true
useRawOutput = true
}

if os.Getenv("NO_COLOR") != "" {
fmtc.DisableColors = true
}
}

// configureUI configures UI
func configureUI() {
if options.GetB(OPT_NO_COLOR) {
Expand Down
33 changes: 32 additions & 1 deletion templates/simple-utility/_name_.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package main
import (
"fmt"
"os"
"strings"

"pkg.re/essentialkaos/ek.v12/fmtc"
"pkg.re/essentialkaos/ek.v12/options"
Expand Down Expand Up @@ -51,6 +52,9 @@ var optMap = options.Map{
OPT_GENERATE_MAN: {Type: options.BOOL},
}

// useRawOutput is raw output flag (for cli command)
var useRawOutput = false

// ////////////////////////////////////////////////////////////////////////////////// //

// main is main function
Expand All @@ -65,7 +69,7 @@ func main() {
os.Exit(1)
}

configureUI()
preConfigureUI()

if options.Has(OPT_COMPLETION) {
os.Exit(genCompletion())
Expand All @@ -75,6 +79,8 @@ func main() {
os.Exit(genMan())
}

configureUI()

if options.GetB(OPT_VER) {
os.Exit(showAbout())
}
Expand All @@ -86,6 +92,31 @@ func main() {
process(args)
}

// preConfigureUI preconfigures UI based on information about user terminal
func preConfigureUI() {
term := os.Getenv("TERM")

fmtc.DisableColors = true

if term != "" {
switch {
case strings.Contains(term, "xterm"),
strings.Contains(term, "color"),
term == "screen":
fmtc.DisableColors = false
}
}

if !fsutil.IsCharacterDevice("/dev/stdout") && os.Getenv("FAKETTY") == "" {
fmtc.DisableColors = true
useRawOutput = true
}

if os.Getenv("NO_COLOR") != "" {
fmtc.DisableColors = true
}
}

// configureUI configures user interface
func configureUI() {
if options.GetB(OPT_NO_COLOR) {
Expand Down
33 changes: 32 additions & 1 deletion templates/utility/app/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package app
import (
"fmt"
"os"
"strings"

"pkg.re/essentialkaos/ek.v12/fmtc"
"pkg.re/essentialkaos/ek.v12/options"
Expand Down Expand Up @@ -51,6 +52,9 @@ var optMap = options.Map{
OPT_GENERATE_MAN: {Type: options.BOOL},
}

// useRawOutput is raw output flag (for cli command)
var useRawOutput = false

// ////////////////////////////////////////////////////////////////////////////////// //

// Init is main function
Expand All @@ -65,7 +69,7 @@ func Init() {
os.Exit(1)
}

configureUI()
preConfigureUI()

if options.Has(OPT_COMPLETION) {
os.Exit(genCompletion())
Expand All @@ -75,6 +79,8 @@ func Init() {
os.Exit(genMan())
}

configureUI()

if options.GetB(OPT_VER) {
os.Exit(showAbout())
}
Expand All @@ -86,6 +92,31 @@ func Init() {
process(args)
}

// preConfigureUI preconfigures UI based on information about user terminal
func preConfigureUI() {
term := os.Getenv("TERM")

fmtc.DisableColors = true

if term != "" {
switch {
case strings.Contains(term, "xterm"),
strings.Contains(term, "color"),
term == "screen":
fmtc.DisableColors = false
}
}

if !fsutil.IsCharacterDevice("/dev/stdout") && os.Getenv("FAKETTY") == "" {
fmtc.DisableColors = true
useRawOutput = true
}

if os.Getenv("NO_COLOR") != "" {
fmtc.DisableColors = true
}
}

// configureUI configures user interface
func configureUI() {
if options.GetB(OPT_NO_COLOR) {
Expand Down

0 comments on commit 1ee1621

Please sign in to comment.