1package weechat
2
3import (
4	"log"
5	"time"
6)
7
8var DEBUG = true
9
10func debugf(format string, args ...interface{}) {
11	if DEBUG {
12		log.Printf(format, args...)
13	}
14}
15
16type Nick struct {
17	Group   byte   "group"
18	Visible byte   "visible"
19	Name    string "name"
20	Prefix  string "prefix"
21
22	Buffer uintptr "ptr:buffer"
23	Self   uintptr "ptr:nicklist_item"
24}
25
26func (n Nick) String() string {
27	return n.Prefix + n.Name
28}
29
30type Buffer struct {
31	Name      string "name"
32	ShortName string "short_name"
33	FullName  string "full_name"
34	Title     string "title"
35
36	Self uintptr "ptr:buffer"
37	Prev uintptr "prev_buffer"
38	Next uintptr "next_buffer"
39}
40
41type Line struct {
42	Self uintptr "ptr:line"
43}
44
45type LineData struct {
46	Date        time.Time "date"
47	DatePrinted time.Time "date_printed"
48	TimeString  string    "str_time"
49	Prefix      string    "prefix"
50	Message     string    "message"
51
52	RefreshNeeded byte "refresh_needed"
53	Displayed     byte "displayed"
54	Highlight     byte "highlight"
55
56	Buffer uintptr "ptr:buffer"
57	Lines  uintptr "ptr:lines"
58	Line   uintptr "ptr:line"
59	Self   uintptr "ptr:line_data"
60}
61
62func (l *LineData) Clean() {
63	l.Prefix = cleanColor(l.Prefix)
64	l.Message = cleanColor(l.Message)
65	l.TimeString = cleanColor(l.TimeString)
66}
67
68func cleanColor(s string) string {
69	buf := make([]byte, 0, len(s))
70	for i := 0; i < len(s); i++ {
71		if s[i] == '\x19' {
72			// weechat color code.
73			switch s[i+1] {
74			case 'F', 'B':
75				// fore/back-ground color: F## or B##
76				i += 3
77			case '*':
78				// *##,##
79				i += 6
80			default:
81				// ##
82				i += 2
83			}
84		} else {
85			buf = append(buf, s[i])
86		}
87	}
88	return string(buf)
89}
90