Example #1
0
// free memory for various things at the end of the program
func cleanup(menu_items []*gc.MenuItem, contactMenu *gc.Menu) {
	for i := 0; i < len(menu_items); i++ {
		menu_items[i].Free()
	}
	contactMenu.UnPost()
	contactMenu.Free()
}
Example #2
0
// contact Menu Window Navigation input handler
func contactsWindowNavigation(contactsMenuWin *gc.Window, contactMenu *gc.Menu) int {
	var c gc.Char
	var rawInput gc.Key
	for {
		gc.Update()
		rawInput = contactsMenuWin.GetChar()
		c = gc.Char(rawInput)
		if rawInput == gc.KEY_TAB || rawInput == gc.KEY_RETURN {
			return 0
		} else if c == gc.Char(27) {
			return 1
		} else if c == gc.Char('j') || rawInput == gc.KEY_DOWN {
			contactMenu.Driver(gc.REQ_DOWN)
			changeContact(contactsMenuWin, contactMenu)
		} else if c == gc.Char('k') || rawInput == gc.KEY_UP {
			contactMenu.Driver(gc.REQ_UP)
			changeContact(contactsMenuWin, contactMenu)
		} else if c == gc.Char('g') {
			contactMenu.Driver(gc.REQ_FIRST)
			changeContact(contactsMenuWin, contactMenu)
		} else if c == gc.Char('G') {
			contactMenu.Driver(gc.REQ_LAST)
			changeContact(contactsMenuWin, contactMenu)
		} else {
			continue
		}
	}
}
Example #3
0
func freeMenu(menu *goncurses.Menu) {
	if menu != nil {
		menu.UnPost()
		for _, item := range menu.Items() {
			item.Free()
		}
		menu.Free()
	}
}
//Handles keeping track of all the data structures for changing a contact.
func changeContact(contactsMenuWin *gc.Window, contactMenu *gc.Menu) {
	globalMsgWin.Erase()
	currentContact = getTel(contactMenu.Current(nil).Name())
	rows := getConversation(currentContact)
	defer rows.Close()
	var msg string
	var src string
	var t time.Time
	var b bytes.Buffer
	for rows.Next() {
		rows.Scan(&msg, &src, &t)
		if src != "You" {
			if time.Now().AddDate(0, 0, -1).Before(t) {
				if t.Hour() < 10 {
					b.WriteString("0")
				}
				b.WriteString(strconv.Itoa(t.Hour()))
				b.WriteString(":")
				if t.Minute() < 10 {
					b.WriteString("0")
				}
				b.WriteString(strconv.Itoa(t.Minute()))
				b.WriteString(": ")
				b.WriteString(msg)
				printToMsgWindow(b.String(), globalMsgWin, false)
				b.Reset()
			} else if (time.Now()).AddDate(0, 0, -6).Before(t) {
				b.WriteString(string([]byte(t.Weekday().String())[0:3]))
				b.WriteString(" at ")
				if t.Hour() < 10 {
					b.WriteString("0")
				}
				b.WriteString(strconv.Itoa(t.Hour()))
				b.WriteString(":")
				if t.Minute() < 10 {
					b.WriteString("0")
				}
				b.WriteString(strconv.Itoa(t.Minute()))
				b.WriteString(": ")
				b.WriteString(msg)
				printToMsgWindow(b.String(), globalMsgWin, false)
				b.Reset()
			} else {
				b.WriteString(t.Local().String())
				b.WriteString(": ")
				b.WriteString(msg)
				printToMsgWindow(b.String(), globalMsgWin, false)
				b.Reset()
			}
		} else {
			if time.Now().AddDate(0, 0, -1).Before(t) {
				if t.Hour() < 10 {
					b.WriteString("0")
				}
				b.WriteString(strconv.Itoa(t.Hour()))
				b.WriteString(":")
				if t.Minute() < 10 {
					b.WriteString("0")
				}
				b.WriteString(strconv.Itoa(t.Minute()))
				b.WriteString(": ")
				b.WriteString(msg)
				printToMsgWindow(b.String(), globalMsgWin, true)
				b.Reset()
			} else if (time.Now()).AddDate(0, 0, -6).Before(t) {
				b.WriteString(string([]byte(t.Weekday().String())[0:3]))
				b.WriteString(" at ")
				if t.Hour() < 10 {
					b.WriteString("0")
				}
				b.WriteString(strconv.Itoa(t.Hour()))
				b.WriteString(":")
				if t.Minute() < 10 {
					b.WriteString("0")
				}
				b.WriteString(strconv.Itoa(t.Minute()))
				b.WriteString(": ")
				b.WriteString(msg)
				printToMsgWindow(b.String(), globalMsgWin, true)
				b.Reset()
			} else {
				b.WriteString(t.Local().String())
				b.WriteString(": ")
				b.WriteString(msg)
				printToMsgWindow(b.String(), globalMsgWin, true)
				b.Reset()
			}
		}
	}
	globalMsgWin.Refresh()
}