Пример #1
0
func (o *View) Py_substr(tu *py.Tuple) (py.Object, error) {
	var (
		arg1 primitives.Region
	)
	if v, err := tu.GetItem(0); err != nil {
		return nil, err
	} else {
		if v2, ok := v.(*Region); !ok {
			if v2, ok := v.(*py.Long); !ok {
				return nil, fmt.Errorf("Expected type *Region or *Int for primitives.Buffer.Substr() arg1, not %s", v.Type())
			} else {
				arg1.A = int(v2.Int64())
				arg1.B = arg1.A + 1
			}
		} else {
			arg1 = v2.data
		}
	}
	ret0 := o.data.Buffer().Substr(arg1)
	var err error
	var pyret0 py.Object

	pyret0, err = py.NewUnicode(ret0)
	if err != nil {
		// TODO: do the py objs need to be freed?
		return nil, err
	}

	return pyret0, err
}
Пример #2
0
func (vr *ViewRegions) Cull(viewport primitives.Region) {
	nr := []primitives.Region{}
	for _, r := range vr.Regions.Regions() {
		if viewport.Intersects(r) {
			nr = append(nr, viewport.Intersection(r))
		}
	}
	vr.Regions.Clear()
	vr.Regions.AddAll(nr)
}
Пример #3
0
func (v *View) Py_show(tu *py.Tuple, kw *py.Dict) (py.Object, error) {
	var (
		arg1 primitives.Region
	)
	if v, err := tu.GetItem(0); err != nil {
		return nil, err
	} else {
		if v2, ok := v.(*Region); !ok {
			if v2, ok := v.(*py.Long); !ok {
				return nil, fmt.Errorf("Expected type *Region or *Int for primitives.Buffer.Substr() arg1, not %s", v.Type())
			} else {
				arg1.A = int(v2.Int64())
				arg1.B = arg1.A + 1
			}
		} else {
			arg1 = v2.data
		}
	}
	backend.GetEditor().Frontend().Show(v.data, arg1)
	return toPython(nil)
}
Пример #4
0
func (t *tbfe) clip(v *backend.View, r primitives.Region) primitives.Region {
	s, _ := v.Buffer().RowCol(r.Begin())
	e, _ := v.Buffer().RowCol(r.End())

	_, h := termbox.Size()
	h -= console_height
	if e-s > h {
		e = s + h
	}
	if e2, _ := v.Buffer().RowCol(v.Buffer().TextPoint(e, 1)); e2 < e {
		e = e2
	}
	if e-s < h {
		s = e - h
	}
	if s < 1 {
		s = 1
	}
	r.A = v.Buffer().Line(v.Buffer().TextPoint(s, 1)).A
	r.B = v.Buffer().Line(v.Buffer().TextPoint(e, 1)).B
	return r
}
Пример #5
0
func (t *tbfe) Show(v *backend.View, r primitives.Region) {
	t.visibleregion[v] = t.clip(v, primitives.Region{r.Begin(), v.Buffer().Size()})
}
Пример #6
0
func newQLimeView(v *backend.View) *QLimeView {
	log4go.Debug("new_QLimeView entered")
	defer log4go.Debug("new_QLimeView exited")
	var ret QLimeView
	ret.Widget = qt5.NewWidget()
	ret.v = v
	ret.Widget.OnPaintEvent(func(ev *qt5.PaintEvent) {
		p := qt5.NewPainter()
		defer p.Close()
		p.Begin(ret)
		b := v.Buffer()
		ps := p.Font().PointSize()

		pen := qt5.NewPen()
		p.SetPen(pen)
		brush := qt5.NewBrush()
		brush.SetStyle(qt5.SolidPattern)
		def := scheme.Settings[0]
		p.SetBrush(brush)
		f := p.Font()
		f.SetFixedPitch(true)
		p.SetFont(f)

		brush.SetColor(color.RGBA(def.Settings["background"]))
		p.DrawRect(ev.Rect())
		is_widget, ok := v.Settings().Get("is_widget", false).(bool)
		is_widget = ok && is_widget
		pen.SetColor(color.RGBA(def.Settings["background"]))
		p.SetPen(pen)

		for y := 0; y < 20; y++ {
			pos := b.TextPoint(y, 0)
			line := b.Line(pos)

			if is_widget {
				p.DrawText(qt5.Point{0, (y + 1) * (ps + 2)}, b.Substr(line))
			} else {
				for line.Contains(pos) {
					scope := primitives.Region{pos, pos}
					sn := v.ScopeName(pos)
					for line.Contains(pos) {
						pos++
						if v.ScopeName(pos) != sn {
							scope.B = pos
							break
						}
					}
					is := line.Intersection(scope)
					c := color.RGBA(def.Settings["foreground"])
					s := scheme.ClosestMatchingSetting(sn)
					if v, ok := s.Settings["foreground"]; ok {
						c = color.RGBA(v)
					}
					pen.SetColor(c)
					p.SetPen(pen)
					_, col := b.RowCol(line.A)
					p.DrawText(qt5.Point{col * ps / 2, (y + 1) * (ps + 2)}, b.Substr(is))
					line.A = is.End()
				}
			}
		}
	})
	ret.Widget.OnResizeEvent(func(ev *qt5.ResizeEvent) {
		if w, ok := v.Settings().Get("is_widget", false).(bool); ok && !w {
			ret.Widget.SetMinimumSize(qt5.Size{600, 100})
		}
	})
	v.Settings().Set("lime.qt.widget", &ret)
	return &ret
}