Use variadic args for messenger Message and Error

Closes #41
This commit is contained in:
Zachary Yedidia
2016-04-19 13:45:24 -04:00
parent 87108bfed8
commit 2355f2fa51

View File

@@ -2,6 +2,7 @@ package main
import (
"bufio"
"bytes"
"fmt"
"os"
"strconv"
@@ -15,8 +16,8 @@ import (
// The function must be called when the screen is not initialized
// This will write the message, and wait for the user
// to press and key to continue
func TermMessage(msg string) {
fmt.Println(msg)
func TermMessage(msg ...interface{}) {
fmt.Println(msg...)
fmt.Print("\nPress enter to continue")
reader := bufio.NewReader(os.Stdin)
@@ -49,8 +50,10 @@ type Messenger struct {
}
// Message sends a message to the user
func (m *Messenger) Message(msg string) {
m.message = msg
func (m *Messenger) Message(msg ...interface{}) {
buf := new(bytes.Buffer)
fmt.Fprint(buf, msg...)
m.message = buf.String()
m.style = defStyle
if _, ok := colorscheme["message"]; ok {
@@ -60,8 +63,10 @@ func (m *Messenger) Message(msg string) {
}
// Error sends an error message to the user
func (m *Messenger) Error(msg string) {
m.message = msg
func (m *Messenger) Error(msg ...interface{}) {
buf := new(bytes.Buffer)
fmt.Fprint(buf, msg...)
m.message = buf.String()
m.style = defStyle.
Foreground(tcell.ColorBlack).
Background(tcell.ColorMaroon)