Example #1
0
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

	style, _ := v.Settings().Get("caret_style", "underline").(string)
	inverse, _ := v.Settings().Get("inverse_caret_state", false).(bool)

	caretStyle := getCaretStyle(style, inverse)
	oldCaretStyle := caretStyle

	caretBlink, _ := v.Settings().Get("caret_blink", true).(bool)
	if caretBlink && blink {
		caretStyle = 0
	}

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

	lineNumbers, _ := v.Settings().Get("line_numbers", true).(bool)

	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 lineNumbers {
			renderLineNumber(&line, &x, y, lineNumberRenderSize, fg, bg)
		}

		// TODO: doc
		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++
		}

		iscursor := sel.Contains(Region{o, o})
		if iscursor {
			fg = fg | caretStyle
			termbox.SetCell(x, y, ' ', fg, bg)
		}

		if r == '\t' {
			add := (x + 1 + (tabSize - 1)) &^ (tabSize - 1)
			for ; x < add; x++ {
				if x < ex {
					termbox.SetCell(x, y, ' ', fg, bg)
				}
				// A long cursor looks weird
				fg = fg & ^(termbox.AttrUnderline | termbox.AttrReverse)
			}
			continue
		} else if r == '\n' {
			x = sx
			if y++; y > ey {
				break
			} else if lineNumbers {
				// This results in additional calls to renderLineNumber.
				// Maybe just accumulate positions needing line numbers, rendering them
				// after the loop?
				renderLineNumber(&line, &x, y, lineNumberRenderSize, defaultFg, defaultBg)
			}
			continue
		}
		if x < ex {
			termbox.SetCell(x, y, r, fg, bg)
		}
		x++
	}
	fg, bg = defaultFg, defaultBg
	// Need this if the cursor is at the end of the buffer
	o := vr.Begin() + len(runes)
	iscursor := sel.Contains(Region{o, o})
	if iscursor {
		fg = fg | caretStyle
		termbox.SetCell(x, y, ' ', fg, bg)
	}

	// restore original caretStyle before blink modification
	caretStyle = oldCaretStyle

	if rs := sel.Regions(); len(rs) > 0 {
		if r := rs[len(rs)-1]; !vr.Covers(r) {
			t.Show(v, r)
		}
	}

	fg, bg = defaultFg, palLut(textmate.Color{28, 29, 26, 1})
	y = t.window_layout.height - statusbarHeight
	// Draw status bar bottom of window
	for i := 0; i < t.window_layout.width; i++ {
		termbox.SetCell(i, y, ' ', fg, bg)
	}
	t.renderLStatus(v, y, fg, bg)
	// The right status
	rns := []rune(fmt.Sprintf("Tab Size:%d   %s", tabSize, "Go"))
	x = t.window_layout.width - 1 - len(rns)
	addRunes(x, y, rns, fg, bg)
}
Example #2
0
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

	style, _ := v.Settings().Get("caret_style", "underline").(string)
	inverse, _ := v.Settings().Get("inverse_caret_state", false).(bool)

	caretStyle := getCaretStyle(style, inverse)
	caretBlink, _ := v.Settings().Get("caret_blink", true).(bool)
	if caretBlink && blink {
		caretStyle = 0
	}
	tabSize := 4
	ts := v.Settings().Get("tab_size", tabSize)
	// TODO(.): crikey...
	if i, ok := ts.(int); ok {
		tabSize = i
	} else if f, ok := ts.(float64); ok {
		tabSize = int(f)
	}

	lineNumbers, _ := v.Settings().Get("line_numbers", true).(bool)

	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 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++
		}
		iscursor := sel.Contains(Region{o, o})
		if iscursor {
			fg = fg | caretStyle
			termbox.SetCell(x, y, ' ', fg, bg)
		}
		if r == '\t' {
			add := (x + 1 + (tabSize - 1)) &^ (tabSize - 1)
			for x < add {
				if x < ex {
					termbox.SetCell(x, y, ' ', fg, bg)
				}
				// A long cursor looks weird
				fg = fg & ^(termbox.AttrUnderline | termbox.AttrReverse)
				x++
			}
			continue
		} else if r == '\n' {
			x = sx
			if y++; y > ey {
				break
			} else if lineNumbers {
				renderLineNumber(&line, &x, y, lineNumberRenderSize, fg, bg)
			}
			continue
		}
		if x < ex {
			termbox.SetCell(x, y, r, fg, bg)
		}
		x++
	}
	fg, bg = defaultFg, defaultBg
	// Need this if the cursor is at the end of the buffer
	o := vr.Begin() + len(runes)
	iscursor := sel.Contains(Region{o, o})
	if iscursor {
		fg = fg | caretStyle
		termbox.SetCell(x, y, ' ', fg, bg)
	}

	// restore original caretStyle before blink modification
	caretStyle = caretStyle
}
Example #3
0
File: main.go Project: woldan/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++
	}

	// restore original caretStyle before blink modification
	t.settings.caretStyle = caretStyle
}