aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/color/color.go23
-rw-r--r--internal/config/config.go1
-rw-r--r--internal/game/cmd_color.go1
-rw-r--r--internal/game/cmd_option.go11
-rw-r--r--internal/game/sys_safespot.go12
-rw-r--r--internal/player/player.go2
-rw-r--r--internal/ui/table.go4
7 files changed, 31 insertions, 23 deletions
diff --git a/internal/color/color.go b/internal/color/color.go
index 92535d1..8e301e4 100644
--- a/internal/color/color.go
+++ b/internal/color/color.go
@@ -180,12 +180,23 @@ func VisibleLen(s string) int {
return utf8.RuneCountInString(ansiRe.ReplaceAllString(s, ""))
}
+// Ellipsis returns a Unicode ellipsis character when unicode is true,
+// or the ASCII "..." otherwise.
+func Ellipsis(unicode bool) string {
+ if unicode {
+ return "\u2026"
+ }
+ return "..."
+}
+
// TruncateVisible truncates s to at most maxVisible visible characters,
// preserving ANSI SGR codes. Assumes cells follow the common pattern
-// "\x1b[...mTEXT\x1b[0m" or are plain text. Appends "..." when truncated.
-func TruncateVisible(s string, maxVisible int) string {
- if maxVisible < 3 {
- maxVisible = 3
+// "\x1b[...mTEXT\x1b[0m" or are plain text. Appends an ellipsis when truncated.
+func TruncateVisible(s string, maxVisible int, unicode bool) string {
+ ellipsis := Ellipsis(unicode)
+ ellipLen := utf8.RuneCountInString(ellipsis)
+ if maxVisible < ellipLen {
+ maxVisible = ellipLen
}
if VisibleLen(s) <= maxVisible {
return s
@@ -201,12 +212,12 @@ func TruncateVisible(s string, maxVisible int) string {
rest = rest[:len(rest)-len(Reset)]
}
runes := []rune(rest)
- budget := maxVisible - 3
+ budget := maxVisible - ellipLen
if budget < 0 {
budget = 0
}
if len(runes) > budget {
- rest = string(runes[:budget]) + "..."
+ rest = string(runes[:budget]) + ellipsis
}
return pre + rest + suf
}
diff --git a/internal/config/config.go b/internal/config/config.go
index c8d8830..716f7ec 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -63,6 +63,7 @@ func DefaultColors() ColorsConfig {
"farm_disease": "C4",
"map_at": "0F",
"map_blocked": "C4",
+ "safespot_alert": "C4 bold",
}
}
diff --git a/internal/game/cmd_color.go b/internal/game/cmd_color.go
index fd9fa55..f7041df 100644
--- a/internal/game/cmd_color.go
+++ b/internal/game/cmd_color.go
@@ -166,6 +166,7 @@ var colorCategoryOrder = []string{
"map_at",
"map_blocked",
+ "safespot_alert",
}
func showColorTable(g *Game, sess *net.Session) {
diff --git a/internal/game/cmd_option.go b/internal/game/cmd_option.go
index 958fc0b..f404c2e 100644
--- a/internal/game/cmd_option.go
+++ b/internal/game/cmd_option.go
@@ -26,7 +26,7 @@ func (g *Game) doOption(sess *net.Session, input string) {
}
for _, def := range player.OptionDefs {
val := formatOptionValue(p, &def)
- val = truncateForTable(val)
+ val = truncateForTable(val, p.OptionBool("unicode"))
valid := formatValidValues(&def)
table.Rows = append(table.Rows, []string{
color.Render(mode, color.Parse("4B"), def.Name),
@@ -150,9 +150,12 @@ func parseOptionValue(def *player.OptionDef, input string) (any, bool) {
return nil, false
}
-func truncateForTable(s string) string {
- if len(s) <= 10 {
+func truncateForTable(s string, unicode bool) string {
+ ellipsis := color.Ellipsis(unicode)
+ ellipLen := len([]rune(ellipsis))
+ if len([]rune(s)) <= 10 {
return s
}
- return s[:7] + "..."
+ runes := []rune(s)
+ return string(runes[:10-ellipLen]) + ellipsis
}
diff --git a/internal/game/sys_safespot.go b/internal/game/sys_safespot.go
index 5544667..cdb954b 100644
--- a/internal/game/sys_safespot.go
+++ b/internal/game/sys_safespot.go
@@ -191,12 +191,7 @@ func (g *Game) degradeSafespot(st *world.ObjState, objDef *object.ObjectDef, cfg
if occSess := g.sessionInRoom(name, roomSessions); occSess != nil {
occSess.WriteLine(color.ExpandTags(g.colorMode(occSess),
fmt.Sprintf("The %s crumbles away!", objDef.Name)))
- if occSess.Player != nil {
- alert := occSess.Player.OptionString("safespot_alert")
- if alert != "" {
- occSess.WriteLine(color.ExpandTags(g.colorMode(occSess), alert))
- }
- }
+ occSess.WriteLine(g.colorize(occSess, "safespot_alert", "Your safespot has been compromised!"))
g.writePrompt(occSess)
}
}
@@ -265,10 +260,7 @@ func (g *Game) forceLeaveSafespot(sess *net.Session, p *player.Player, ss *Safes
if reason != "" {
sess.WriteLine(reason)
- alert := p.OptionString("safespot_alert")
- if alert != "" {
- sess.WriteLine(color.ExpandTags(g.colorMode(sess), alert))
- }
+ sess.WriteLine(g.colorize(sess, "safespot_alert", "Your safespot has been compromised!"))
}
}
diff --git a/internal/player/player.go b/internal/player/player.go
index efe13e2..2f83c21 100644
--- a/internal/player/player.go
+++ b/internal/player/player.go
@@ -138,7 +138,7 @@ var OptionDefs = []OptionDef{
{"mix_all", OptBool, false, nil, "Auto-start mixing when only one product is possible"},
{"construct_all", OptBool, false, nil, "Auto-start constructing when only one product is possible"},
{"craft_all", OptBool, false, nil, "Auto-start crafting when only one product is possible"},
- {"safespot_alert", OptString, "{C4 bold}** Your safespot has been compromised! **{/}", nil, "Message shown when forced out of a safespot"},
+
{"danger_warning", OptBool, true, nil, "Confirm before entering a dangerous (hazardous) area"},
{"prompt_break", OptString, "on", []string{"on", "off"}, "Line break after prompt before output"},
}
diff --git a/internal/ui/table.go b/internal/ui/table.go
index 5061417..5ef2c99 100644
--- a/internal/ui/table.go
+++ b/internal/ui/table.go
@@ -83,11 +83,11 @@ func (t *Table) Render(unicode bool, maxWidth int) []string {
colWidths[last] = budget
if len(t.Columns) > last {
- t.Columns[last] = color.TruncateVisible(t.Columns[last], budget)
+ t.Columns[last] = color.TruncateVisible(t.Columns[last], budget, unicode)
}
for i := range t.Rows {
if len(t.Rows[i]) > last {
- t.Rows[i][last] = color.TruncateVisible(t.Rows[i][last], budget)
+ t.Rows[i][last] = color.TruncateVisible(t.Rows[i][last], budget, unicode)
}
}
}