func TestTransform(t *testing.T) { sc, err := textmate.LoadTheme("../3rdparty/bundles/TextMate-Themes/GlitterBomb.tmTheme") if err != nil { t.Fatal(err) } var ( w Window v = w.NewFile() ) v.Settings().Set("syntax", "textmate/testdata/Go.tmLanguage") d, err := ioutil.ReadFile("view.go") if err != nil { t.Fatal(err) } e := v.BeginEdit() v.Insert(e, 0, string(d)) v.EndEdit(e) time.Sleep(time.Second) a := v.Transform(sc, Region{0, 100}).Transcribe() v.Transform(sc, Region{100, 200}).Transcribe() c := v.Transform(sc, Region{0, 100}).Transcribe() if !reflect.DeepEqual(a, c) { t.Errorf("not equal:\n%v\n%v", a, c) } }
func loadTextMateScheme() { path := "../../3rdparty/bundles/TextMate-Themes/GlitterBomb.tmTheme" if sc, err := textmate.LoadTheme(path); err != nil { log4go.Error(err) } else { scheme = sc } }
func main() { py.InitializeEx(false) defer py.Finalize() e := backend.GetEditor() log4go.AddFilter("stdout", log4go.DEBUG, log4go.NewConsoleLogWriter()) if sc, err := textmate.LoadTheme("../../3rdparty/bundles/TextMate-Themes/GlitterBomb.tmTheme"); err != nil { log4go.Error(err) } else { scheme = sc log4go.Debug("scheme: %v", scheme) } backend.OnNewWindow.Add(new_window) backend.OnNew.Add(new_view) backend.OnModified.Add(view_modified) go e.Init() qt5.Main(func() { w := e.NewWindow() w.OpenFile("main.go", 0) w.OpenFile("../../backend/editor.go", 0) qt5.Run() }) }
func (t *tbfe) loop() { backend.OnNew.Add(func(v *backend.View) { v.Settings().AddOnChange("lime.frontend.termbox.render", func() { t.render() }) }) backend.OnModified.Add(func(v *backend.View) { t.render() }) backend.OnSelectionModified.Add(func(v *backend.View) { t.render() }) ed := backend.GetEditor() ed.SetFrontend(t) ed.LogInput(false) ed.LogCommands(false) c := ed.Console() var ( scheme *textmate.Theme ) if sc, err := textmate.LoadTheme("../../3rdparty/bundles/TextMate-Themes/GlitterBomb.tmTheme"); err != nil { log4go.Error(err) } else { scheme = sc } var ( palLut func(col textmate.Color) termbox.Attribute pal = make([]termbox.RGB, 0, 256) mode256 bool ) if err := termbox.SetColorMode(termbox.ColorMode256); err != nil { log4go.Error("Unable to use 256 color mode: %s", err) } else { log4go.Debug("Using 256 color mode") mode256 = true } if !mode256 { pal = pal[:10] // Not correct, but whatever pal[termbox.ColorBlack] = termbox.RGB{0, 0, 0} pal[termbox.ColorWhite] = termbox.RGB{255, 255, 255} pal[termbox.ColorRed] = termbox.RGB{255, 0, 0} pal[termbox.ColorGreen] = termbox.RGB{0, 255, 0} pal[termbox.ColorBlue] = termbox.RGB{0, 0, 255} pal[termbox.ColorMagenta] = termbox.RGB{255, 0, 255} pal[termbox.ColorYellow] = termbox.RGB{255, 255, 0} pal[termbox.ColorCyan] = termbox.RGB{0, 255, 255} diff := func(i, j byte) int { v := int(i) - int(j) if v < 0 { return -v } return v } palLut = func(col textmate.Color) termbox.Attribute { mindist := 10000000 mini := 0 for i, c := range pal { if dist := diff(c.R, col.R) + diff(c.G, col.G) + diff(c.B, col.B); dist < mindist { mindist = dist mini = i } } return termbox.Attribute(mini) } } else { palLut = func(col textmate.Color) termbox.Attribute { tc := termbox.RGB{col.R, col.G, col.B} for i, c := range pal { if c == tc { return termbox.Attribute(i) } } l := len(pal) pal = append(pal, tc) return termbox.Attribute(l) } } for i, s := range scheme.Settings { var ( fi = defaultFg bi = defaultBg ) if fg, ok := s.Settings["foreground"]; ok { fi = palLut(fg) if i == 0 { defaultFg = fi } } if bg, ok := s.Settings["background"]; ok { bi = palLut(bg) if i == 0 { defaultBg = bi } } schemelut[s.Scope] = [2]termbox.Attribute{fi, bi} } if mode256 { termbox.SetColorPalette(pal) } evchan := make(chan termbox.Event, 32) defer func() { close(evchan) termbox.Close() fmt.Println(util.Prof) }() w := ed.NewWindow() v := w.OpenFile("main.go", 0) v.Settings().Set("trace", true) v.Settings().Set("syntax", "../../3rdparty/bundles/go.tmbundle/Syntaxes/Go.tmLanguage") c.Buffer().AddCallback(t.scroll) sel := v.Sel() sel.Clear() // end := v.Buffer().Size() - 2 sel.Add(Region{0, 0}) // sel.Add(Region{end - 22, end - 22}) // sel.Add(Region{end - 16, end - 20}) // sel.Add(Region{end - 13, end - 10}) go func() { for { evchan <- termbox.PollEvent() } }() { w, h := termbox.Size() t.lock.Lock() t.layout[v] = layout{0, 0, w, h - console_height - 1, Region{}, 0} t.layout[c] = layout{0, h - console_height + 1, w, console_height - 5, Region{}, 0} t.lock.Unlock() t.Show(v, Region{1, 1}) } t.Show(v, Region{100, 100}) t.Show(v, Region{1, 1}) go func() { ed.Init() sublime.Init() }() for { p := util.Prof.Enter("mainloop") blink_phase := time.Second if p, ok := ed.Settings().Get("caret_blink_phase", 1.0).(float64); ok { blink_phase = time.Duration(float64(time.Second) * p) } timer := time.NewTimer(blink_phase / 2) select { case ev := <-evchan: mp := util.Prof.Enter("evchan") limit := 3 loop: switch ev.Type { case termbox.EventError: log4go.Debug("error occured") return case termbox.EventKey: var kp backend.KeyPress if ev.Ch != 0 { kp.Key = backend.Key(ev.Ch) } else if v2, ok := lut[ev.Key]; ok { kp = v2 } else { break } if ev.Key == termbox.KeyCtrlQ { return } ed.HandleInput(kp) blink = true } if len(evchan) > 0 { limit-- ev = <-evchan goto loop } mp.Exit() case <-timer.C: // // case <-time.After(blink_phase / 2): blink = !blink t.render() // // // Divided by two since we're only doing a simple toggle blink // // // TODO(q): Shouldn't redraw if blink is disabled... } timer.Stop() p.Exit() } }
func (t *tbfe) loop() { qml.Init(nil) engine := qml.NewEngine() engine.Context().SetVar("lines", t) engine.Context().SetVar("frontend", t) engine.Context().SetVar("editor", backend.GetEditor()) backend.OnNew.Add(func(v *backend.View) { v.Settings().AddOnChange("lime.frontend.html.render", func(name string) { t.dirty = true }) }) backend.OnModified.Add(func(v *backend.View) { t.dirty = true }) backend.OnSelectionModified.Add(func(v *backend.View) { t.dirty = true }) ed := backend.GetEditor() ed.SetFrontend(t) ed.LogInput(false) ed.LogCommands(false) c := ed.Console() if sc, err := textmate.LoadTheme("../../3rdparty/bundles/TextMate-Themes/GlitterBomb.tmTheme"); err != nil { log4go.Error(err) } else { scheme = sc } defer func() { fmt.Println(util.Prof) }() w := ed.NewWindow() v := w.OpenFile("main.go", 0) v.Settings().Set("trace", true) v.Settings().Set("syntax", "../../3rdparty/bundles/go.tmbundle/Syntaxes/Go.tmLanguage") c.Buffer().AddCallback(t.scroll) sel := v.Sel() sel.Clear() sel.Add(Region{0, 0}) { w, h := 800, 600 t.lock.Lock() t.layout[v] = layout{0, 0, w, h - console_height - 1, Region{}, 0} t.layout[c] = layout{0, h - console_height + 1, w, console_height - 5, Region{}, 0} t.lock.Unlock() t.Show(v, Region{1, 1}) } t.Show(v, Region{100, 100}) t.Show(v, Region{1, 1}) t.Len, _ = v.Buffer().RowCol(v.Buffer().Size()) ed.Init() sublime.Init() component, err := engine.LoadFile("main.qml") if err != nil { log4go.Exit(err) } window := component.CreateWindow(nil) window.Show() qml.Changed(t, &t.Len) log4go.Debug("Done") window.Wait() }
func (t *tbfe) loop() { backend.OnNew.Add(func(v *backend.View) { v.Settings().AddOnChange("lime.frontend.html.render", func() { t.dirty = true }) }) backend.OnModified.Add(func(v *backend.View) { t.dirty = true }) backend.OnSelectionModified.Add(func(v *backend.View) { t.dirty = true }) ed := backend.GetEditor() ed.SetFrontend(t) ed.LogInput(false) ed.LogCommands(false) c := ed.Console() if sc, err := textmate.LoadTheme("../../3rdparty/bundles/TextMate-Themes/GlitterBomb.tmTheme"); err != nil { log4go.Error(err) } else { scheme = sc } defer func() { fmt.Println(util.Prof) }() w := ed.NewWindow() v := w.OpenFile("main.go", 0) v.Settings().Set("trace", true) v.Settings().Set("syntax", "../../3rdparty/bundles/go.tmbundle/Syntaxes/Go.tmLanguage") c.Buffer().AddCallback(t.scroll) sel := v.Sel() sel.Clear() // end := v.Buffer().Size() - 2 sel.Add(Region{0, 0}) // sel.Add(Region{end - 22, end - 22}) // sel.Add(Region{end - 16, end - 20}) // sel.Add(Region{end - 13, end - 10}) { w, h := 800, 600 t.lock.Lock() t.layout[v] = layout{0, 0, w, h - console_height - 1, Region{}, 0} t.layout[c] = layout{0, h - console_height + 1, w, console_height - 5, Region{}, 0} t.lock.Unlock() t.Show(v, Region{1, 1}) } t.Show(v, Region{100, 100}) t.Show(v, Region{1, 1}) go func() { ed.Init() sublime.Init() }() log4go.Debug("serving") http.HandleFunc("/key", t.key) http.HandleFunc("/", t.ServeHTTP) http.HandleFunc("/view", t.view) if err := http.ListenAndServe("localhost:8080", nil); err != nil { log4go.Error("Error serving: %s", err) } log4go.Debug("Done") }