Skip to content

Commit

Permalink
"github.com/e-gun/policeresponses"
Browse files Browse the repository at this point in the history
  • Loading branch information
e-gun committed Aug 6, 2024
1 parent 0ea3831 commit 1edb317
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 267 deletions.
19 changes: 9 additions & 10 deletions INSTRUCTIONS/fyi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,28 +173,27 @@ self-test with vectors can be deceptive because `-wc` flag will not override con

```
e-gun/HipparchiaGoServer/ % cloc --exclude-dir=z --not-match-f="^jq*" .
168 text files.
150 unique files.
172 text files.
154 unique files.
191 files ignored.
github.com/AlDanial/cloc v 2.00 T=0.14 s (1067.1 files/s, 214952.6 lines/s)
github.com/AlDanial/cloc v 2.00 T=0.12 s (1277.3 files/s, 254441.3 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
Go 97 3139 3540 14364
Go 98 3182 3580 14646
JavaScript 8 310 193 1595
CSS 1 349 89 1567
HTML 12 160 18 1532
Markdown 11 457 0 1206
HTML 12 160 17 1532
Markdown 11 458 0 1206
JSON 9 0 0 414
Text 5 90 0 412
SVG 1 1 1 392
JSON 9 0 0 386
XML 4 0 0 313
XML 7 0 0 382
Bourne Shell 1 13 7 63
Python 1 5 6 7
-------------------------------------------------------------------------------
SUM: 150 4524 3854 21837
SUM: 154 4568 3893 22216
-------------------------------------------------------------------------------
```
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## HipparchiaGoServer v1.3.5
## HipparchiaGoServer v1.3.6

### FEATURES

Expand Down
22 changes: 10 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ module github.com/e-gun/HipparchiaGoServer
go 1.22

require (
github.com/e-gun/lastnlines v0.1.0
github.com/e-gun/nlp v0.0.2
github.com/e-gun/tsnemp v0.1.7
github.com/e-gun/wego v0.1.0
github.com/go-echarts/go-echarts/v2 v2.4.0 // v2.4 breaks the api
github.com/go-echarts/go-echarts/v2 v2.4.1 // v2.4 breaks the api
github.com/google/uuid v1.6.0
github.com/gorilla/websocket v1.5.3
github.com/jackc/pgx/v5 v5.6.0
Expand All @@ -17,27 +18,24 @@ require (
gonum.org/v1/gonum v0.15.0
)

require (
github.com/e-gun/mutexstack v0.0.1
github.com/nxadm/tail v1.4.11
)

require (
github.com/armon/go-radix v1.0.0 // indirect
github.com/e-gun/lastnlines v0.0.1 // indirect
github.com/e-gun/policeresponses v0.0.1 // indirect
github.com/e-gun/safestack v0.1.1 // indirect
github.com/e-gun/sparse v0.0.0-20230418220937-07063da15582 // indirect
github.com/felixge/fgprof v0.9.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/google/pprof v0.0.0-20240721033354-7089f98c1d14 // indirect
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/nxadm/tail v1.4.11 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
Expand All @@ -48,8 +46,8 @@ require (
github.com/valyala/fasttemplate v1.2.2 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/time v0.6.0 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
)
27 changes: 18 additions & 9 deletions internal/base/mm/messaging.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,13 @@ func (m *MessageMaker) Emit(message string, threshold int) {
return
}

if m.ToFile {
m.EmitToFile(message, threshold)
if m.ToFile && !m.BW {
msg := m.ColorMessage(message, threshold)
m.EmitToFile(msg)
return
} else if m.ToFile {
msg := m.BWMessage(message, threshold)
m.EmitToFile(msg)
}

if !m.Win && !m.BW {
Expand All @@ -146,6 +150,10 @@ func (m *MessageMaker) EmitBW(message string, threshold int) {

// EmitColor - send a color message to the console
func (m *MessageMaker) EmitColor(message string, threshold int) {
fmt.Printf(m.ColorMessage(message, threshold))
}

func (m *MessageMaker) ColorMessage(message string, threshold int) string {
var color string

switch threshold {
Expand All @@ -166,22 +174,23 @@ func (m *MessageMaker) EmitColor(message string, threshold int) {
default:
color = WHITE
}
fmt.Printf("[%s%s%s] %s%s%s\n", YELLOW1, m.SNm, RESET, color, message, RESET)
return fmt.Sprintf("[%s%s%s] %s%s%s\n", YELLOW1, m.SNm, RESET, color, message, RESET)
}

// EmitToFile - send the message to a file
func (m *MessageMaker) EmitToFile(message string, threshold int) {
func (m *MessageMaker) BWMessage(message string, threshold int) string {
tn := time.Now().Format(time.RFC3339)
ms := fmt.Sprintf("[%s] [%s] [%d] %s\n", tn, m.SNm, threshold, message)
// circular import if vv.LOGFILEML
// f, err := os.OpenFile(vv.LOGFILEML, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
return fmt.Sprintf("[%s] [%s] [%d] %s\n", tn, m.SNm, threshold, message)
}

// EmitToFile - send the message to a file
func (m *MessageMaker) EmitToFile(message string) {
uh, _ := os.UserHomeDir()
f, err := os.OpenFile(uh+"/"+LOGFILE, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
if err != nil {
panic(err)
}
defer f.Close()
if _, err = f.WriteString(ms); err != nil {
if _, err = f.WriteString(message); err != nil {
panic(err)
}
return
Expand Down
3 changes: 2 additions & 1 deletion internal/lnch/configatlaunch.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ func ConfigAtLaunch() {
"vmodel": Config.VectorModel,
"workers": Config.WorkerCount,
"knownfnts": strings.Join(kff, "C0, C3"),
"tlines": Config.TickerLines,
"deffnt": Config.Font}

t := template.Must(template.New("").Parse(vv.HELPTEXTTEMPLATE))
Expand Down Expand Up @@ -255,7 +256,7 @@ func ConfigAtLaunch() {
case "-tl":
ll, err := strconv.Atoi(args[i+1])
if err != nil {
fmt.Println("Invalid port number")
fmt.Println("number not found after '-tl'")
os.Exit(1)
}
Config.TickerLines = ll
Expand Down
4 changes: 2 additions & 2 deletions internal/lnch/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func PrintVersion(cc str.CurrentConfiguration) {
if !Config.LogToFile {
fmt.Println(versioninfo)
} else {
Msg.EmitToFile(versioninfo, 0)
Msg.EmitToFile(versioninfo)
}
}

Expand All @@ -80,7 +80,7 @@ func PrintBuildInfo(cc str.CurrentConfiguration) {
if !Config.LogToFile {
fmt.Println(bi)
} else {
Msg.EmitToFile(bi, 0)
Msg.EmitToFile(bi)
}

}
38 changes: 20 additions & 18 deletions internal/vlt/pathinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,21 @@ func TerminalTicker(wait time.Duration) {
//BrowseLine: 51 * LexFindByForm: 48 * LexLookup: 6 * LexReverse: 6 * NeighborsSearch: 1 * Search: 7

const (
CLEAR = "\033[2K"
CLEARLN = "\033[2K"
CLEARRT = "\033[0K"
CLEARSCR = "\033[2J"
HEAD = "\r"
CURSHOME = "\033[1;1H"
FIRSTLINE = "\033[2;1H"
FOURTHLINE = "\033[4;1H"
CURSSAVE = "\033[s"
CURSREST = "\033[u"
PADDING = " ----------------- "
STATTMPL = "%s: C2%dC0"
UPTIME = "[S1C6%vC0] C5S1%s uptime: C1%vC0 [S1C6%sC0]"
TIMESTR = "%02dd %02dh %02dm %02ds"
CLEAR = "\033[2K"
CLEARLN = "\033[2K"
CLEARRT = "\033[0K"
CLEARSCR = "\033[2J"
HEAD = "\r"
CURSHOME = "\033[1;1H"
FIRSTLINE = "\033[2;1H"
FROMTOP = 4
NLINE = "\033[%d;1H"
CURSSAVE = "\033[s"
CURSREST = "\033[u"
PADDING = " ----------------- "
STATTMPL = "%s: C2%dC0"
UPTIME = "[S1C6%vC0] C5S1%s uptime: C1%vC0 [S1C6%sC0]"
TIMESTR = "%02dd %02dh %02dm %02ds"
)

// ANSI escape codes do not work in windows
Expand Down Expand Up @@ -102,12 +103,12 @@ func TerminalTicker(wait time.Duration) {
// start collecting tails of the two logfiles
uh, _ := os.UserHomeDir()

lnl1 := lastnlines.NewMutexLNL(uh + "/" + vv.LOGFILEEL)
lnl1 := lastnlines.NewLNL(uh + "/" + vv.LOGFILEEL)
lnl1.SetDepth(lnch.Config.TickerLines)
lnl1.Start()
defer lnl1.Stop()

lnl2 := lastnlines.NewMutexLNL(uh + "/" + vv.LOGFILEML)
lnl2 := lastnlines.NewLNL(uh + "/" + vv.LOGFILEML)
lnl2.SetDepth(lnch.Config.TickerLines)
lnl2.Start()
defer lnl2.Stop()
Expand All @@ -131,10 +132,11 @@ func TerminalTicker(wait time.Duration) {
up := time.Since(Msg.Lnc)
uptimer(up)
srchinfo()
fmt.Printf(CURSSAVE + FOURTHLINE)
fmt.Printf(CURSSAVE + fmt.Sprintf(NLINE, FROMTOP))
hdr(vv.LOGFILEEL)
tailinfo(lnl1.Get())
fmt.Printf(CLEARLN)
fmt.Printf(CURSSAVE + fmt.Sprintf(NLINE, FROMTOP+lnch.Config.TickerLines))
fmt.Println()
hdr(vv.LOGFILEML)
tailinfo(lnl2.Get())
time.Sleep(wait)
Expand Down
Loading

0 comments on commit 1edb317

Please sign in to comment.