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