示例#1
0
文件: virn.go 项目: kawasima/virn
func main() {
	filename := os.Args[len(os.Args)-1]
	filepath := findFile(filename)
	bs, _ := ioutil.ReadFile(filepath)
	s := string(bs[:])

	scr, err := goncurses.Init()
	if err != nil {

	}
	defer terminateWindow()
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, syscall.SIGTERM)
	go func() {
		<-c
		terminateWindow()
		os.Exit(1)
	}()

	goncurses.CBreak(true)
	scr.ScrollOk(true)
	scr.Keypad(true)
	goncurses.Echo(false)
	goncurses.NewLines(true)

	y, x := scr.MaxYX()
	scr.Resize(y-1, x)

	status_win, err := goncurses.NewWindow(1, x, y-1, 0)
	if err != nil {
	}
	status_win.ClearOk(true)
	status_win.Printf("\"%s\" [New File]", filename)
	status_win.Refresh()
	renderInitialWindow(scr)

	scr.GetChar()
	status_win.Erase()
	status_win.Move(0, 0)
	status_win.AttrOn(goncurses.A_BOLD)
	status_win.Print("--INSERT--")
	status_win.Refresh()
	scr.Move(0, 0)
	scr.Refresh()

	chars := strings.Split(s, "")
	i := 0
	for true {
		ch := scr.GetChar()
		rune, _ := utf8.DecodeRuneInString(chars[i])
		if rune == '\n' {
			if ch == '\n' {
				scr.Print("\n")
				scr.DelChar()
				for true {
					i++
					if i >= len(chars) {
						break
					}
					r, _ := utf8.DecodeRuneInString(chars[i])
					if r == '\t' || r == ' ' {
						scr.Printf("%c", r)
					} else {
						break
					}
				}
			}
		} else {
			scr.Printf("%c", rune)
			i++
		}

		if i >= len(chars) {
			break
		}
	}
	scr.GetChar()
	status_win.Erase()
	status_win.Refresh()
	scr.Refresh()
	scr.GetChar()
	scr.GetChar()

	ioutil.WriteFile(filename, []byte(s), 0644)
}
示例#2
0
文件: virn.go 项目: kawasima/virn
func terminateWindow() {
	log.Println("TERMINATE")
	goncurses.CBreak(false)
	goncurses.NewLines(false)
	goncurses.End()
}