예제 #1
0
파일: maildir.go 프로젝트: deweerdt/amua
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
}
예제 #2
0
파일: amua.go 프로젝트: deweerdt/amua
func drawKnownMaildirs(amua *Amua, g *gocui.Gui, v *gocui.View) error {
	v.Clear()
	v.Frame = false
	w, h := v.Size()
	displayed := len(amua.knownMaildirs)
	if len(amua.knownMaildirs) > h {
		displayed = h
	}
	fillers := h - displayed
	space := 1
	for i := 0; i < displayed; i++ {
		current := amua.knownMaildirs[i].maildir == amua.curMaildirView.md
		nrMsgs := fmt.Sprintf("(%d)", len(amua.knownMaildirs[i].maildir.messages))
		availableWidth := w - space - len(nrMsgs) - 3
		strfmt := fmt.Sprintf(" %%-%ds %s ", availableWidth, nrMsgs)
		str := fmt.Sprintf(strfmt, util.TruncateString(amua.knownMaildirs[i].path, availableWidth))
		if current {
			colorstring.Fprintf(v, "[bold]%s", str)
		} else {
			fmt.Fprint(v, str)
		}
		fmt.Fprintf(v, strings.Repeat(" ", space-1))
		fmt.Fprintln(v, "|")
	}
	for i := 0; i < fillers; i++ {
		fmt.Fprintf(v, strings.Repeat(" ", w-1))
		fmt.Fprintln(v, "|")
	}
	return nil
}