"os"
"runtime"
"sort"
+ "time"
"github.com/go-errors/errors"
isatty "github.com/mattn/go-isatty"
}
}()
+ // clear the drawchan so we don't redraw excessively
+ // if someone requested a redraw before we started displaying
+ for len(screen.DrawChan) > 0 {
+ <-screen.DrawChan
+ }
+
+ var event tcell.Event
+
+ // wait for initial resize event
+ select {
+ case event = <-events:
+ action.Tabs.HandleEvent(event)
+ case <-time.After(20 * time.Millisecond):
+ // time out after 10ms
+ }
+
for {
// Display everything
screen.Screen.Fill(' ', config.DefStyle)
action.InfoBar.Display()
screen.Screen.Show()
- var event tcell.Event
-
// Check for new events
select {
case f := <-shell.Jobs:
"path/filepath"
"strconv"
"strings"
+ "sync"
"time"
"unicode/utf8"
Highlighter *highlight.Highlighter
// Modifications is the list of modified regions for syntax highlighting
Modifications []Loc
+ HighlightLock sync.Mutex
// Hash of the original buffer -- empty if fastdirty is on
origHash [md5.Size]byte
}
if b.Highlighter == nil || syntaxFile != "" {
- b.Settings["filetype"] = b.SyntaxDef.FileType
+ if b.SyntaxDef != nil {
+ b.Settings["filetype"] = b.SyntaxDef.FileType
+ }
} else {
b.SyntaxDef = &highlight.EmptyDef
}
if b.SyntaxDef != nil {
b.Highlighter = highlight.NewHighlighter(b.SyntaxDef)
if b.Settings["syntax"].(bool) {
- b.Highlighter.HighlightStates(b)
- b.Highlighter.HighlightMatches(b, 0, b.End().Y)
+ go func() {
+ b.Highlighter.HighlightStates(b)
+ b.Highlighter.HighlightMatches(b, 0, b.End().Y)
+ screen.DrawChan <- true
+ }()
}
}
}
import (
"bufio"
"io"
+ "sync"
"unicode/utf8"
"github.com/zyedidia/micro/pkg/highlight"
state highlight.State
match highlight.LineMatch
rehighlight bool
+ lock sync.Mutex
}
const (
if err != nil {
if err == io.EOF {
- la.lines = Append(la.lines, Line{data[:], nil, nil, false})
+ la.lines = Append(la.lines, Line{
+ data: data[:],
+ state: nil,
+ match: nil,
+ rehighlight: false,
+ })
}
// Last line was read
break
} else {
- la.lines = Append(la.lines, Line{data[:dlen-1], nil, nil, false})
+ la.lines = Append(la.lines, Line{
+ data: data[:dlen-1],
+ state: nil,
+ match: nil,
+ rehighlight: false,
+ })
}
n++
}
// newlineBelow adds a newline below the given line number
func (la *LineArray) newlineBelow(y int) {
- la.lines = append(la.lines, Line{[]byte{' '}, nil, nil, false})
+ la.lines = append(la.lines, Line{
+ data: []byte{' '},
+ state: nil,
+ match: nil,
+ rehighlight: false,
+ })
copy(la.lines[y+2:], la.lines[y+1:])
- la.lines[y+1] = Line{[]byte{}, la.lines[y].state, nil, false}
+ la.lines[y+1] = Line{
+ data: []byte{},
+ state: la.lines[y].state,
+ match: nil,
+ rehighlight: false,
+ }
}
// Inserts a byte array at a given location
// State gets the highlight state for the given line number
func (la *LineArray) State(lineN int) highlight.State {
+ la.lines[lineN].lock.Lock()
+ defer la.lines[lineN].lock.Unlock()
return la.lines[lineN].state
}
// SetState sets the highlight state at the given line number
func (la *LineArray) SetState(lineN int, s highlight.State) {
+ la.lines[lineN].lock.Lock()
+ defer la.lines[lineN].lock.Unlock()
la.lines[lineN].state = s
}
// SetMatch sets the match at the given line number
func (la *LineArray) SetMatch(lineN int, m highlight.LineMatch) {
+ la.lines[lineN].lock.Lock()
+ defer la.lines[lineN].lock.Unlock()
la.lines[lineN].match = m
}
// Match retrieves the match for the given line number
func (la *LineArray) Match(lineN int) highlight.LineMatch {
+ la.lines[lineN].lock.Lock()
+ defer la.lines[lineN].lock.Unlock()
return la.lines[lineN].match
}
func (la *LineArray) Rehighlight(lineN int) bool {
+ la.lines[lineN].lock.Lock()
+ defer la.lines[lineN].lock.Unlock()
return la.lines[lineN].rehighlight
}
func (la *LineArray) SetRehighlight(lineN int, on bool) {
+ la.lines[lineN].lock.Lock()
+ defer la.lines[lineN].lock.Unlock()
la.lines[lineN].rehighlight = on
}