Example #1
0
func (mv *MaildirView) Draw(v *gocui.View) error {
	v.Clear()
	w, h := v.Size()
	if h <= 1 {
		return fmt.Errorf("The screen is too small")
	}
	if w <= 20 {
		return fmt.Errorf("The screen is too small")
	}

	xo, _ := v.Origin()
	v.SetOrigin(xo, mv.curTop)
	xc, _ := v.Cursor()
	v.SetCursor(xc, mv.cur-mv.curTop)
	msgs := mv.md.messages
	flagsLen := 5
	indexLen := 6
	sizeLen := 5
	remW := w - indexLen - flagsLen - sizeLen + 2 /* two spaces */ + 2 /* two brackets around the size */
	fromRatio := 25
	subjRatio := 100 - fromRatio
	fromLen := (remW - 10) * fromRatio / 100.0
	subjLen := (remW - 10) * subjRatio / 100.0
	fmtString := fmt.Sprintf("%%-%dd%%-%ds%%-%ds [%%%ds] %%-%ds\n", indexLen, flagsLen, fromLen, sizeLen, subjLen)
	for i, m := range msgs {
		from := util.TruncateString(m.From, fromLen)
		subj := util.TruncateString(m.Subject, subjLen)
		flags := flagsToString(m.Flags)
		fmt.Fprintf(v, fmtString, i, flags, from, util.SiteToHuman(m.size), subj)

	}
	return nil
}
Example #2
0
func partSummary(m *mime.MimePart) *bytes.Buffer {
	name := ""
	if m.Name != "" {
		name = fmt.Sprintf("- %s ", m.Name)
	}

	str := fmt.Sprintf("\n\033[7m[-- %s %s- (%s) --]\n", mime.MimeTypeTxt(m.MimeType), name, util.SiteToHuman(int64(m.Buf.Len())))
	return bytes.NewBufferString(str)
}