func NewFile(name string, flushChan chan struct{}, screen *terminal.Screen) *File { file := &File{ Name: name, screen: screen, fileMode: os.FileMode(int(0644)), buffer: buffer.MakeBuffer([]string{""}), savedBuffer: buffer.MakeBuffer([]string{""}), MultiCursor: cursor.MakeMultiCursor(), flushChan: flushChan, saveChan: make(chan struct{}, 1), SyntaxRules: syntaxcolor.NewSyntaxRules(""), autoIndent: true, autoTab: true, tabString: "\t", newline: "\n", tabHealth: true, timer: MakeTimer(), maxRate: 100.0, statusMutex: &sync.Mutex{}, } file.buffHist = NewBufferHist(file.buffer, file.MultiCursor) go file.processSaveRequests() go file.ReadFile(name) switch path.Ext(name) { case ".md", ".txt", ".csv", ".C": file.autoIndent = false } return file }
func TestGetFileType(t *testing.T) { sr := syntaxcolor.NewSyntaxRules("foo.go") ft := sr.GetFileType("foo.go") if ft != "go" { t.Error("Error getting file type. Expected 'go', got", ft) } ft = sr.GetFileType("foo.cpp") if ft != "c" { t.Error("Error getting file type. Expected 'c', got", ft) } }
func ExampleColorize() { sr := syntaxcolor.NewSyntaxRules("foo.go") lc := sr.Colorize("package main") fmt.Println(lc) lc = sr.Colorize("var x ") fmt.Println(lc[0].Start, lc[0].End) // Output: // [] // 5 6 }
// OpenFile opens a specified file. func (editor *Editor) OpenFile(name string) { file := file.NewFile(name, editor.flushChan, editor.screen) file.SyntaxRules = syntaxcolor.NewSyntaxRules(name) editor.files = append(editor.files, file) }