aboutsummaryrefslogtreecommitdiff
path: root/wildsea_roll
diff options
context:
space:
mode:
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