コード例 #1
0
ファイル: dir_cat.go プロジェクト: qjpcpu/sexy-ssh
func drawCenter(g *gocui.Gui) {
	if v := g.View("center"); v != nil {
		_, height := g.Size()
		height = height - 2
		if text, err := TailFile(files[file_offset], height); err == nil {
			if i := strings.Index(text, "\n"); i > 0 {
				re := regexp.MustCompile("\\033[[0-9]+m")
				line := re.ReplaceAllString(text[0:i], "")
				text = line + text[i:]
			} else {
				re := regexp.MustCompile("\\033[[0-9]+m")
				text = re.ReplaceAllString(text, "")
			}
			v.Clear()
			fmt.Fprintf(v, "%s", text)
			g.Flush()
		} else {
			v.Clear()
			fmt.Fprintf(v, "------ failed to read from %s ------\n", filepath.Base(files[file_offset]))
			g.Flush()
		}
	}
}