func (t *tbfe) loop() { ed := backend.GetEditor() ed.SetFrontend(t) //ed.LogInput(true) //ed.LogCommands(true) c := ed.Console() var ( scheme textmate.Theme ) if d, err := ioutil.ReadFile("../../3rdparty/bundles/TextMate-Themes/GlitterBomb.tmTheme"); err != nil { log4go.Error("Unable to load colorscheme definition: %s", err) } else if err := loaders.LoadPlist(d, &scheme); err != nil { log4go.Error("Unable to load colorscheme definition: %s", err) } 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) } defer func() { termbox.Close() fmt.Println(c.Buffer().Data()) }() w := ed.NewWindow() t.active_window = w v := w.OpenFile("main.go", 0) v.Settings().Set("trace", true) c.Buffer().AddCallback(t.scroll) if err := v.SetSyntaxFile("../../3rdparty/bundles/GoSublime/GoSublime.tmLanguage"); err != nil { log4go.Error("Unable to set syntax file: %s", err) } sel := v.Sel() sel.Clear() // end := v.Buffer().Size() - 2 sel.Add(primitives.Region{0, 0}) // sel.Add(primitives.Region{end - 22, end - 22}) // sel.Add(primitives.Region{end - 16, end - 20}) // sel.Add(primitives.Region{end - 13, end - 10}) evchan := make(chan termbox.Event) go func() { for { evchan <- termbox.PollEvent() } }() sublime.Init() for { blink = !blink termbox.Clear(defaultFg, defaultBg) w, h := termbox.Size() t.renderView(0, 0, w, h-console_height, v) t.renderView(0, h-(console_height), w, (console_height - 1), c) runes := []rune(t.status_message) for i := 0; i < w && i < len(runes); i++ { termbox.SetCell(i, h-1, runes[i], defaultFg, defaultBg) } termbox.Flush() 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) } select { case ev := <-evchan: switch ev.Type { 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 = false } case <-time.After(blink_phase / 2): // Divided by two since we're only doing a simple toggle blink // TODO(q): Shouldn't redraw if blink is disabled... } } }
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() { var ( ed = t.setupEditor() c = ed.Console() w = ed.NewWindow() v = createNewView("main.go", w) sel = v.Sel() ) t.settings = getSettings(v) c.Buffer().AddCallback(t.scroll) t.setupCallbacks() loadTextMateScheme() setColorMode() setSchemeSettings() sel.Clear() sel.Add(Region{0, 0}) evchan := make(chan termbox.Event, 32) defer func() { close(evchan) termbox.Close() fmt.Println(util.Prof) }() 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) } // Divided by two since we're only doing a simple toggle blink 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 = false } if len(evchan) > 0 { limit-- ev = <-evchan goto loop } mp.Exit() case <-timer.C: // TODO(q): Shouldn't redraw if blink is disabled... blink = !blink t.render() } timer.Stop() p.Exit() } }
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") }