mirror of
https://github.com/fiatjaf/nak.git
synced 2025-12-09 09:08:50 +00:00
global bold/italic helpers.
This commit is contained in:
14
bunker.go
14
bunker.go
@@ -83,8 +83,6 @@ var bunker = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
npub, _ := nip19.EncodePublicKey(pubkey)
|
npub, _ := nip19.EncodePublicKey(pubkey)
|
||||||
bold := color.New(color.Bold).Sprint
|
|
||||||
italic := color.New(color.Italic).Sprint
|
|
||||||
|
|
||||||
// this function will be called every now and then
|
// this function will be called every now and then
|
||||||
printBunkerInfo := func() {
|
printBunkerInfo := func() {
|
||||||
@@ -93,12 +91,12 @@ var bunker = &cli.Command{
|
|||||||
|
|
||||||
authorizedKeysStr := ""
|
authorizedKeysStr := ""
|
||||||
if len(authorizedKeys) != 0 {
|
if len(authorizedKeys) != 0 {
|
||||||
authorizedKeysStr = "\n authorized keys:\n - " + italic(strings.Join(authorizedKeys, "\n - "))
|
authorizedKeysStr = "\n authorized keys:\n - " + colors.italic(strings.Join(authorizedKeys, "\n - "))
|
||||||
}
|
}
|
||||||
|
|
||||||
authorizedSecretsStr := ""
|
authorizedSecretsStr := ""
|
||||||
if len(authorizedSecrets) != 0 {
|
if len(authorizedSecrets) != 0 {
|
||||||
authorizedSecretsStr = "\n authorized secrets:\n - " + italic(strings.Join(authorizedSecrets, "\n - "))
|
authorizedSecretsStr = "\n authorized secrets:\n - " + colors.italic(strings.Join(authorizedSecrets, "\n - "))
|
||||||
}
|
}
|
||||||
|
|
||||||
preauthorizedFlags := ""
|
preauthorizedFlags := ""
|
||||||
@@ -130,13 +128,13 @@ var bunker = &cli.Command{
|
|||||||
)
|
)
|
||||||
|
|
||||||
log("listening at %v:\n pubkey: %s \n npub: %s%s%s\n to restart: %s\n bunker: %s\n\n",
|
log("listening at %v:\n pubkey: %s \n npub: %s%s%s\n to restart: %s\n bunker: %s\n\n",
|
||||||
bold(relayURLs),
|
colors.bold(relayURLs),
|
||||||
bold(pubkey),
|
colors.bold(pubkey),
|
||||||
bold(npub),
|
colors.bold(npub),
|
||||||
authorizedKeysStr,
|
authorizedKeysStr,
|
||||||
authorizedSecretsStr,
|
authorizedSecretsStr,
|
||||||
color.CyanString(restartCommand),
|
color.CyanString(restartCommand),
|
||||||
bold(bunkerURI),
|
colors.bold(bunkerURI),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
printBunkerInfo()
|
printBunkerInfo()
|
||||||
|
|||||||
12
helpers.go
12
helpers.go
@@ -212,3 +212,15 @@ func randString(n int) string {
|
|||||||
func leftPadKey(k string) string {
|
func leftPadKey(k string) string {
|
||||||
return strings.Repeat("0", 64-len(k)) + k
|
return strings.Repeat("0", 64-len(k)) + k
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var colors = struct {
|
||||||
|
italic func(...any) string
|
||||||
|
italicf func(string, ...any) string
|
||||||
|
bold func(...any) string
|
||||||
|
boldf func(string, ...any) string
|
||||||
|
}{
|
||||||
|
color.New(color.Italic).Sprint,
|
||||||
|
color.New(color.Italic).Sprintf,
|
||||||
|
color.New(color.Bold).Sprint,
|
||||||
|
color.New(color.Bold).Sprintf,
|
||||||
|
}
|
||||||
|
|||||||
11
serve.go
11
serve.go
@@ -81,24 +81,21 @@ var serve = &cli.Command{
|
|||||||
exited <- err
|
exited <- err
|
||||||
}()
|
}()
|
||||||
|
|
||||||
bold := color.New(color.Bold).Sprintf
|
|
||||||
italic := color.New(color.Italic).Sprint
|
|
||||||
|
|
||||||
var printStatus func()
|
var printStatus func()
|
||||||
|
|
||||||
// relay logging
|
// relay logging
|
||||||
rl.RejectFilter = append(rl.RejectFilter, func(ctx context.Context, filter nostr.Filter) (reject bool, msg string) {
|
rl.RejectFilter = append(rl.RejectFilter, func(ctx context.Context, filter nostr.Filter) (reject bool, msg string) {
|
||||||
log(" got %s %v\n", color.HiYellowString("request"), italic(filter))
|
log(" got %s %v\n", color.HiYellowString("request"), colors.italic(filter))
|
||||||
printStatus()
|
printStatus()
|
||||||
return false, ""
|
return false, ""
|
||||||
})
|
})
|
||||||
rl.RejectCountFilter = append(rl.RejectCountFilter, func(ctx context.Context, filter nostr.Filter) (reject bool, msg string) {
|
rl.RejectCountFilter = append(rl.RejectCountFilter, func(ctx context.Context, filter nostr.Filter) (reject bool, msg string) {
|
||||||
log(" got %s %v\n", color.HiCyanString("count request"), italic(filter))
|
log(" got %s %v\n", color.HiCyanString("count request"), colors.italic(filter))
|
||||||
printStatus()
|
printStatus()
|
||||||
return false, ""
|
return false, ""
|
||||||
})
|
})
|
||||||
rl.RejectEvent = append(rl.RejectEvent, func(ctx context.Context, event *nostr.Event) (reject bool, msg string) {
|
rl.RejectEvent = append(rl.RejectEvent, func(ctx context.Context, event *nostr.Event) (reject bool, msg string) {
|
||||||
log(" got %s %v\n", color.BlueString("event"), italic(event))
|
log(" got %s %v\n", color.BlueString("event"), colors.italic(event))
|
||||||
printStatus()
|
printStatus()
|
||||||
return false, ""
|
return false, ""
|
||||||
})
|
})
|
||||||
@@ -118,7 +115,7 @@ var serve = &cli.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
<-started
|
<-started
|
||||||
log("%s relay running at %s\n", color.HiRedString(">"), bold("ws://%s:%d", hostname, port))
|
log("%s relay running at %s\n", color.HiRedString(">"), colors.boldf("ws://%s:%d", hostname, port))
|
||||||
|
|
||||||
return <-exited
|
return <-exited
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user