aboutsummaryrefslogtreecommitdiff
path: root/wildsea_roll
diff options
context:
space:
mode:
authorNat Lasseter <user@4574.co.uk>2024-11-05 19:14:49 +0000
committerNat Lasseter <user@4574.co.uk>2024-11-05 19:14:49 +0000
commit05b99b8d32f13836526e8b3f29ffa55b6135c4e0 (patch)
treedcd34ac0cdf0ed6f7d5556c561ea7d01839c9a63 /wildsea_roll
parentaada9ee5b918475300609e1f94a20a91a82deeb9 (diff)
[wildsea_roll] Add colour!HEADmain
Diffstat (limited to 'wildsea_roll')
-rwxr-xr-xwildsea_roll34
1 files changed, 29 insertions, 5 deletions
diff --git a/wildsea_roll b/wildsea_roll
index 9f6cac2..abacd29 100755
--- a/wildsea_roll
+++ b/wildsea_roll
@@ -1,5 +1,22 @@
#!/usr/bin/env ruby
+module Term
+ CSI = "["
+
+ def sgr(*code)
+ "#{CSI}#{code.join(?;)}m"
+ end
+ module_function :sgr
+
+ RESET = sgr(0)
+ BOLD = sgr(1, 97)
+ RED = sgr(31)
+ GREEN = sgr(32)
+ YELLOW = sgr(33)
+ BLUE = sgr(34)
+ PURPLE = sgr(35)
+end
+
class Roll
def initialize(res, cuts)
@res = res
@@ -21,14 +38,14 @@ class Roll
def interpret
outcome = case @res.max
when 1,2,3
- "disaster"
+ "#{Term::RED}disaster#{Term::RESET}"
when 4,5
- "conflict"
+ "#{Term::YELLOW}conflict#{Term::RESET}"
when 6
- "triumph"
+ "#{Term::GREEN}triumph#{Term::RESET}"
end
- "#{outcome}#{" with a twist" if twist?}"
+ "#{outcome}#{" with a #{Term::BLUE}twist#{Term::RESET}" if twist?}"
end
def cut_twist
@@ -56,7 +73,7 @@ class Roll
readres = ""
ary.tally.each do |val, num|
- readres += "#{numword[num]} #{val}#{?s if num > 1}, "
+ readres += "#{numword[num]} #{Term::BOLD}#{val}#{Term::RESET}#{?s if num > 1}, "
end
readres = readres[0...-2]
readres.sub!(/.*\K, /, " and ")
@@ -76,13 +93,20 @@ class Roll
end
def prompt(msg)
+ print Term::PURPLE
print msg
print ?? unless msg[-1] == ??
print ?\s
+ print Term::RESET
gets.to_i
end
+trap("INT") do
+ puts
+ exit
+end
+
loop do
number = prompt "How many dice"
break if number == 0