| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- //
- // terminal_helper.cxx
- // simple_dice
- //
- // Created by Sam Jaffe on 12/18/18.
- // Copyright © 2018 Sam Jaffe. All rights reserved.
- //
- #include "dice-roll/terminal_helper.h"
- #include <iostream>
- #include "dice-roll/die.h"
- #include "dice-roll/exception.h"
- #include "dice-roll/roll.h"
- namespace terminal { namespace {
- void print(dice::dice_roll const & r) {
- std::cout << int(r) << " (" << r << ")\n";
- }
-
- void print(std::vector<dice::dice_roll> const & rs) {
- if (rs.size() != 1) {
- std::cout << '\n';
- for (int i = 0; i < rs.size(); ++i) {
- std::cout << " Result/" << i << ": ";
- print(rs[i]);
- }
- } else {
- print(rs[0]);
- }
- }
- }}
- namespace terminal {
- void process_dice_string(std::string const & str) {
- auto d = dice::from_string(str);
- auto rs = dice::roller()(d);
- std::cout << "Result of '" << d << "': ";
- print(rs);
- }
-
- void print_error_message(std::string const & str,
- dice::unexpected_token const & ut) {
- std::cerr << "Error in roll: '" << str << "': " << ut.what() << "\n";
- std::cerr << " " << ut.pointer(str.size() + 1) << std::endl;
- }
- }
|