コード例 #1
0
ファイル: main.go プロジェクト: BinaryPaean/lime
func (t *tbfe) renderView(sx, sy, w, h int, v *backend.View) {
	sel := v.Sel()
	substr := v.Buffer().Data()
	vr := t.VisibleRegion(v)
	lines := strings.Split(substr, "\n")
	s, _ := v.Buffer().RowCol(vr.Begin())
	e, _ := v.Buffer().RowCol(vr.End())
	if e > 1 {
		e = e - 1
		if e > h {
			s = e - h
		}
	}
	off := len(strings.Join(lines[:s], "\n"))
	lines = lines[s:e]
	runes := []rune(strings.Join(lines, "\n"))
	x, y := sx, sy
	ex, ey := sx+w, sy+h

	sub2 := ""
	var (
		lastScope string
		lfg, lbg  = defaultFg, defaultBg
	)

	tab_size, ok := v.Settings().Get("tab_size", 4).(int)
	if !ok {
		tab_size = 4
	}
	caret_style := termbox.AttrUnderline
	if b, ok := v.Settings().Get("caret_style", "underline").(string); ok {
		if b == "block" {
			caret_style = termbox.AttrReverse
		}
	}
	if b, ok := v.Settings().Get("inverse_caret_state", false).(bool); !b && ok {
		if caret_style == termbox.AttrReverse {
			caret_style = termbox.AttrUnderline
		} else {
			caret_style = termbox.AttrReverse
		}
	}
	caret_blink := true
	if b, ok := v.Settings().Get("caret_blink", true).(bool); ok {
		caret_blink = b
	}

	for i := range runes {
		sub2 += string(runes[i])

		if x < ex {
			o := off + len(sub2)
			r := primitives.Region{o, o}
			fg, bg := lfg, lbg
			scope := v.ScopeName(o)
			if scope != lastScope {
				fg, bg = defaultFg, defaultBg
				lastScope = scope
				na := scope
				for len(na) > 0 {
					sn := na
					i := strings.LastIndex(sn, " ")
					if i != -1 {
						sn = sn[i+1:]
					}
					if c, ok := schemelut[sn]; ok {
						fg, bg = c[0], c[1]
						break
					}
					if i2 := strings.LastIndex(na, "."); i2 == -1 {
						break
					} else if i > i2 {
						na = na[:i]
					} else {
						na = strings.TrimSpace(na[:i2])
					}
				}
				lfg, lbg = fg, bg
			} else {
				fg, bg = lfg, lbg
			}
			for _, r2 := range sel.Regions() {
				if r2.B == r.B {
					if !caret_blink || blink {
						if r2.Contains(o) {
							fg |= termbox.AttrReverse
						} else {
							fg |= caret_style
						}
					}
					break
				} else if r2.Contains(o) {
					fg |= termbox.AttrReverse
					break
				}
			}
			if runes[i] == '\t' {
				add := (x + 1 + (tab_size - 1)) &^ (tab_size - 1)

				for x < add {
					termbox.SetCell(x, y, ' ', fg, bg)
					x++
				}
				continue
			} else if runes[i] == '\n' {
				termbox.SetCell(x, y, ' ', fg, bg)
				x = sx
				y++
				if y > ey {
					break
				}
				continue
			}
			termbox.SetCell(x, y, runes[i], fg, bg)
		}
		x++
	}
}
コード例 #2
0
ファイル: main.go プロジェクト: vivekgalatage/lime
func (t *tbfe) renderView(v *backend.View, lay layout) {
	p := util.Prof.Enter("render")
	defer p.Exit()

	sx, sy, w, h := lay.x, lay.y, lay.width, lay.height
	vr := lay.visible
	runes := v.Buffer().Substr(vr)
	x, y := sx, sy
	ex, ey := sx+w, sy+h

	caretStyle := t.settings.caretStyle
	if t.settings.caretBlink && blink {
		t.settings.caretStyle = 0
	}

	recipie := v.Transform(scheme, vr).Transcribe()

	fg, bg := defaultFg, defaultBg
	sel := v.Sel()

	line, _ := v.Buffer().RowCol(vr.Begin())
	eofline, _ := v.Buffer().RowCol(v.Buffer().Size())
	lineNumberRenderSize := len(intToRunes(eofline))

	for i, r := range runes {
		o := vr.Begin() + i
		curr := 0
		fg, bg = defaultFg, defaultBg

		if t.settings.lineNumbers {
			renderLineNumber(&line, &x, y, lineNumberRenderSize, fg, bg)
		}

		for curr < len(recipie) && (o >= recipie[curr].Region.Begin()) {
			if o < recipie[curr].Region.End() {
				fg = palLut(textmate.Color(recipie[curr].Flavour.Foreground))
				bg = palLut(textmate.Color(recipie[curr].Flavour.Background))
			}
			curr++
		}
		if sel.Contains(Region{o, o}) {
			fg = fg | t.settings.caretStyle
		}
		if r == '\t' {
			add := (x + 1 + (t.settings.tabSize - 1)) &^ (t.settings.tabSize - 1)
			for x < add {
				if x < ex {
					termbox.SetCell(x, y, ' ', fg, bg)
				}
				fg = fg &^ termbox.AttrUnderline // Just looks weird with a long underline
				x++
			}
			continue
		} else if r == '\n' {
			x = sx
			y++
			if y > ey {
				break
			}
			continue
		}
		if x < ex {
			termbox.SetCell(x, y, r, fg, bg)
		}
		x++
	}

	if t.settings.lineNumbers {
		renderLineNumber(&line, &x, y, lineNumberRenderSize, fg, bg)
	}

	// restore original caretStyle before blink modification
	t.settings.caretStyle = caretStyle
}
コード例 #3
0
ファイル: main.go プロジェクト: richardfontana/lime
func (t *tbfe) renderView(v *backend.View, lay layout) {
	p := util.Prof.Enter("render")
	defer p.Exit()

	sx, sy, w, h := lay.x, lay.y, lay.width, lay.height
	sel := v.Sel()
	vr := lay.visible
	runes := v.Buffer().SubstrR(vr)
	x, y := sx, sy
	ex, ey := sx+w, sy+h

	var (
		lastScope string
		lfg, lbg  = defaultFg, defaultBg
	)

	tab_size, ok := v.Settings().Get("tab_size", 4).(int)
	if !ok {
		tab_size = 4
	}
	caret_style := termbox.AttrUnderline
	if b, ok := v.Settings().Get("caret_style", "underline").(string); ok {
		if b == "block" {
			caret_style = termbox.AttrReverse
		}
	}
	if b, ok := v.Settings().Get("inverse_caret_state", false).(bool); !b && ok {
		if caret_style == termbox.AttrReverse {
			caret_style = termbox.AttrUnderline
		} else {
			caret_style = termbox.AttrReverse
		}
	}
	caret_blink := true
	if b, ok := v.Settings().Get("caret_blink", true).(bool); ok {
		caret_blink = b
	}

	highlight_line := false
	if b, ok := v.Settings().Get("highlight_line", highlight_line).(bool); ok {
		highlight_line = b
	}

	// TODO: much of this belongs in backend as it's not specific to any particular frontend
	for i := range runes {
		o := vr.Begin() + i
		fg, bg := lfg, lbg
		scope := v.ScopeName(o)
		var lr Region
		if highlight_line {
			lr = v.Buffer().Line(o)
		}
		if scope != lastScope {
			fg, bg = defaultFg, defaultBg
			lastScope = scope
			na := scope
			for len(na) > 0 {
				sn := na
				i := strings.LastIndex(sn, " ")
				if i != -1 {
					sn = sn[i+1:]
				}
				if c, ok := schemelut[sn]; ok {
					fg, bg = c[0], c[1]
					break
				}
				if i2 := strings.LastIndex(na, "."); i2 == -1 {
					break
				} else if i > i2 {
					na = na[:i]
				} else {
					na = strings.TrimSpace(na[:i2])
				}
			}
			lfg, lbg = fg, bg
		} else {
			fg, bg = lfg, lbg
		}
		for _, r2 := range sel.Regions() {
			if highlight_line && (lr.Contains(r2.A) || lr.Contains(r2.B)) {
				// TODO: highlight color
				bg |= termbox.AttrReverse
				continue
			}
			if r2.Contains(o) {
				if r2.Size() == 0 {
					if !caret_blink || blink {
						fg |= caret_style
					}
					break
				} else if r2.Contains(o + 1) {
					// TODO: selection color
					fg |= termbox.AttrReverse
					break
				}
			}
		}
		if runes[i] == '\t' {
			add := (x + 1 + (tab_size - 1)) &^ (tab_size - 1)
			for x < add {
				if x < ex {
					termbox.SetCell(x, y, ' ', fg, bg)
				}
				fg = fg &^ termbox.AttrUnderline // Just looks weird with a long underline
				x++
			}
			continue
		} else if runes[i] == '\n' {
			for ; x < ex; x++ {
				termbox.SetCell(x, y, ' ', fg, bg)
				if !highlight_line {
					break
				}
			}
			x = sx
			y++
			if y > ey {
				break
			}
			continue
		}
		if x < ex {
			termbox.SetCell(x, y, runes[i], fg, bg)
		}
		x++
	}
}
コード例 #4
0
ファイル: main.go プロジェクト: nadavvin/lime
func (t *tbfe) renderView(v *backend.View, lay layout) {
	p := util.Prof.Enter("render")
	defer p.Exit()

	sx, sy, w, h := lay.x, lay.y, lay.width, lay.height
	vr := lay.visible
	runes := v.Buffer().Substr(vr)
	x, y := sx, sy
	ex, ey := sx+w, sy+h

	tab_size, ok := v.Settings().Get("tab_size", 4).(int)
	if !ok {
		tab_size = 4
	}

	recipie := v.Transform(scheme, vr).Transcribe()

	curr := 0
	fg, bg := defaultFg, defaultBg
	_ = render.DRAW_TEXT
	sel := v.Sel()

	caret_blink := true
	if b, ok := v.Settings().Get("caret_blink", true).(bool); ok {
		caret_blink = b
	}

	highlight_line := false
	if b, ok := v.Settings().Get("highlight_line", highlight_line).(bool); ok {
		highlight_line = b
	}
	caret_style := termbox.AttrUnderline
	if b, ok := v.Settings().Get("caret_style", "underline").(string); ok {
		if b == "block" {
			caret_style = termbox.AttrReverse
		}
	}
	if b, ok := v.Settings().Get("inverse_caret_state", false).(bool); !b && ok {
		if caret_style == termbox.AttrReverse {
			caret_style = termbox.AttrUnderline
		} else {
			caret_style = termbox.AttrReverse
		}
	}

	if caret_blink && blink {
		caret_style = 0
	}

	for i, r := range runes {
		o := vr.Begin() + i
		curr = 0
		fg, bg = defaultFg, defaultBg
		for curr < len(recipie) && (o >= recipie[curr].Region.Begin()) {
			// if curr > 0 {
			// 	curr--
			// }
			if o < recipie[curr].Region.End() {
				fg = palLut(textmate.Color(recipie[curr].Flavour.Foreground))
				bg = palLut(textmate.Color(recipie[curr].Flavour.Background))
			}
			curr++
		}
		if sel.Contains(Region{o, o}) {
			fg = fg | caret_style
		}
		if r == '\t' {
			add := (x + 1 + (tab_size - 1)) &^ (tab_size - 1)
			for x < add {
				if x < ex {
					termbox.SetCell(x, y, ' ', fg, bg)
				}
				fg = fg &^ termbox.AttrUnderline // Just looks weird with a long underline
				x++
			}
			continue
		} else if r == '\n' {
			// for ; x < ex; x++ {
			// 	termbox.SetCell(x, y, ' ', fg, bg)
			// 	if !highlight_line {
			// 		break
			// 	}
			// }
			x = sx
			y++
			if y > ey {
				break
			}
			continue
		}
		if x < ex {
			termbox.SetCell(x, y, r, fg, bg)
		}
		x++
	}
}