예제 #1
0
파일: file.go 프로젝트: wx13/sith
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
}
예제 #2
0
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)
	}

}
예제 #3
0
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

}
예제 #4
0
파일: editor.go 프로젝트: wx13/sith
// 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)
}