File: message.go

package info (click to toggle)
restic 0.18.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 30,824 kB
  • sloc: sh: 3,704; makefile: 50; python: 34
file content (53 lines) | stat: -rw-r--r-- 1,274 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package ui

import (
	"fmt"
)

// Message reports progress with messages of different verbosity.
type Message struct {
	term Terminal
	v    uint
}

// NewMessage returns a message progress reporter with underlying terminal
// term.
func NewMessage(term Terminal, verbosity uint) *Message {
	return &Message{
		term: term,
		v:    verbosity,
	}
}

// E reports an error
func (m *Message) E(msg string, args ...interface{}) {
	m.term.Error(fmt.Sprintf(msg, args...))
}

// S prints a message, this is should only be used for very important messages
// that are not errors.
func (m *Message) S(msg string, args ...interface{}) {
	m.term.Print(fmt.Sprintf(msg, args...))
}

// P prints a message if verbosity >= 1, this is used for normal messages which
// are not errors.
func (m *Message) P(msg string, args ...interface{}) {
	if m.v >= 1 {
		m.term.Print(fmt.Sprintf(msg, args...))
	}
}

// V prints a message if verbosity >= 2, this is used for verbose messages.
func (m *Message) V(msg string, args ...interface{}) {
	if m.v >= 2 {
		m.term.Print(fmt.Sprintf(msg, args...))
	}
}

// VV prints a message if verbosity >= 3, this is used for debug messages.
func (m *Message) VV(msg string, args ...interface{}) {
	if m.v >= 3 {
		m.term.Print(fmt.Sprintf(msg, args...))
	}
}