6 "github.com/zyedidia/micro/internal/buffer"
7 "github.com/zyedidia/micro/internal/config"
8 "github.com/zyedidia/micro/internal/screen"
9 "github.com/zyedidia/micro/internal/shell"
10 "github.com/zyedidia/tcell"
11 "github.com/zyedidia/terminal"
14 type TermWindow struct {
21 func NewTermWindow(x, y, w, h int, term *shell.Terminal) *TermWindow {
30 // Resize informs the terminal of a resize event
31 func (w *TermWindow) Resize(width, height int) {
32 if config.GetGlobalOption("statusline").(bool) {
35 w.Term.Resize(width, height)
36 w.Width, w.Height = width, height
39 func (w *TermWindow) SetActive(b bool) {
43 func (w *TermWindow) IsActive() bool {
47 func (w *TermWindow) LocFromVisual(vloc buffer.Loc) buffer.Loc {
51 func (w *TermWindow) Clear() {
52 for y := 0; y < w.Height; y++ {
53 for x := 0; x < w.Width; x++ {
54 screen.SetContent(w.X+x, w.Y+y, ' ', nil, config.DefStyle)
59 func (w *TermWindow) Relocate() bool { return true }
60 func (w *TermWindow) GetView() *View {
63 func (w *TermWindow) SetView(v *View) {
67 // Display displays this terminal in a view
68 func (w *TermWindow) Display() {
70 defer w.State.Unlock()
73 for y := 0; y < w.Height; y++ {
74 for x := 0; x < w.Width; x++ {
76 c, f, b := w.State.Cell(x, y)
78 fg, bg := int(f), int(b)
79 if f == terminal.DefaultFG {
80 fg = int(tcell.ColorDefault)
82 if b == terminal.DefaultBG {
83 bg = int(tcell.ColorDefault)
85 st := tcell.StyleDefault.Foreground(config.GetColor256(int(fg))).Background(config.GetColor256(int(bg)))
87 if l.LessThan(w.Selection[1]) && l.GreaterEqual(w.Selection[0]) || l.LessThan(w.Selection[0]) && l.GreaterEqual(w.Selection[1]) {
91 screen.SetContent(w.X+x, w.Y+y, c, nil, st)
94 if config.GetGlobalOption("statusline").(bool) {
95 statusLineStyle := config.DefStyle.Reverse(true)
96 if style, ok := config.Colorscheme["statusline"]; ok {
97 statusLineStyle = style
100 text := []byte(w.Name())
101 textLen := utf8.RuneCount(text)
102 for x := 0; x < w.Width; x++ {
104 r, size := utf8.DecodeRune(text)
106 screen.SetContent(w.X+x, w.Y+w.Height, r, nil, statusLineStyle)
108 screen.SetContent(w.X+x, w.Y+w.Height, ' ', nil, statusLineStyle)
112 if w.State.CursorVisible() && w.active {
113 curx, cury := w.State.Cursor()
114 screen.ShowCursor(curx+w.X, cury+w.Y)